Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 28, 2022 04:55 pm GMT

Find files and directories in CLI

Sign up to my newsletter!.

Although the popular use of the find command is to search within the folder path with its option, it can also meet much more specific needs when customized.

The basic usage is as follows:

find [search-to-directory] [option] [search-org]

Let's start with examples. Our first example is to find the error.log files on the server.

find / -name "error.log"

Or using type;

find / -type f -name "error.log"

When this command is applied, the error.log files found in other services in the system will also be listed. If we want to find all *.log files on the server, the following command will be useful.

find / -name "*.log"

Let's search multiple files at once. The files we want to find are access.logand error.log.

find / -type f ( -name "access.log" -o -name "error.log" ) -print

we are not limited to searching only filenames. Let's take a look at -type expressions before folder searches.

  • b: block device
  • c: character device
  • d: directory
  • f: regular file
  • l: symbolic link
  • P: FIFO
  • s: socket

Now let's perform a folder search.

find / -type d -name [folder-name]

Let me remind you that all operations are case-sensitive. We can use -iname to perform search operations without distinction of upper and lower case.

find / -type d -iname [folder-name]

Sign up to my newsletter!.


Original Link: https://dev.to/baransel/find-files-and-directories-in-cli-1m58

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To