What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




Commands using tar from sorted by
Terminal - Commands using tar - 193 results
tar -jcvf /folder/file.tar.bz2 --same-owner --same-permissions /folder/
tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
2009-02-18 19:31:27
User: starchox
Functions: tar

You can exclude more system folders or individual files which are not necessary for the backup and can be recreated after the restore procedure, like /lost+found, /mnt, /media, /tmp, /usr ...

Restoring the above backup procedure is as simple as becoming root and typing:

tar zxpf backup.tgz -C /

You can extract any file or directory out of the backup.tgz file for recovery, for instance, if you have a corrupt or mis-configured fstab file, you could simply issue the command:

tar zxpf backup.tgz /ect/fstab -C /

Other options:

v add verbose option to see files processed

A far safer solution is to restore the desired files under a different directory, and then compare, move, or update the files to their original locations afterward.

tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
2009-02-18 14:50:45
User: nlinux
Functions: tar

This command tar?s up a directory and sends the output to gzip, showing a rate of 223MB/s.

This may require you installing the pv command.

For debian based users out there:

sudo aptitude install pv
curl http://example.com/foo.tar.gz | tar zxvf -
for i in *.tar.gz *.tgz; do tar -zxvf $i; done
2009-02-18 10:58:12
User: bohemicus
Functions: tar

This is a little bash script that will take all files following the *gz pattern in the directory and apply the tar -zxvf command to them.

tar cvzf - /directory/ | ssh root@host "cat > /dev/nst0"
2009-02-18 07:12:54
User: Tuxmania
Functions: ssh tar

I use this all the time for taking manual backups of stuff i want to keep but not important enough to backup regularly.

find ~/bin/ -name "*sh" -print0 | xargs -0t tar -zcvf foofile.tar.gz
2009-02-17 08:48:34
User: lhb
Functions: find tar xargs

tar options may change ;)

c to compress into a tar file, z for gzip (j for bzip) man tar

-print0 and -0t are usefull for names with spaces, \, etc.

cd /source/directory; tar cf - . | tar xf - -C /destination/directory
(cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf -)
2009-02-16 09:36:34
Functions: cd tar

uses tar to dump files from /orignl/path to /dst/dir. i find tar's out more readable than cp, and it doesn't mess with modified dates.

tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup
2009-02-12 22:31:58
User: zb
Functions: find tar

due to bug can not comment

tar zcvf somedir-$(date +%Y%m%d-%H%M).tar.gz somedir/
2009-02-10 15:25:40
User: kmac
Functions: date tar

A useful bash function:



if [ $# -ne 1 ] ; then

echo "incorrect arguments: should be gztardir "


tar zcvf "${1%/}-$(date +%Y%m%d-%H%M).tar.gz" "$1"



svn st | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz
2009-02-09 11:24:31
User: chrisdrew
Functions: cut sed tar xargs

Create a tgz archive of all the files containing local changes relative to a subversion repository.

Add the '-q' option to only include files under version control:

svn st -q | cut -c 8- | sed 's/^/\"/;s/$/\"/' | xargs tar -czvf ../backup.tgz

Useful if you are not able to commit yet but want to create a quick backup of your work. Of course if you find yourself needing this it's probably a sign you should be using a branch, patches or distributed version control (git, mercurial, etc..)

wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -
cd /some/directory \&\& tar cf - | cd /some/directory \&\& tar xvf - */
tar -cvzf - /source/path | ssh <targethostname> -l <username> dd of=/destination/path/backupfile.tgz
2009-02-06 15:52:09
User: smm
Functions: dd ssh tar

Creates a quick backup with tar to a remote host over ssh.

tar cfvz - /home/user | netcat -l -p 10000
2009-02-05 21:05:40
User: ajrobinson
Functions: tar

tar's directory and sends to netcat listening on port 10000

On the client end:

netcat [server ip] 10000 | tar xfvz -

This will send it over the network and extract it on the clients machine.

tar -tvjf backup.tar.bz2 | sort -nrk 3 | head
tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination
2009-01-29 10:38:26
User: xsawyerx
Functions: ssh tar

it compresses the files and folders to stdout, secure copies it to the server's stdin and runs tar there to extract the input and output to whatever destination using -C. if you emit "-C /destination", it will extract it to the home folder of the user, much like `scp file user@server:`.

the "v" in the tar command can be removed for no verbosity.