Hide

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.

Hide

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:

Hide

News

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

Tags

Hide

Functions

Commands using tar from sorted by
Terminal - Commands using tar - 203 results
tar zcvf /path/to/your-`date +%Y-%m-%d`.tar.bz2 ./your/directory --exclude ./you/dont/want/to/include
ssh user@remote "cat /path/to/archive.tgz" | tar zxvf -
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
2012-02-03 16:24:08
User: 0disse0
Functions: find tar xargs
1

Finally, we can make the file "unchangeable"

sudo chattr +i

tmpfs(){ cd /;for i in $@;do tar czvf /tmp/$i $i;mount -t tmpfs tmpfs /$i;tar xvzf /tmp/$i;cd ~ ;}# usage: tmpfs etc var
tar czf git_mods_circa_dec23.tgz --files-from <(git ls-files -m)
tar -xaf archive.tar.gz --strip-components=1
2011-11-29 07:38:19
User: sirex
Functions: tar
Tags: tar strip
12

If archive has leading directory level same as archive name and you want to strip it, this command is for you.

tar xfz filename.tar.gz -C PathToDirectory
2011-11-17 12:43:56
User: Dhinesh
Functions: tar
Tags: tar.gz
11

The command extracting the tar contents into particular directory ...

while true; do nc -l 7000 | tar -xvf -; done
2011-10-26 23:43:51
User: anhpht
Functions: tar
18

At client side:

tar c myfile | nc localhost 7000 ##Send file myfile to server

tar c mydir | nc localhost 7000 ## Send directory mydir to server

tar -cf - /etc | tar -xf - -C </destination/folder>
tar cvf - /src | ( cd /dest ; tar xvf - )
2011-09-22 15:35:24
User: a8ksh4
Functions: cd tar
-3

This is how I've done it in the past

(cd src && tar -cf - .) | (cd dest && tar -xpf -)
2011-09-22 11:30:57
User: Cowboy
Functions: cd tar
0

Simple tar pipe to be used to copy directories while including hidden files and maintaining file permissions

find ./ -iname "*.dmp" -maxdepth 0 -type f -exec tar czvf {}.tar.gz --remove-files {} \; \;
2011-09-07 08:36:29
User: evilinside
Functions: find tar
0

This command will :

-Archive all *.dmp files individually (one file per archive) from current directory .

-Delete original file after has been compressed.

svn st -q | cut -c 2- | tr -d ' ' | xargs tar -czvf ../backup.tgz
2011-08-31 10:30:29
User: titus
Functions: cut tar tr xargs
1

This works more reliable for me ("cut -c 8-" had one more space, so it did not work)

find . -type d|xargs tar rf ~/dirstructure.tar --no-recursion
2011-08-03 16:21:10
User: gdevarajan
Functions: find tar xargs
1

The original suggestion did not work for me, when operating on folders located on an external mount (ie other than the root device) in Ubuntu. A variation using xargs does the trick.

ssh -C USER@HOST tar -c --exclude /proc --exclude /sys / | tar -x
cd / ; tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
2011-07-20 15:44:07
User: strzel_a
Functions: cd tar
0

Backup your entire system on a tar ball file format.

tar cf - . |(cd /targetdir; tar xvf -)
for i in *.tar.gz; do tar -x -v -z -f $i && rm -v $i; done
for i in "*.txt"; do tar -c -v -z -f $i.tar.gz "$i" && rm -v "$i"; done
tar -caf some_dir.tar.xz some_dir
2011-06-09 19:00:06
Functions: tar
0

the -a flag causes tar to automatically pick the right compressor to filter the archive through, based on the file extension. e.g.

"tar -xaf archive.tar.xz" is equivalent to "tar -xJf archive.tar.xz"

"tar -xaf archive.tar.gz" is equivalent to "tar -xzf archive.tar.gz"

No need to remember -z is gzip, -j is bzip2, -Z is .Z, -J is xz, and so on :)

tar jcpf /home/[usuario]/etc-$(hostname)-backup-$(date +%Y%m%d-%H%M%S).tar.bz2 /etc
2011-04-29 22:53:11
User: mack
Functions: date tar
-1

Simple Compressed Backup of the /etc

Linux compatible

mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/
2011-04-14 17:02:05
User: depesz
Functions: gzip mkdir tar tee
Tags: bash tee tar
-1

Sometimes you might need to have two copies of data that is in tar. You might unpack, and then copy, but if IO is slow, you might lower it by automatically writing it twice (or more times)

svn diff -r 1792:HEAD --summarize | awk '{if ($1 != "D") print $2}'| xargs -I {} tar rf incremental_release.tar {}
2011-04-05 15:00:49
User: windfold
Functions: awk diff tar xargs
Tags: bash svn awk xargs tar
0

The result of this command is a tar with all files that have been modified/added since revision 1792 until HEAD. This command is super useful for incremental releases.

tar -c bins/ | gzip -9 | openssl enc -base64
2011-02-24 22:15:23
User: mweed
Functions: gzip tar
1

Useful when you have multiple files or binary files that you need to transfer to a different host and scp or the like is unavailable.

To unpack on the destination host copy paste output using the opposite order:

openssl enc -d -base64 | gunzip | tar -x

Terminate openssl input using ^d

Note: gzip is outside of tar because using -z in tar produces lots of extra padding.

tar -cvz /<path>/ | gpg --encrypt --recipient <keyID> > /<backup-path>/backup_`date +%d_%m_%Y`.tar.gz.gpg
2011-02-23 14:19:08
User: kaiserkailua
Functions: gpg tar
Tags: GPG tar.gz
1

Create a encrypted tar.gz file from a directory on the fly. The encryption is done by GPG with a public key. The resulting filename is tagged with the date of creation. Very usefull for encrypted snapshots of folders.