Linux Commands#File, Directory
search for files in a directory hierarchy
Operation | Commands |
---|---|
delete files before 7 days | find /testdir -type f -name "*test*" -mtime +6 -exec rm -rf {} \; |
find recently change files | find /testdir -mtime -5 -ls |
Operation | Commands |
---|---|
count file | find DIR -type f | wc -l |
count directory | find DIR -type d | wc -l |
count file and directory | find DIR -name \* | wc -l |
Operation | Commands |
---|---|
delete so many files | find /path -type f | xargs -n 10 rm |
move so many files | find . -maxdepth 1 -name "*.txt" |xargs mv -t tmp/ |
delete the file incluce space in name | find /path -type f -print0 | xargs -0 rm |
compress many files | find . -type f |xargs tar rvf test.tar You must not use “cf” but “rf”. |