May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

find shell

Find files larger than 100MB…

find . -size +100000000c -ls
Old Files
Find files last modified over 30days ago…

find . -type f -mtime 30 -ls
Find files last modified over 365days ago…

find . -type f -mtime 365 -ls
Find files last accessed over 30days ago…

find . -type f -atime 30 -ls
Find files last accessed over 365days ago…

find . -type f -atime 365 -ls
Find Recently Updated Files
There have been instances where a runaway process is seemingly using up any and all space left on a partition. Finding the culprit file is always useful.

If the file is being updated at the current time then we can use find to find files modified in the last day…

find . -type f -mtime -1 -ls
Better still, if we know a file is being written to now, we can touch a file and ask the find command to list any files updated after the timestamp of that file, which will logically then list the rogue file in question.

touch testfile
find . -type f -newer testfile -ls
Finding tar Files
A clean up of redundant tar (backup) files, after completing a piece of work say, is sometimes forgotten. Conversely, if tar files are needed, they can be identified and duly compressed (using compress or gzip) if not already done so, to help save space. Either way, the following lists all tar files for review.

find . -type f -name “*.tar” -ls
find . -type f -name “*.tar.Z” -ls
Large Directories
List, in order, the largest sub-directories (units are in Kb)…

du -sk * | sort -n
Sometimes it is useful to then cd into that suspect directory and re-run the du command until the large files are found.

Removing Files using Find
The above find commands can be edited to remove the files found rather than list them. The “-ls” switch can be changed for “-exec rm {}\;”=.

e.g.

find . -type f -mtime 365 -exec rm {} \;

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>