The find command in Unix/Linux is used to search for files and directories in a directory hierarchy based on various criteria. It is a powerful and flexible tool that allows you to locate files and perform actions on them
Here are some common options: -name pattern: Search for files with a specific name pattern. -type type: Search for files of a specific type (e.g., f for regular files, d for directories). -mtime n: Search for files modified n days ago. -size n[c]: Search for files of a specific size (optionally followed by a unit, such as k for kilobytes). -exec command {} +: Execute a command on the found files.
find /path/to/search -name "filename.txt"
find /path/to/search -type d -name "directory_name"
find /path/to/search -mtime -1
find /path/to/search -size +1G
find /path/to/search -name "*.log"
find /path/to/search -type f -exec chmod 644 {} \;
find /path/to/search -inum 12345
find /path/to/search -type f -not -path "/path/to/exclude/*"
find /path/to/search -type f -perm 644
find /path/to/search -type d -empty
find /path/to/search -type f -name "*.tmp" -delete
find /path/to/search -type f -name "*.txt" -exec tar czf archive.tar.gz {} +
find /path/to/search -newermt "2023-01-01"
find /path/to/search -type f -exec basename {} \;
find /path/to/search -type f | wc -l
find /path/to/search -type f -exec du -h {} \;
find /path/to/search -type f -exec ls -l {} \;
find /path/to/search -type f -exec ls -lt {} +
find /path/to/search -mtime -7
find /path/to/search -type f -exec ls -l {} \; | awk '{print $3}'
find /path/to/search -type d -exec ls -R {} \;
find /path/to/search -type f -name "*.jpg" -exec mv {} /path/to/destination/ \;
find /path/to/search -type f -name "*.log" -exec gzip {} \;
find /path/to/search -type f -exec stat --format="%x" {} \;
find /path/to/search -type f -exec chmod 644 {} \;
find /path/to/search -mmin -30
find /path/to/search -type f -name "*.bak" -exec rm -i {} \;
find /path/to/search -type f -exec ls -i {} \;
find /path/to/search -type f -name "*.txt" -exec rename 's/\.txt$/\.bak/' {} \;
find /path/to/search -type f -name "*.log" -exec tar czf archive_$(date +"%Y%m%d%H%M%S").tar.gz {} +
find /path/to/search -type f -exec ls -Z {} \;
find /path/to/search -type f -exec stat --format="%y" {} \;
find /path/to/search -type f -exec du -h --apparent-size {} \;
find /path/to/search -type f -name "*.jpg" -exec cp {} /path/to/destination/ \;
find /path/to/search -type d -name "temp" -exec rm -r {} \;
find /path/to/search -type f -exec stat --format="%Y" {} \;
find /path/to/search -type f -name "*.log" -exec tar czf archive_$(date +"%Y%m%d")_{} \;
find /path/to/search -mtime +30
find /path/to/search -type f -exec bash -c 'year=$(date -r "{}" +%Y); month=$(date -r "{}" +%m); mkdir -p "/path/to/destination/$year/$month" && mv "{}" "/path/to/destination/$year/$month/"' \;
find /path/to/search -type f -exec stat --format="%a" {} \;
find /path/to/directory -type f -name "*.txt" -exec rm {} \;
find /path/to/source -type f -exec cp {} /path/to/destination/ \;
find /path/to/files -type f -exec mv {} /path/to/backup/ \;
find /path/to/files -type f -exec chmod 644 {} \;
find /path/to/files -type f -exec grep "search_text" {} \;
find /path/to/files -type f -exec wc -l {} \; | awk '{ total += $1 } END { print "Total lines: " total }'
find /path/to/files -type f -name "*.sh" -exec ./custom_script.sh {} \;
find /path/to/files -type f -exec stat {} \;
find /path/to/files -type f -name "*.log" -exec tar -cvzf logs.tar.gz {} +
find /path/to/directory -type d -empty -exec rmdir {} \;
find /path/to/files -type f -mtime -7 -exec ls -l {} \;
find /path/to/files -type f -name "*.tmp" -exec rm {} \;
find /path/to/files -type f -size +1G -exec ls -lh {} \;
find /path/to/files -type f -name "*.jpg" -or -name "*.png" -exec tar -cvzf images.tar.gz {} +
find /path/to/files -type f -name "*.pdf" -exec mv {} /path/to/pdf_files/ \;
find /path/to/files -type f -user username -exec ls -l {} \;
find /path/to/files -type f -perm 644 -exec ls -l {} \;
find /path/to/files -type f -name "*.bak" -exec rm {} \;
find /path/to/files -type f -exec exiftool {} \;
find /path/to/files -type f -mtime -30 -exec tar -cvzf recent_files.tar.gz {} +