Website based on my experience working as System Administrator

LINUX INFORMATION WEBSITE

This site is dedicated to providing tutorials, help, guides and links for Linux users.
HOME PAGE
LINUX COMMANDS
   
   
   
   
   
   
   
   
   

LINUX COMMANDS

Contents | Previous | Next

Finding files

$ find

The find command finds files and directories, matching a specified criteria. Many things can be done with find, making it appear intimidating. But in practise, the first two examples given, will be what you use most.


Finding files by name

find . -name '*.txt'
Find all files ending with .txt in the current directory.


find ~ -iname '*dex*'
Find all files in your home directory (~), ignoring case (-iname), with dex anywhere in the filename ('*dex*').


Finding files by size

find ~/work -empty
Find all empty files in the ~/work directory.


find /usr/bin -size +1024k
Find files in the /usr/bin directory, over one megabyte in size (-size +1024k).


find /usr/bin -size +1024k -size -2048k
Find files in the /usr/bin directory, over one megabyte (-size +1024k), and under two megabytes (-size -2048k).


Running commands on files found

With the -exec option, you can run a command on each file found. '{}' indicates where you want the result to go (i.e. anywhere a filename would go as part of a command), and ';' indicates the end of the command to be run.

For confirmation before running a command on each file found, use -ok instead of -exec.


find /usr/bin -size +1024k -size -2048k -exec ls -lh '{}' ';'
Same as last example, but each result ('{}') is to be listed (ls) in long (-l) human-readable (-h) form.


find ~ -name '*temp*' -ok rm '{}' ';'
Find files in your home directory (~), with 'temp' somewhere in the filename ('*temp*'), and confirm removal (-ok rm '{}' ';').


Finding files by owner

find ~ -user root
Find files in your home (~) directory, belonging to root (-user root).


find /site -group columnists
Find files in the /site directory, belonging to the columnists group (-group columnists).


Finding files by modification time

find ~/work -mtime -1
Find files in the ~/work directory, modified less than 24 hours ago (-mtime -1).


find ~/work -mtime +7
Find files in the ~/work directory, modified over a week ago (-mtime +7).


find reports -mmin -5
Find files in reports directory, modified less than 5 minutes ago.


find reports -mmin +60 -mmin -180
Find files in reports directory, modified over an hour ago, and under 3 hours ago.


find reports -newer reports/sales.doc
Find files in the reports directory, modified later than the file, reports/sales.doc.


find ~/mywork -used +200
Find files that haven't been accessed for over 200 days since last being modified.

Contents | Previous | Next

 
Last Update: Jan 2003

HOME | CONTACT | FAQ'S | TRICKS & TIPS | WEIRD NEWS
This Material has been taken from different sources. Its free for anyone to use and reproduce.