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

RSS feed | Trackback URI

1 Comment »

Comment by Fred Subscribed to comments via email
2010-01-13 13:47:41

:>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.

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post