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 - 194 results
tar -xvpf file.tar.gz
2014-04-25 10:23:03
User: shajeen
Functions: tar
1

-x, --extract, --get

extract files from an archive

-p, --preserve-permissions, --same-permissions

extract information about file permissions (default for superuser)

-f, --file=ARCHIVE

use archive file or device ARCHIVE

-v, --verbose

verbosely list files processed

tar -cf - file1 dir1/ dir2/ | md5sum
2014-04-17 14:33:44
User: snipertyler
Functions: tar
-3

Doesn't create a file

Make sure to list the files / directories in the same order every time.

tar -cvf - /path/to/tar/up | xz - > myTarArchive.tar.xz
2014-03-18 19:51:50
User: razerwolf
Functions: tar
1

compress directory archive with xz compression, if tar doesn't have the -J option (OSX tar doesn't have -J)

tar -cJf myarchive.tar.xz /path/to/archive/
2014-03-13 03:34:18
User: Sepero
Functions: tar
1

Compress files or a directory to xz format. XZ has superior and faster compression than bzip2 in most cases. XZ is superior to 7zip format because it can save file permissions and other metadata data.

git log origin/master..master --name-only --pretty="format:" | sort | uniq | xargs tar -rf mytarfile.tar
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs tar -rf mytarfile.tar
2014-03-04 12:16:07
Functions: tar xargs
1

################################################################################

# get all modified files since last commit and zip them to upload to live server

################################################################################

# delete previous tar output file

rm mytarfile.tar -rf

#rm c:/tarOutput/*.* -rf

# get last commit id and store in variable

declare RESULT=$(git log --format="%H" | head -n1)

# generate file list and export to tar file

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $RESULT | xargs tar -rf mytarfile.tar

# extract tar files to specified location

tar -xf mytarfile.tar -C c:/tarOutput

tar --exclude='patternToExclude' --use-compress-program=pbzip2 -cf 'my-archive.tar.bz2' directoyToZip/
tar -axf fileNameHere.tgz
2014-02-01 16:14:22
User: toro
Functions: tar
Tags: tar
1

With -a you don't care about file type (bz2, gzip, etc.)

tar zxvf fileNameHere.tgz
2014-01-28 10:33:51
User: Jonas_E
Functions: tar
Tags: tar unpack
-2

tar command options:

-z : Uncompress the resulting archive with gzip command.

-x : Extract to disk from the archive.

-v : Produce verbose output i.e. show progress and file names while extracting files.

-f backup.tgz : Read the archive from the specified file called backup.tgz.

-C /tmp/data : Unpack/extract files in /tmp/data instead of the default current directory.

tar --exclude-from=$excludefile -zcvp "$source" | openssl aes-128-cbc -salt -out $targetfile -k $key
2013-12-13 19:35:20
User: klausman
Functions: tar
0

Create compressed, encrypted backup from $source to $targetfile with password $key and exclude-file $excludefile

find <PATH> -maxdepth 1 -type f -name "server.log*" -exec tar czPf '{}'.tar.gz --transform='s|.*/||' '{}' --remove-files \;
find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir/"; tar -g "$destdir"/"$tarfile".snar -czf "$destdir"/"$tarfile"_`date +%F`.tgz -P $d; done
find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir"; tar -czvf "$destdir"/"$tarfile"_`date +%F`.tgz -P $d; done
2013-12-05 19:18:03
User: jaimerosario
Functions: cut find read tar
1

Problem: I wanted to backup user data individually, using and incremental method. In this example, all user data is located in "/mnt/storage/profiles", and about 25 folders inside, each with a username ( /mnt/storage/profiles/mike; /mnt/storage/profiles/lucy ...)

I need each individual folder backed up, not the whole "/mnt/storage/profiles". So, using find while excluding directories depth and creating two variables (tarfile=username & desdir=destination), tar will create a .tgz file for each folder, resulting in a "mike_2013-12-05.tgz" and "lucy_2013-12-05.tgz".

find /mnt/storage/profiles/ -maxdepth 1 -mindepth 1 -type d | while read d; do tarfile=`echo "$d" | cut -d "/" -f5`; destdir="/local/backupdir/"; tar -czf $destdir/"$tarfile"_full.tgz -P $d; done
2013-12-05 19:07:17
User: jaimerosario
Functions: cut find read tar
1

Problem: I wanted to backup user data individually. In this example, all user data is located in "/mnt/storage/profiles", and about 25 folders inside, each with a username ( /mnt/storage/profiles/mike; /mnt/storage/profiles/lucy ...)

I need each individual folder backed up, not the whole "/mnt/storage/profiles". So, using find while excluding directories depth and creating two variables (tarfile=username & desdir=destination), tar will create a .tgz file for each folder, resulting in a "mike_full.tgz" and "lucy_full.tgz".

wget --no-check-certificate https://www.kernel.org/$(wget -qO- --no-check-certificate https://www.kernel.org | grep tar | head -n1 | cut -d\" -f2)
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