Skip to main content

find

檔案大小

找出大於 1000 MB 的檔案

find / -type f -size +1000M

列出最大檔案的清單

find . -type f -exec wc -c {} \; | sort -nr | head
檔案的日期時間

搬移指定日期範圍的檔案
將修改日期是 2012 - 2014 的所有檔案搬移至 /export_data/2012-2014

touch --date "2012-01-01" /tmp/start
touch --date "2015-01-01" /tmp/end

find /home/ams/ipdr -type f -newer /tmp/start -not -newer /tmp/end > 2012-2014.lst
find /home/ams/ipdr -type f -newer /tmp/start -not -newer /tmp/end -exec cp -a {}  /export_data/2012-2014 \;
find /home/ams/ipdr -type f -newer /tmp/start -not -newer /tmp/end -exec rm -f {} \;

列出 2018-03-20 至 2018-04-10 期間曾修改過的檔案

find ~/ -xdev -newermt 2018-03-20 \! -newermt 2018-04-10 -type f -ls

列出 365天以前/20分鐘以前 的所有檔案

find ./ -ctime +365 -ls
find ./ -cmin +20 -ls
  • ctime 檔案建立時間
  • mtime 最近檔案修改時間
  • atime 最近存取檔案時間

找尋3日內曾異動過的檔案,並轉換 Excel format(csv)

find . -xdev -mtime -3 -ls > found.list
sed 's/^[ ]*//g;s/[ ][ ]*/   /g' found.list | awk '{print $3","$5","$6","$7","$8" "$9","$10","$11}' > found.list.csv

列出剛剛異動過的檔案

# 最近 5 分鐘異動過的檔案(包含權限與新增檔案)
find dir -cmin -5

# 最近 10 分鐘修改過的檔案
find dir -mmin 10

目錄 data 內有許多以日期命名的小 log,需要將去年的所有 log 搬到新目錄 archive-2013
註:排除目錄 ./archive-2013

cd data/
mkdir archive-2013
find ./ -path "./archive-2013" -prune -o -name "dcdb_13*" -exec mv {} archive-2013 \;

要排除多個目錄時可以改成
find ./  \( -path "./dir1" -o -path "./dir2" \) -prune -o -name "dcdb_13*" -exec mv {} archive-XXXX \;

按時間先後作排序

find /istrpt/arlog/ -name "*.LOG" -print | xargs ls -lt