Tuesday, December 31, 2013

Find command

Linux commands - Find command

Find files under a specified directory that match conditions you specify.

find / -name myfile*

Find files in the root directory and all directories under it that have file names beginning with myfile. The * is a wild-card character that represents any number of characters. The ? is a wild-card character that represents a single character.

find -name '*.pdf' -print -exec chown User2 {} \;

Find all files in this directory and all subdirectories that end with .pdf, display the names of all files that are found on the screen and, for each file (indicated by the curly braces — {}), change its owner to User2.
 The -print option is not necessary, but it is handy to track the progress of the find command. If you do not use -print, the find command is silent except for error messages from find or from chown.

find -name '*.pdf' -exec grep -il 'SOMETHING' {} \;

Find all files in this directory and all subdirectories that end with .pdf and look for the pattern SOMETHING in each of the files. The -i option to grep makes the search case-insensitive. The -l option to grep causes grep to display the names of the files that have SOMETHING in them. When a file is found that contains SOMETHING, this command displays the full path to the file from the current directory (for example,
./home/user/Documents/Linuxcommand.pdf).

     

Share this article :

0 comments:

Post a Comment