find
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| find [2009/04/01 03:18] – created k2patel | find [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <code text> | + | ====== 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, | + | 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: | 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 | find . -mtime -1 -print | ||
| + | </ | ||
| - | 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. | + | 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: | 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 / | find / | ||
| + | </ | ||
| - | 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. | + | 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: | + | 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 / | find / | ||
| + | </ | ||
| - | 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: | + | 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/$$ | touch -t `date +%m%d0000` /tmp/$$ | ||
| find / | find / | ||
| rm /tmp/$$ | rm /tmp/$$ | ||
| + | </ | ||
| - | 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. | + | 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 {} \; | ||
| </ | </ | ||
| + | |||
| + | Confirm before delete \\ | ||
| + | All files older then 14 days in root of location will be deleted with confirmation. | ||
| + | |||
find.1238555930.txt.gz · Last modified: 2020/08/10 02:30 (external edit)