find /etc -name "*" | xargs grep "enable"
find -name april* Find files starting with april in the current directory
find -name april* fprint file Find files starting with april in the current directory and output the results to file
find -name ap* -o -name may * Find files starting with ap or may
find /mnt -name tom.txt -ftype vfat Find a file with name tom.txt and file system type vfat under /mnt find /mnt -name t.txt ! -ftype vfat Find a file
with name tom under /mnt. txt and the file system type is not vfat
find /tmp -name wa* -type l Find the file whose name starts with wa and whose type is a symbolic link in /tmp Find
/home -mtime -2 Find the last two files in /home Changed files within the past day find /home -atime -1 Check files
that have been accessed within 1 day
find /home -mmin +60 Check /home for files changed 60 minutes ago
find /home -amin +30 Check Find the files that have been accessed 30 minutes ago and
find /home -newer tmp.txt Find files or directories with a newer update time than tmp.txt
in /home Find /home -anewer tmp.txt Find the access time in /home Files or directories closer than tmp.txt
find /home -used -2 List files or directories that have been accessed within 2 days after the file or directory has been changed
find /home -user cnscn List the files or directories belonging to the user cnscn in the /home directory
find /home -uid +501 List the files or directories with the user ID greater than 501 in the /home directory
find /home -group cnscn List /home group cnscn files or directories
find /home -gid 501 list files or directories with group id 501 in
/home find /home -nouser list /home files or directories that do not belong to local users
find /home -nogroup List files or directories that do not belong to the local group in
/home find /home -name tmp.txt -maxdepth 4 List tmp.txt in /home The depth is up to 3 layers
find /home -name tmp.txt -mindepth 3 start from the second layer
find /home -empty find files with size 0 or empty directories
find /home -size +512k find files larger than 512k
find /home -size -512k find files smaller than 512k
find /home -links +2 Find files or directories with more than 2 hard links
find /home -perm 0700 Find files or directories with a permission of 700
find /tmp -name tmp.txt -exec cat {} \;
find /tmp - name tmp.txt -ok rm {} \;
find / -amin -10 # Find files accessed in the system in the last 10 minutes
find / -atime -2 # Find files accessed in the system in the last 48 hours
find / -empty # Find files or folders that are empty in the system
find / -group cat # Find files belonging to groupcat in the system
find / -mmin -5 # Find files modified in the last 5 minutes in the system
find / -mtime -1 # Find files modified in the system in the last 24 hours file
find / -nouser #Find files belonging to invalid users in the system
find / -user fred #Find files belonging to the user FRED in the system
Check all common files in the current directory
-rw-r–r– 1 root root 34928 2003-02-25 ./conf/httpd.conf
-rw-r–r– 1 root root 12959 2003 -02-25 ./conf/magic
-rw-r–r– 1 root root 180 2003-02-25 ./conf.d/README
Check all ordinary files in the current directory and use ls in the -exec option - l command to list them
=====================================================
at Find files in the /logs directory with a change time older than 5 days and delete them:
$ find logs -type f -mtime +5 -exec -ok rm {} \;
===================================================
Query Modified files of the day
[root@book class]# find ./ -mtime -1 -type f -exec ls -l {} \;
===================================================
Query file and ask if you want to show
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls … ./classDB.inc.php > ? y
-rw-r– r– 1 cnscn cnscn 13709 Jan 12 12:22 ./classDB.inc.php
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls … ./ classDB.inc.php > ?n
[root@book class]#
===================================================
Query And hand it over to awk to process
[root@book class]# who | awk '{print $1"\t"$2}'
cnscn pts/0
===============================================
awk —Grep — sed
[root@book class]# df -k | awk '{print $1}' | grep -v 'none' | sed s"/\/dev\///g"
file system
sda2
sda1
[root@book class]# df -k | awk '{print $1}' | grep -v 'none'
filesystem
/dev/sda2
/dev/sda1
A) find /tmp -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
B) grep SYSCALL_VECTOR /tmp/*.h | cut -d’:' -f1| uniq > filename
C) find /tmp -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print
2)find / -name filename -exec rm -rf {} \;
find / -name filename -ok rm -rf {} \;
3) For example, to find files larger than 3M in the disk:
find . -size +3000k -exec ls -ld {} ;
4) Copy the found things to another place
find *.c -exec cp '{}' /tmp ';'
If there are special files, you can use cpio, or you can use this syntax:
find dir -name filename -print | cpio -pdv newdir
6) Find files changed at 2004-11-30 16:36:37
# A=`find ./ -name "*php"` | ls -l --full-time $A 2>/dev/null | grep "2004-11-30 16:36:37"