A collection of "find" command examples for Unix/Linux
<<<<<<<The
find command is used to locate files on a Unix
or Linux system.It can search the entire filesystem to find files and directories
according to the search criteria you specify. Besides using the find
command to locate files, you can also execute other Linux commands (grep, mv, rm, etc.) on the files and directories you find, which makes find extremely powerful.>>>>>>>1. find / -name xyzThis will search the whole system for any files namedxyzand display theirpath names.Here we are using the criterion-name with the argumentxyztotellfindto perform a name search for the file namexyz.2. find /tmp /var/tmp . $HOME -name xyzYou can specify as many places to search as you wish.
3. find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tarHere's an example using two search criteria, will find any regular files( i.e., not directories or other special files) with the criteria “‑type f”,and only those modified seven or fewer days ago (“‑mtime ‑7”).4. find / -name xyz | xargs /bin/rm -f5. find / -name xyz -exec /bin/rm -f '{}' \; # same thing6. find / -name xyz -delete # same if using Gnu findAnother use ofxargsis illustrated above. This command willefficiently remove all files namedxyzfrom your system (provided yourun the command as root of course)7. find . -iname xyz # find xyz, Xyz, XYz, xyZ etc, case-insensitive searching
8. find . -iname xyz -type d # Same thing but only directory9. find . -type f \( -name "*.c" -o -name "*.sh" \)find files with different extensions10. find . -type f \( -name "*php" -o -name "*jsp" -o -name "*html" \)find files with different extensions for three patterns.
11. find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \;cp *.mp3 files to /tmp/MusicFiles12. find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;copy the file header.shtml to those dirs
13. find . -type d -name xyz -exec rm -r {} \;remove all subdirectories named "xyz" under current dir
14. find . -mtime 1 # 24 hours 15. find . -mtime -7 # last 7 days 16. find . -mtime -7 -type f # just files 17. find . -mtime -7 -type d # just dirsfind files by modification time
Great...........
ReplyDelete