This shows you the differences between two versions of the page.
find [2011/10/24 16:02] k2patel |
find [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Find ====== | ||
- | |||
- | To find all files that was modified since a specific time ago\\ | ||
- | (i.e an hour ago, a day ago, 24 hours ago, a weeks ago and so on) in Unix environment,\\ | ||
- | the find command will come in handy. The command syntax is: | ||
- | |||
- | To find all files modified in the last 24 hours (last full day) in current directory and its sub-directories: | ||
- | |||
- | <code bash | cmd> | ||
- | find . -mtime -1 -print | ||
- | </code> | ||
- | |||
- | Flag -mtime -1 option tells find command to look for files modified in the last day (24 hours).\\ | ||
- | Flag -print option will cause find command to print the files’ location.\\ | ||
- | -print can be replaced with -ls if you want a directory-listing-type response. | ||
- | |||
- | To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories: | ||
- | |||
- | <code bahs | cmd> | ||
- | find /directory_path -mtime -1 -print | ||
- | </code> | ||
- | |||
- | The command is basically the same with the earlier command,\\ | ||
- | just that now you no need to cd (change directory) to the directory you want to search. | ||
- | |||
- | To find all files with regular file types only,\\ | ||
- | and modified in the last 24 hours (last full day) in current directory and its sub-directories: | ||
- | |||
- | <code bash | cmd> | ||
- | find /directory_path -type f -mtime -1 -print | ||
- | </code> | ||
- | |||
- | To find all files that are modified today only (since start of day only, i.e. 12 am),\\ | ||
- | in current directory and its sub-directories: | ||
- | |||
- | <code bash | cmd> | ||
- | touch -t `date +%m%d0000` /tmp/$$ | ||
- | find /tmefndr/oravl01 -type f -newer /tmp/$$ | ||
- | rm /tmp/$$ | ||
- | </code> | ||
- | |||
- | The first command can be modified to specify other date and time,\\ | ||
- | so that the commands will return all files that have changed since that particular date and time. | ||
- | |||
- | |||
- | <code bash | cmd> | ||
- | find . -type f -mtime +14 -ok rm -f {} \; | ||
- | </code> | ||
- | |||
- | Confirm before delete \\ | ||
- | All files older then 14 days in root of location will be deleted with confirmation. | ||