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 -cf "../${PWD##*/}.tar" .
2013-11-06 11:15:38
User: joedhon
Functions: tar
-1

should do the same as command #12875, just shorter.

ORIGDIR=${PWD##*/}; PARENT=`dirname $PWD`; tar -C $PARENT -cf ../${ORIGDIR}.tar $ORIGDIR
2013-11-04 18:44:34
User: vwal
Functions: tar
1

tars the current directory (and its children) in an archive of the same name (plus ".tar" :)) in the parent directory without the absolute path, so that when the archive is extracted, only the current directory name is created for the path. Assumes bash/zsh.

tar -zcvf archive_name.tar.gz directory_to_compress
gzip -cd gzippedarchive.tar.gz | tar -xf -
2013-09-18 17:41:25
User: RAKK
Functions: gzip tar
Tags: gzip aix
0

This command is for UNIX OSes that have plain vanilla System V UNIX commands instead of their more functional GNU counterparts, such as IBM AIX.

for i in */; do echo tar -cjf "${i%/}.tar.bz2" "$i"; done
2013-08-20 22:13:28
User: sudopeople
Functions: echo tar
1

Remove the "echo" to actually archive.

Many similar commands are found on commandlinefu but I end up needing this very specific one from time to time.

To extract any of them, use the standard tar.bz2 extract command:

tar xvjf folder1.tar.bz2
sudo tar -zcvf $(hostname)-etc-back-`date +%d`-`date +%m`-`date +%y`.tar.gz /etc && sudo chown $USER:$USER $(hostname)-etc-back*
2013-08-18 12:49:11
User: thanosme
Functions: chown sudo tar
Tags: backup tar date
0

Back up /etc directory with a name based on the current date and the hostname of the machine, then chown the file for the current user for use.

cd /srcfolder; tar -czf - . | pv -s `du -sb . | awk '{print $1}'` | ssh -c arcfour,blowfish-cbc -p 50005 root@destination.com "tar -xzvf - -C /dstfolder"
2013-05-30 07:21:06
User: bhbmaster
Functions: awk cd ssh tar
Tags: ssh tar pv
0

NOTE: When doing these commands when asked for questions there might be flowing text from the pv doing the progress bar just continue typing as if its not there, close your eyes if it helps, there might be a yes or no question, type "yes" and ENTER to it, and also it will ask for a password, just put in your password and ENTER

I talk alot more about this and alot of other variations of this command on my site:

http://www.kossboss.com/linuxtarpvncssh

while true; do nc -l -p 50002 | pv | tar -xf -; done
2013-05-30 07:17:23
User: bhbmaster
Functions: tar
Tags: tar nc pv
0

Do above at the Destination aka The Server.

Do the following at the Source aka The Client:

tar -cf - /srcfolder | pv | nc www.home.com 50002

If you want ETAs and stuff:

tar -cf - /srcfolder | pv -s `du -sb /srcfolder | awk '{print $1}'` | nc www.home.com 50002

If you dont care about progress bars @ server/destination:

tar -cf - /srcfolder | pv | nc www.home.com 50002

If you dont care about progress bars @ client/source:

tar -cf - /srcfolder | pv -s `du -sb /srcfolder | awk '{print $1}'` | nc www.home.com 50002

I have this in alot better detail where there is more room to talk about it on my site:

http://www.kossboss.com/linuxtarpvncssh

cat file.gz.cpt *[a-z] | ccdecrypt -k yoursecretpassword | tar -xzf -
tar czf - /directory/to/tar | ccrypt -k yourpassword | split -b50m - /final/encrypted.cpt
tar cfp - file-to-be-archived | gzip > archive.tar.gz
XZ_OPT=-9 tar cJf tarfile.tar.xz directory
2013-03-30 06:00:39
Functions: tar
0

is preserving creation time, modification time, permission, the directory structure, etc.

tar zcf - foo | gpg -c --cipher-algo aes256 -o foo.tgz.gpg
2013-03-13 09:44:39
User: skkzsh
Functions: gpg tar
0

Decrypt with:

gpg -o- foo.tgz.gpg | tar zxvf -
wget -O- http://example.com/mytarball.tgz | tee mytarball.tgz | tar xzv
2013-03-06 11:11:28
Functions: tar tee wget
0

Very similar as doing "wget http://example.com/mytarball|tar xzv", this one involves the "tee" command between both, which will simultaneously write the tarball and copy it to stdout. So this command will locally save the tarball and extract it - both at the same time while it downloads.

tar -zcvf <archive<.tar.gz --exclude /home/szimbaro/tmp /home/szimbaro
tar --create --file - --posix --gzip -- <dir> | openssl enc -e -aes256 -out <file>
2012-11-27 15:33:45
User: seb1245
Functions: tar
19

Create an AES256 encrypted and compressed tar archive.

User is prompted to enter the password.

Decrypt with:

openssl enc -d -aes256 -in <file> | tar --extract --file - --gzip
tar -cjf - $DIR | nc $HOST $PORT
2012-11-13 16:44:26
Functions: tar
Tags: netcat tar
0

Tar's up $DIR locally (w/bzip2) and sends remotely to $HOST:$PORT where netcat listens (using openbsd netcat). Start up receiving side command first, then execute this.

tar --lzma -xvf /path/to/archive
tar -zcvf file.tgz ./
find ./ -type f -name "*.txt" -exec tar uvf myarchives.tar {} +
2012-07-29 00:35:58
User: bugmenot
Functions: find tar
4

Note: the tar archive must not exist in order to create it. If exists it will only be updated and no already existent files in present search will still remain in the tar archive. The update option has to be used instead of create because the command tar may be executed more than once depending on the number of arguments that find throws. You can see maximum number of arguments with 'getconf ARG_MAX'

ssh -l username server.tdl "tar -czf - /home/username/public_html" | tar -xzf -
tar -cvzf home_backup.tar.gz --exclude={.*,Downloads} /home/<user>
2012-07-24 12:16:33
User: mesuutt
Functions: tar
4

If you want to exclude only one file or directory you should use as --exclude=file_or_directory

tar cvzf - /folder/ | ssh root@192.168.0.1 "dd of=/dest/folder/file.tar.gz"
2012-07-13 17:54:51
User: kruspemsv
Functions: ssh tar
1

You can ran this also with cat for example:

tar zcvf - /folder/ | ssh root@192.168.0.1 "cat > /dest/folder/file.tar.gz"

Or even run other command's:

tcpdump | ssh root@10.0.0.1 "cat > /tmp/tcpdump.log"
tar zcpvf backup.tgz $(find $HOME -maxdepth 1 -name '.*' -and -not -name '.')
2012-05-01 17:48:24
User: DavidAlfonso
Functions: find tar
Tags: backup
0

This will make a backup of all hidden files and folders in the home folder.

GZIP="--rsyncable" tar -czf something.tgz /something