100 Best Use Cases of Find Command in Linux -ExpLinux

0
24
Find Command in Linux

SNUseCommand1Find files in a specific directory:find /path/to/directory -type f2Find directories in a specific directory:find /path/to/directory -type d3Find files with a specific name:find /path/to/directory -name “file_name”4Find files with a specific extension:find /path/to/directory -name “*.extension”5Find files based on their size:find /path/to/directory -size +10M6Find files based on their modification time:find /path/to/directory -mtime +77Find files based on their access time:find /path/to/directory -atime +78Find files based on their inode number:find /path/to/directory -inum 1234569Find files that are readable:find /path/to/directory -perm -44410Find files that are writable:find /path/to/directory -perm -22211Find files that are executable:find /path/to/directory -perm -11112Find files that are owned by a specific user:find /path/to/directory -user user_name13Find files that are owned by a specific group:find /path/to/directory -group group_name14Find files with a specific user ID:find /path/to/directory -uid 12345615Find files with a specific group ID:find /path/to/directory -gid 12345616Find files that match a specific pattern:find /path/to/directory -regex “.*pattern.*”17Find files that contain a specific word or phrase:find /path/to/directory -type f -exec grep -q “word or phrase” {} \; -print18Find files that are symbolic links:find /path/to/directory -type l19Find files that are hard links:find /path/to/directory -type f -links +120Find files that are empty:find /path/to/directory -empty21Find files that are not empty:find /path/to/directory ! -empty22Find files and execute a specific command on each file:find /path/to/directory -type f -exec command {} \;23Find files and move them to a new location:find /path/to/directory -type f -exec mv {} /path/to/new/location \;24Find files and delete themfind /path/to/directory -type f -exec rm -i {} \;25Find files and copy them to a new location:find /path/to/directory -type f -exec cp {} /path/to/new/location \;26Find files and change the permissions on each file:find /path/to/directory -type f -exec chmod 755 {} \;27Find files and change the owner of each file:find /path/to/directory -type f -exec chown user:group {} \;28Find files and change the group of each file:find /path/to/directory -type f -exec chgrp group_name {} \;29Find files and print the full path of each file:find /path/to/directory -type f -printf “%p\n”30Find files and print the size of each file:find /path/to/directory -type f -printf “%s\n”31Find files and print the inode number of each file:find /path/to/directory -type f -printf “%i\n”32Find files and print the modification time of each file:find /path/to/directory -type f -printf “%T@\n”33Find files and print the user name of the owner of each file:find /path/to/directory -type f -printf “%u\n”34Find files and print the group name of the owner of each file:find /path/to/directory -type f -printf “%g\n”35Find files and print the permissions of each file:find /path/to/directory -type f -printf “%M\n”36Find files and execute a command with a specific time limit:find /path/to/directory -type f -mmin +5 -exec command {} \;37Find files and execute a command only if the file has been modified in the last 5 minutes:find /path/to/directory -type f -mmin -5 -exec command {} \;38Find files and execute a command only if the file has not been modified in the last 5 minutes:find /path/to/directory -type f ! -mmin -5 -exec command {} \;39Find files and search for a specific string in each file:find /path/to/directory -type f -exec grep “string” {} \;40Find files and list only the first 10 files that match a specific criteria:find /path/to/directory -type f -print | head -1041Find files and list only the last 10 files that match a specific criteria: find /path/to/directory | head 1042Find files and exclude a specific directory from the search:find /path/to/directory -type f -not -path “/path/to/directory/to/exclude/*” -print43Find files and exclude multiple directories from the search:find /path/to/directory -type f \( -not -path “/path/to/directory/to/exclude/*” -and -not -path “/path/to/directory/to/exclude2/*” \) -print44Find files and search for files with a specific name pattern:find /path/to/directory -type f -name “*.txt”45Find files and search for files with a specific size:find /path/to/directory -type f -size +100M46Find files and search for files smaller than a specific size:find /path/to/directory -type f -size -100M47Find files and search for files larger than a specific size:find /path/to/directory -type f -size +100M48Find files and search for files of an exact size:find /path/to/directory -type f -size 100M49Find files and search for files with a specific user owner:find /path/to/directory -type f -user user_name50Find files and search for files with a specific group owner:find /path/to/directory -type f -group group_name51Find files and search for files with a specific type of permissions:find /path/to/directory -type f -perm 64452Find files and search for files that are writable:find /path/to/directory -type f -perm -22253Find files and search for files that are readable:find /path/to/directory -type f -perm -44454Find files and search for files that are executable:find /path/to/directory -type f -perm -11155Find files and search for files with specific type of executability:find /path/to/directory -type f -perm /u=x,g=x56Find files and search for files that have changed in the last 7 days:find /path/to/directory -type f -ctime -757Find files and search for files that have changed more than 7 days ago:find /path/to/directory -type f -ctime +758Find files and search for files that have been modified in the last 7 days:find /path/to/directory -type f -mtime -759Find files and search for files that have been modified more than 7 days ago:find /path/to/directory -type f -mtime +760Find files and search for files that have been accessed in the last 7 days:find /path/to/directory -type f -atime -761Find files and search for files that have not been accessed in the last 7 days:find /path/to/directory -type f -atime +762Find files and search for files that match multiple criteria:find /path/to/directory -type f \( -name “*.txt” -or -name “*.pdf” \) -and -size +100M63Find files and delete the files that match certain criteria:find /path/to/directory -type f -name “*.bak” -delete64Find files and print the output in a specific format:find /path/to/directory -type f -printf “%p %u %g %s\n”65Find files and execute a specific command on the matching files:find /path/to/directory -type f -exec chmod 644 {} \;66Find files and limit the number of results to display:find /path/to/directory -type f -print | head -1067Find files and sort the results by file size:find /path/to/directory -type f -printf “%s %p\n” | sort -nr68Find files and exclude specific files or directories from the results:find /path/to/directory -type f \( ! -name “*.bak” ! -path “/path/to/directory/to/exclude/*” \) -print69Find files and search for files based on their inode number:find /path/to/directory -type f -inum 12345670Find files and search for files based on their access time and modification time:find /path/to/directory -type f -anewer file.txt -or -mnewer file.txt71Find files and search for files with a specific type of type:find /path/to/directory -type l -ls72Find files and search for files with a specific type of type and perform an action on them:find /path/to/directory -type l -exec ls -l {} \;73Find files and search for files based on the number of links:find /path/to/directory -type f -links +574Find files and search for files based on the number of links and perform an action on them:find /path/to/directory -type f -links +5 -exec ls -l {} \;75Find files and search for files based on the type of file system they are on:find /mnt/c/ -type f -fstype xfs76Find files and search for files with a specific owner:find /path/to/directory -type f -user username77Find files and search for files with a specific group:find /path/to/directory -type f -group groupname78Find files and search for files with a specific permissions:find /path/to/directory -type f -perm 064479Find files and search for files with a specific name and perform a certain action on them:find /path/to/directory -type f -name “*.log” -exec gzip {} \;80Find files and search for files that match a certain pattern and perform a certain action on them:find /path/to/directory -type f -regex “.*\.\(jpg\|jpeg\|png\)” -exec cp {} /path/to/destination/ \;81Find files and search for files that have been modified in the last 7 days and perform a certain action on them:find /path/to/directory -type f -mtime -7 -exec rm {} \;82Find files and search for files that have a specific size and perform a certain action on them:find /path/to/directory -type f -size +100M -exec mv {} /path/to/destination/ \;83Find files and search for files that have a specific size range and perform a certain action on them:find /path/to/directory -type f -size +10M -size -100M -exec cp {} /path/to/destination/ \;84Find files and search for files that have a specific size range and print the results in a specific format:find /path/to/directory -type f -size +10M -size -100M -printf “%p %u %g %s\n”85Find files and search for files that have a specific name and move them to a specific location:find /path/to/directory -type f -name “*.log” -exec mv {} /path/to/destination/ \;86Find files and search for files that have a specific name and copy them to a specific location:find /path/to/directory -type f -name “*.log” -exec cp {} /path/to/destination/ \;87Find files and search for files that have a specific name and count the number of matches:find /path/to/directory -type f -name “*.log” | wc -l88Find files and search for files that have a specific name and delete the matches:find /path/to/directory -type f -name “*.log” -delete89Find files and search for files that have a specific name and rename the matches:find /path/to/directory -type f -name “*.log” -exec mv {} {}.bak \;90Find files that have been modified in the last day and delete them:find /path/to/directory -type f -mtime -1 -delete91Find files that have been modified in the last 7 days and compress them:find /path/to/directory -type f -mtime -7 -exec gzip {} \;92Find files that have a specific name and show the details in a human-readable format:find /path/to/directory -type f -name “*.log” -exec stat -c “%n %s %y” {} \;93Find all symbolic links and delete them:find /path/to/directory -type l -delete94Find all symbolic links and replace them with their targets:find /path/to/directory -type l -exec sh -c ‘ln -sf “$(readlink -f “$1″)” “$1″‘ _ {} \;95Find all symbolic links that point to a specific location and delete them:find /path/to/directory -type l -lname “/path/to/link/target” -delete96Find all files that are larger than a specific size and delete them:find /path/to/directory -type f -size +100M -delete97Find mp3 files in ext4 filesystemfind /mnt/usb/ -type f -fstype ext4 | grep -i ‘\.mp3$’98Find files that have been modified in the last hour and move them to a different location:find /path/to/directory -type f -mmin -60 -exec mv {} /path/to/destination/ \;99Find commnad in linux with sed command . Find file and replace text mylinux to explinuxfind my_files -type f -name ‘*.txt’ -exec sed -i ‘s/mylinux/explinux/g’ {} \;100Find process pid status and print from proc find /proc/1234 -maxdepth 0 -name status -o -name stat -exec cat {} \;

LEAVE A REPLY

Please enter your comment!
Please enter your name here