How to find a folder in Linux using the command line

How to find a folder in Linux using the command line

To find a folder in Linux using the command line, you can use the find command. The syntax is as follows:

find /path/to/search -type d -name folder-name
Sou‮‬rce:www.lautturi.com

Replace /path/to/search with the path of the directory you want to search, and folder-name with the name of the folder you are looking for.

For example, to find a folder called documents in the /home directory, you would run the following command:

find /home -type d -name documents

This will search the /home directory and all of its subdirectories for a folder called documents and display the path of any matches.

You can use the -print option to print the full path of the found folders, like this:

find /home -type d -name documents -print

You can also use the -ls option to list the found folders in a long format, like this:

find /home -type d -name documents -ls

Keep in mind that the find command will search recursively, so it may take a while to complete if you are searching a large directory tree. You can use the -maxdepth option to limit the depth of the search. For example, to search only the top-level directories in the /home directory, you would run the following command:

find /home -maxdepth 1 -type d -name documents

This will search only the top-level directories in the /home directory for a folder called documents.

Created Time:2017-10-16 14:38:46  Author:lautturi