Saturday, December 19, 2009

Find

Find

Syntax
# find   location  test  options   criteria_to_match   action_to_perform

Finding files
To find all files having txt extension *.txt
# find / -name *.txt

To find file location
# find / -name syslog.conf

Files owned by a user
# find / -user root

Files by type
# find / -type d

l—symbolic link
d—directory
b—block (buffered) special
c—character (unbuffered) special
p—named pipe (FIFO)
s—socket

File according to date and time
# find / -atime +3
-atime +3: All files that were last accessed more than 3 days ago

mtime—the time that the contents of a file were last modified 
atime—the time that a file was read or accessed
ctime—the time that a file’s status was changed

-n returns less than n 
+n returns greater than n 
n, by itself,returns exactly n matches

Files by size(larger than 5 MB)
# find / -size +5000000c

Finding by Permission and Ownership
# find / -type f  -perm a=rwx 
or 
# find / -type f  -perm 777

Finding files and perform some action (delete)
# find . -type f -perm 777 -exec ls -l *.* {} \;

Locate command
To find the location of files & directories
# locate *.txt

To update the database
# updatedb

No comments:

Post a Comment