Handy Linux Commands
Some handy linux commands I use from time to time.
I’m posting this mostly for my own reference, but they might be of use to others.
Clearing a file
A quick and easy way to empty a large file, such as say, a log file, is the following:
cat > filename
-> then hit ctrl + d
Finding a recently modified file
The below command will find any files modified or created within the past three days.
find . -mtime -3
Number of files in a directory
You would be amazed how many times I wonder exactly how many files there are in a directory (and subdirectories) of say uploaded images (it was 5,843).
ls -1R | wc -l
Directory Size
Sometimes you need to know the size of the current folder’s sub directories.
du -h --max-depth=1

:>filename
That will clear the file immediately without needing to press ctrl-d
ls|wc -l
ls will write 1 filename per line when writing to a pipe, so the -1R is unneeded.