Linux commands – 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).

http://linuxxcommand.blogspot.com/2013/12/linux-commands-find-command.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s