Lets have a quick bash

I wrote a quick reference for doing common things in bash, particularly for those things that I'm always forgetting.

Save the output of a command as a file:

$ ls *.txt > /path/to/file

Append the output of a command to a file:

$ echo 'Test.' >> /path/to/file

Get a list hidden files:

$ ls -A

Get a list only hidden files:

$ ls -d .??*

Get word count statistics:

$ wc -l < /path/to/file

Flags for wc:

–l
Count lines
–w
Count words
–c
Count characters

Compress a directory:

$ tar -cj directory > archive.tar.bz2

Extract an archive:

$ tar -xj < archive.tar.bz2

Flags for tar:

–j
Compress with bzip2 (.bz2)
–z
Compress with gzip (.gz)
–v
Show progress messages

Download a file over ftp or http:

$ wget http://domain/path/to/file
OR $ curl http://domain/path/to/file -o /path/to/output/file

Share your thoughts...

Brian Zerangue wrote on :

Very helpful! Thanks so much for posting!