User Tools

Site Tools


find

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
find [2009/04/01 03:18]
k2patel created
find [2011/10/24 16:02]
k2patel
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,​ the find command will come in handy. The command syntax is:+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
 +</​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.+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 /​directory_path -mtime -1 -print 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.+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 /​directory_path -type f -mtime -1 -print 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:​+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 /​tmefndr/​oravl01 -type f -newer /tmp/$$ find /​tmefndr/​oravl01 -type f -newer /tmp/$$
 rm /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.+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>​ </​code>​
 +
 +Confirm before delete \\
 +All files older then 14 days in root of location will be deleted with confirmation.
 +
find.txt · Last modified: 2020/08/10 02:35 (external edit)