Friday, August 3, 2012

UNIX Useful Commands - FIND


1).Find files modified within specific time
Find files that have been modified less than 3 days ago.
find . -mtime -3
To be more specific and just check for the file change time, use:
find . -ctime -3
To be even more specific you can set a date range by using: Find all files changed, and thus modified, at least one day ago but within three days ago.
find . -ctime +1 -a -ctime -3
2).Find and Replace text in Multiple Files
Use,
                                find . -type f | xargs grep -l 'IBM' | xargs sed -i '' -e 's/IBM/ORACLE/g'
The first part of the command is find, which finds all files and excludes directories. That result is then piped to grep, which lists all files that contain IBM. The results of is then sent to sed, which replaces all occurances of IBM with ORACLE.
3).Find and Move files to a specific location
Use,
                              find . -newer *lmd.trc -exec cp '{}' /tmp/ \ ;
Above command find the file newer than the *lmd.trc and then copies all the files to the tmp directory.

No comments: