unix search text string in file Finding all files containing a text string in linux find /home/anujs/Documents -type f -exec grep -il "/tickets" {} \; find /home/oracle -type f -exec grep -il "192.168.0.17" {} \; find /u01/app/oracle/diag/rdbms/irac/irac1/trace -type f -exec grep -il "undo_tablespace" {} \; if you know the file type find . -type f -name "*.ext" -exec grep -il "hello" {} \ find /u01/app/oracle/diag/rdbms/irac/irac1/trace -type f -name "*.log" -exec grep -il "undo_tablespace" {} \; find . -type f -exec grep -il "hdp" {} \; rm -rf `ls -l | grep 'Apr 2' | tr -s ' ' | cut -d ' ' -f9`
==
find /home/oracle -name 'TKT0' -print -exec zip /dumps/TKT0_`hostname`.zip {} \;
find /ux/log/alert -type f -exec grep -r "ORA-01555" {} \;
<txt>ORA-01555 caused by SQL statement below (SQL ID: 0kv0t7aj8yu67, Query Duration=16206 sec, SCN:
<txt>ORA-01555 caused by SQL statement below (SQL ID: 8ru41zauaub1n, Query Duration=14790 sec, SCN:
<txt>ORA-01555 caused by SQL statement below (SQL ID: 20fr6cgpnzgcy, Query Duration=15270 sec, SCN:
w
find . -type f -name "opr_dia0*" -print -exec zip /home/oracle/odsprdc_dia.zip {} \;
===
to delete files
rm -rf `find -maxdepth 1 -type f -exec ls -l {} + | grep '11:54' | awk '{ print $9 }'`
to delete Dir
rm -rf `find -type d -exec ls -l {} + | grep '11:54' | awk '{ print $9 }'`
==================
Find all files in the current directory:
find . -type f
Find all files with a specific extension in the current directory:
find . -name "*.txt"
Find all files modified within the last 24 hours:
find . -mtime -1
Find all files larger than 100MB:
find . -size +100M
Find all files with a specific name and execute a command on them:
find . -name "example.txt" -exec cat {} \;
Find all files with a specific permission:
find . -perm 777
Find all files that are empty:
find . -empty
Find all files that are owned by a specific user:
find / -user myusername
Find all files that are in a specific group:
find / -group mygroupname
Find all files that are older than a certain date:
find / -type f -newermt "2022-01-01"
Find all directories in the current directory:
find . -type d
Find all files with a specific name and delete them:
find . -name "temp*" -delete
Find all files with a specific name and move them to a different directory:
find . -name "*.log" -exec mv {} /var/log/ \;
Find all files that are larger than a certain size and print their size:
find . -size +1G -exec ls -lh {} \;
Find all files that are older than a certain number of days and print their names: find . -mtime +30 -exec ls {} \;
Find all files that have been accessed within the last 7 days and print their names: find . -atime -7 -exec ls {} \;
Find all files that match a specific pattern and copy them to a different directory: find . -name "*.txt" -exec cp {} /backup/ \;
Find all files that are symbolic links and print their target:
find . -type l -exec ls -l {} \;
Find all files that have been modified within the last hour and print their names: find . -cmin -60 -exec ls {} \;
Find all files that have been modified within the last week and compress them: find . -mtime -7 -exec gzip {} \;
Find all files that have been modified within the last 30 days and have a specific string in their content:
find . -mtime -30 -exec grep -l "string" {} \;
Find all files that have been modified within the last 30 days and have a specific string in their content and delete them:
find . -mtime -30 -exec grep -l "string" {} \; -delete
Find all files that are larger than a certain size and have a specific string in their content and move them to a different directory:
find . -size +1G -exec grep -l "string" {} \; -exec mv {} /new_folder/ \;
Find all files that are smaller than a certain size and have a specific string in their content and print their name and size:
find . -size -100M -exec grep -l "string" {} \; -exec ls -lh {} \;
Find all files that have been modified within the last year and have a specific string in their content and compress them with tar:
find . -mtime -365 -exec grep -l "string" {} \; -exec tar -czf {}.tar.gz {} \;
Find all files that have been accessed within the last month and have a
specific string in their content and print their name and last access time:
find . -atime -30 -exec grep -l "string" {} \; -exec stat -c "%n last accessed on %x" {} \;
Find all files that have been modified within the last week and have a specific string in their content
and mail them to a specific email address:
find . -mtime -7 -exec grep -l "string" {} \; -exec mail -s "Files with specific string" email@example.com < {} \;
Find all files that have been modified within the last 30 days and have a specific string in their content
and run a specific command on them:
find . -mtime -30 -exec grep -l "string" {} \; -exec your_command {} \;
Find all files that have been modified within the last year and have a specific string in their content
and rename them:
find . -mtime -365 -exec grep -l "string" {} \; -exec mv {} {}_newname \;
Find all files that have a specific string in their content and have been modified within the last year,
and change their permission:
find . -mtime -365 -exec grep -l "string" {} \; -exec chmod 755 {} \;
Find all files that have been modified within the last year and have a specific string in their content
and also have a specific file extension and print their name and path:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec stat -c "%n path: %h" {} \;
Find all files that have a specific string in their content and have been modified within the last year
and also have a specific file extension and change their owner:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec chown new_owner {} \;
Find all files that have a specific string in their content and have been modified within the last year
and also have a specific file extension and change their group:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec chgrp new_group {} \;
Find all files that have been modified within the last year and have a specific string in their content
and also have a specific file extension and print their name and last access time:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec stat -c "%n last accessed on %x" {} \;
Find all files that have been modified within the last year and have a specific string in their content
and also have a specific file extension and move them to a different directory:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec mv {} /new_folder/ \;
Find all files that have been modified within the last year and have a specific string in their content
and also have a specific file extension and compress them with tar:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec tar -czf {}.tar.gz {} \;
Find all files that have been modified within the last year and have a specific string in their
content and also have a specific file extension and mail them to a specific email address:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec mail -s "Files with specific string" email@example.com < {} \;
Find all files that have a specific string in their content and have been modified within the
last year and also have a specific file extension and rename them:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec mv {} {}_newname \;
Find all files that have been modified within the last year and have a specific string in their content
and also have a specific file extension and change their permission:
find . -mtime -365 -name "*.txt" -exec grep -l "string" {} \; - exec chmod 755 {} \;