Find: Difference between revisions
no edit summary
No edit summary |
|||
Line 3:
<br />
Find Text Files
Line 17 ⟶ 11:
find ~/test -type d -empty
Find all empty files (zero byte file)
find ~ -empty
List all the empty files only in your home directory
find
List only the non-hidden empty files only in the current directory
find
Find Files Using Name
Line 43 ⟶ 32:
Find the passwd file under root and one level down
find -maxdepth 2 -name passwd
Find only the socket files
Line 79 ⟶ 38:
Find all directories
find . -type d
find ~/test ! -name *.jpg ! -name *.gif ! -name *.png ! -name *.jpeg ! -name *.JPG ! -name *.bmp ! -name *.html ! -name *.htm ! -type d
Find only the normal files
Line 89 ⟶ 49:
find -type d -name ".*"
List and Export only files recursively without Directory name
find . -maxdepth 10 -type f -printf '%f\n' > fileslist.txt
=
Created within 2 days
find ~/test -
Modified within 24 hours
find ~/test -
Find files in directory and sub-directories updated within 60 min
Line 130 ⟶ 73:
find . -cmin -60
find / -ctime -1
Displays all files which are modified after the /etc/passwd files was modified
Line 149 ⟶ 86:
find -mmin -60 -exec ls -l {} \;
= Delete Files =
Delete empty folders
find ~/test -type d -empty -exec rmdir {} \;
find ~/ -type d -empty -delete
Find and Delete .ini & .db files
find ~/test -name *.ini
find ~/test -name *.ini -delete
find ~/test -name *.db
find ~/test -name *.db -delete
Replaces space in all the *.mp3 files with _
Line 163 ⟶ 107:
Move Specific files to another location
find ./* -name *.jpg -exec mv {} ~/Public/ \;
Search all jpg images in the system and archive it
find ~/test -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Inverting the match
find -maxdepth 1 -not -iname "MyCProgram.c"
= Size based Sort =
Find files bigger than the given size
find ~ -size +100M
Find files smaller than the given size
find ~ -size -100M
Find files that matches the exact given size
find ~ -size 100M
Remove the files named a.out frequently
alias rmao="find . -iname a.out -exec rm {} \;"
$ rmao
Remove the core files generated by c program
alias rmc="find . -iname core -exec rm {} \;"
$ rmc
Removes *.zip files that are over 100M
find / -type f -name *.zip -size +100M -exec rm -i {} \;"
Restricting the find output only to files
find /etc/sysconfig -amin -30 -type f
Do not display hidden files in find output
find . -mmin -15 \( ! -regex ".*/\..*" \)
If multiple partitions mounted under /, this command will NOT search all mounted partitions
find / -xdev -name "*.log"
If you don’t want to see the errors and would like to redirect it to null
find -name "*.txt" 2>>/dev/null
Line 178 ⟶ 177:
<br />
Finding the Top 5 Big Files
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Finding the Top 5 Small Files
find . -type f -exec ls -s {} \; | sort -n | head -5
List the smaller files other than the ZERO byte files
find . -not -empty -type f -exec ls -s {} \; | sort -n | head -5
Find files which has read permission to group
find . -perm -g=r -type f -exec ls -l {} \;
Find files which has read permission only to group
find . -perm g=r -type f -exec ls -l {} \;
Executing Commands on the Files Found by the Find Command
find -iname "MyCProgram.c" -exec md5sum {} \;
<br />
|