8:33 PM FIND utility in Linux to search for files or directories. | ||||||
Find command: A powerful utility to search for a file or directory on a target directory. Description:
Though we can use cd and ls commands to locate a file but if the path is too deep or the file hirachy is too nested, its difficult to search. So, in that case FIND is very usefull.
Format: find [path] [criteria] [action]
EXAMPLES: Lets try to understand this command using some example command and their interpretation. 1. find ~ -name abc -print The above command will search and print for a file named "abc" in the home directory in downward direction.
2. find . -type d -name somedir -print The above command will search for a directory named "somedir" in the current directory downward. Also, it will print them on console.
3. find / -type f -links 1 -print The above command will search and print all the files which are of type file(not directories) and having one links.
4. find .. -perm 644 -exec rm {} \; The above command will search and remove all the files having permission as 644 (rw-r--r--) in the parent of current directory in downward direction. Note:- Here "{}" indicates that the out put of find becomes the argument of rm command. ";" shows the end of rm command and "\" is used to avoid apecial meaning of ";"
5. find ~ -size 5c -exec cat {} \; The above command will search and print the content of each file of size 5 bytes in home directory downward.
6. find . -type f -name somename -exec rm -i {} \; The above command will search and remove all the files of name "somename" in the current directory downward , interactively.
Note:- If we use "-i" option in exec, the rm command will perform on each file interactively. But if we use the action "OK", it will implicitly perform the command interactively. See the next example:
7. find / -type f -name somename -ok rm {} \; The above command will search and remove all the files of name "somename" from the root directory downward , interactively.
| ||||||
|
Related blogs
You may also like to see:
[2017-08-13] | [Open System-Linux] |
Perl trick to remove Ctrl - M charater from a file |
[2015-06-13] | [Open System-Linux] |
XRANDR command : a command line interface to RandR extension, set screen size and orientation |
[2014-09-21] | [Open System-Linux] |
How to define command prompt strings in Linux : what are $PS1, $PS2, $PS3 and $PS4? |
[2015-06-01] | [Open System-Linux] |
DIG command : A DNS lookup utility |
[2014-12-05] | [Open System-Linux] |
PIDSTAT command for debugging and analysis of Performance of Linux process |
Total comments: 0 | |