Saturday, December 13, 2008

find command linux

-atime n File was accessed n days ago
-mtime n File was modified n days ago
-size n File is n blocks big (a block is 512 bytes)
-type c Specifies file type: f=plain text, d=directory
-fstype typ Specifies file system type: 4.2 or nfs
-name nam The filename is nam
-user usr The file's owner is usr
-group grp The file's group owner is grp
-perm p The file's access mode is p (where p is an integer)

You can use + (plus) and - (minus) modifiers with the atime, mtime, and size criteria to increase their usefulness, for example,

-mtime +7 Matches files modified more than seven days ago
-atime -2 Matches files accessed less than two days ago
-size +100 Matches files larger than 100 blocks (50KB)



find . \! -iname *.cpp find file except cpp files

find . \( -iname \*.sh -a -iname \*.cpp \) find sh and cpp files

find /dir1 /dir2 \! -iname *.cpp feed search path this way

-exec cmd Execute command cmd on a file.
-ok cmd Prompt before executing the command cmd on a file.


find . -size +100M
find . -size -100M

find . \( -iname \*.cpp -a -size -1k \)

-mmin n
File's data was last modified n minutes ago.
find . -mtime 2
find . -mtime -2 files that are less than 2 days old
find . -mtime +2 files that are more than 2 days old


find . -mmin 2
find . -mmin -2 files that are less than 2 min old
find . -mmin +2 files that are more than 2 min old

-amin n
File was last accessed n minutes ago.

find . -atime +30 find files that have not been accessed for over 30 days

find . -type d list directories in present directory
find . -type f list directories in present regular file

find . -maxdepth 1 -size +100k find files size more than 100k in present directory


find files created after 1.sh
find . -cnewer 1.sh

find files modified after 1.sh
find . -newer 1.sh

find . -empty -maxdepth 1


Print me the way you want me, baby!
Changing the output information
If you want more than just the names of the files displayed, find's -printf action lets you have just about any type of information displayed. Looking at the man page there is a startling array of options.

These are used the most:
%p filename, including name(s) of directory the file is in
%m permissions of file, displayed in octal.
%f displays the filename, no directory names are included
%g name of the group the file belongs to.
%h display name of directory file is in, filename isn't included.
%u username of the owner of the file

find . -name l.sh -printf %AD\ %Ar\\n;
11/29/08 05:01:27 PM

find . -name l.sh -printf %AI\ %AM\ %AS\ %Ap\ %AD\\n;
09 41 25.0000000000 PM 11/29/08

find . -name 2.sh -printf %h\\n;
display directory only

No comments:

Post a Comment