The Linux find command can find files based upon practically any requirements that you might need. This post describes the many criteria you can use to find what you’re searching for — even when you can’t remember what you named a file or when you last changed it or added content.Basic discover syntax The standard syntax
for the find command appears like this:$find [starting place] [criteria] [options] [action to take] The beginning area can be a directory site name (e.g.,/ var/log), the present directory (.), your house directory site whether you’re sitting in it or not (~), or a directory site relative to your present position (e.g.,./ bin). You can be as specific as you desire when entering the beginning location.Finding files by name Searching for files by name
is the most convenient and most straightforward way to find a file. Note the command below uses an asterisk so that it will find any files that start with”repair “.$ find ~ -name “fix *”
– print/ home/shs/fixit
Finding files by type
You can also discover files that are of a particular type (e.g., a file, directory site or symbolic link) To discover a file, usage “-type f”.
$ discover Files -name junk * -type f -print Documents/junk. odt Documents/junk. docx
To find a symbolic link, usage “-type l”.
$ find. -name “h *” -type l -ls 28603 0 lrwxrwxrwx 1 shs 9 Jun 27 12:27./ hold ->/ tmp/hold4me
To find a directory site, use “-type d”.
$ discover. -type d -ls|head -3 3389 4 drwxr-x– 25 shs 4096 Jun 27 14:24. 3467 4 drwxr-xr-x 2 shs 4096 May 20 2021./ Pictures 3468 4 drwxr-xr-x 2 shs 4096 May 7 2021./ Videos
Determining what you want to see or do
You most likely noticed in the 2 previous commands that you can note (-ls means a long listing) or merely show the name of a file (-print). These are not the only choices.
To delete a file, you require to include the -exec rm command as revealed listed below. This command will eliminate any file with a “. old” extension from your house directory (including subdirectories).
$ find ~ -name *. old -officer rm ;
The exec command can even enable you to view the contents of a file. Here’s an example:
$ find. -name “h *” -type l -officer cat ; Meow, Meow!
Discovering files by owner and/or group
To discover files by user, consist of the “-user uname” requirements. You can define the username or the user ID. The third example listed below send out output that produces a mistake (e.g., approval denied) to/ dev/null so that it does not clutter up the screen.
$ discover. -user shs -ls|head -4 3389 4 drwxr-x– 25 shs 4096 Jun 27 13:18. 5617 4 -rw-rw-r– 1 shs 22 Feb 15 2021./ CHECKME 8001 4 -rwx —— 1 shs 150 Feb 25 2021./ send_msg 12727 24 -rw-rw-r– 1 shs 20805 Apr 15 2021./ history-rece $ discover. -user 1000 -ls|head -4 3389 4 drwxr-x– 25 shs 4096 Jun 27 13:18. 5617 4 -rw-rw-r– 1 shs 22 Feb 15 2021./ CHECKME 8001 4 -rwx —— 1 shs 150 Feb 25 2021./ send_msg 12727 24 -rw-rw-r– 1 shs 20805 Apr 15 2021./ history-recent $ find/ tmp -user shs -ls 2 >/ dev/null 26476575 4 -rw-rw-r– 1 shs 10 Jun 27 12:44/ tmp/haha 26476577 4 drwx —— 2 …
Source