The Find command is one of the most powerful commands

Source: Internet
Author: User
Tags file size
The Find command is one of the most powerful commands, but it is also one of the most difficult commands for command-line structures to master.
# Find/-print | WC-L displays the number of files and directories in the system.
# Find/-user $LOGNAME-print displays all files and directories for that user in the system.
# Find/-size 100-print display file size is blocks.
# Find/-size-100-print shows file size less than blocks.
# Find/-size +100-print shows file size greater than blocks.
# Find/-name core-exec rm {} \; Find and delete the core file.
# Find. -exec chown $LOGNAME {} \; Modifies all files in a directory to which the user belongs.
# find.-type d-exec chmod 770 {} \; Modify permissions for all directories under a directory.


Find: (The following are all operating under Hp-unix)
Find./dir-mtime +10-exec rm-rf {}\; Locate the file 10 days ago in the Dir directory, and then delete it. The E x E C option is followed by the command to be executed, followed by a pair of {}, a space and a \, and finally a semicolon.
Find./dir-mtime +20 | Xargs rm found 20 days ago and deleted files in the Dir directory. Xargs efficiency and performance are better than direct with-EXEC option
Find/dir-mtime-2 in dir directory for files within two days
Find./dir-mtime +3 files found three days ago in the Dir directory
Find/dir-user fly in the Dir directory for files belonging to fly users
Find./dir-group user finds files belonging to the user group in the dir directory
Find./dir-type d looking for files of file type directory in dir directory
Find./dir-name "*.sh"-depth when using the f i n d command, you might want to match all of the files before looking in subdirectories. Use the D e p t h option to make the f i n d command do this

Find all files in a Unix machine that contain "jdbc/wapdatasource" strings

Find/grep "Jdbc/wapdatasource"

Find/-name httpd.conf
Find/-name Access_log 2>/dev/null
Find/etc-name ' *srm* '
Find/-amin-10 # finds files accessed in the last 10 minutes of the system
Find/-atime-2 # finds files accessed in the last 48 hours of the system
Find/-mmin-5 # finds files that have been modified in the last 5 minutes of the system
Find/-mtime-1 #查找在系统中最后24小时里修改过的文件
Find/-cmin-5 # finds files that have changed state in the last 5 minutes of the system
Find/-ctime-1 #查找在系统中最后24小时里被改变状态的文件
Find/-user Reda #查找在系统中属于fred这个用户的文件
Find/-not-user Reda #查找在系统中不属于FRED这个用户的文件
Find/-group Redagrp # finds files that belong to the REDAGRP group in the system
Find/-gid 501 #查找系统中属于组id为501的文件
Find/-user fred-a-group redagrp
Find/-user Reda-o-user Tracy
Find/-nouser #查找在系统中属于作废用户的文件
Find/-empty # finds files that are empty in the system or empty folders
Find/-false #查找系统中总是错误的文件
Find/-size +5k #查找系统中大于5k字节的文件
Find/-size +5c #查找系统中大于5字节的文件
Find/-perm +6000
Find/-type B
File type: the
B Block (buffer) device.
C-character device.
D directory.
P Famous pipe (FIFO).
F rule file.
L Symbolic link.
s socket.
Find/-maxdepth 2-name Fred
Find/tmp-size +10000000c-and-mtime +2
Find/-user Reda-or-user Tracy
Find/tmp! -user Reda
Find/-name ' httpd.conf '-ls
Find/-user reda-exec ls-l {} \;
Find/-user Reda-ok #确认后执行
Find/-user Reda | Xargs ls-l

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.