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 tagged tar from sorted by
Terminal - Commands tagged tar - 71 results
for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done
2009-11-11 00:50:52
User: alchandia
Functions: find tar
Tags: tar
-2

The magic is performed by the parameter -t

find <path> -name "*.tgz" -or -name "*.tar.gz" | while read file; do echo "$file: "; tar -tzf $file; done
2009-11-10 20:39:04
User: polaco
Functions: echo find read tar
Tags: find tar list
-2

This script will list all the files in the tarballs present on any folder or subfolder of the provided path. The while loop is for echoing the file name of the tarball before listing the files, so the tarball can be identified

ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
2009-11-10 20:06:47
User: polaco
Functions: ssh tar
9

This command will copy a folder tree (keeping the parent folders) through ssh. It will:

- compress the data

- stream the compressed data through ssh

- decompress the data on the local folder

This command will take no additional space on the host machine (no need to create compressed tar files, transfer it and then delete it on the host).

There is some situations (like mirroring a remote machine) where you simply cant wait for a huge time taking scp command or cant compress the data to a tarball on the host because of file system space limitation, so this command can do the job quite well.

This command performs very well mainly when a lot of data is involved in the process. If you copying a low amount of data, use scp instead (easier to type)

tar pzcvf /result_path/result.tar.gz /target_path/target_folder
2009-11-10 11:17:00
User: CafeNinja
Functions: tar
0

The command as given would create the file "/result_path/result.tar.gz" with the contents of the target folder including permissions and sub- folder structure.

openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3
2009-10-03 03:50:46
User: berot3
3

The lifehacker way: http://lifehacker.com/software/top/geek-to-live--encrypt-your-data-178005.php#Alternate%20Method:%20OpenSSL

"That command will encrypt the unencrypted-data.tar file with the password you choose and output the result to encrypted-data.tar.des3. To unlock the encrypted file, use the following command:"

openssl des3 -d -salt -in encrypted-data.tar.des3 -out unencrypted-data.tar
tar cvfz dir_name.tgz dir/
2009-09-15 10:20:20
Functions: tar
Tags: tar
0

This command creates tar zip of a directory and its sub-directories.

tar czf /path/archive_of_foo.`date -I`.tgz /path/foo
2009-09-07 05:45:33
Functions: tar
Tags: backup tar
1

creates a compressed tar archive of files in /path/foo and writes to a timestamped filename in /path.

tar --create --file /path/$HOSTNAME-my_name_file-$(date -I).tar.gz --atime-preserve -p -P --same-owner -z /path/
2009-09-07 04:52:12
User: Odin_sv
Functions: date tar
Tags: backup tar
1

Use tar command for a backup info with a date of creation

cat files.txt | xargs tar -cv | tar -x -c $DIR/
2009-08-06 22:55:21
User: lingo
Functions: cat tar xargs
0

If you want certain files out of a directory hierarchy, this will copy just the listed files, but will create the directory hierarchy in the new location ($DIR/)

tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
2009-07-23 06:03:39
User: recursiverse
Functions: c++ tar
5

command to decrypt:

openssl enc -aes-256-cbc -d < secret.tar.enc | tar x

Of course, don't forget to rm the original files ;) You may also want to look at the openssl docs for more options.

(cd /source/dir ; tar cv .)|(cd /dest/dir ; tar xv)
2009-07-19 10:31:13
User: marssi
Functions: cd tar
-11

the f is for file and - stdout, This way little shorter.

I Like copy-directory function It does the job but looks like SH**, and this doesn't understand folders with whitespaces and can only handle full path, but otherwise fine,

function copy-directory () { ; FrDir="$(echo $1 | sed 's:/: :g' | awk '/ / {print $NF}')" ; SiZe="$(du -sb $1 | awk '{print $1}')" ; (cd $1 ; cd .. ; tar c $FrDir/ )|pv -s $SiZe|(cd $2 ; tar x ) ; }

tar -pczf archive_name.tar.gz /path/to/dir/or/file
2009-07-17 19:53:02
User: ryuslash
Functions: tar
Tags: bash tar gzip
-2

Create a single tar.gz archive

I know it's a very basic one, but it's one I keep forgetting.

7z x -so testfile.tar.7z | tar tvf -
2009-07-15 21:00:58
User: slashdot
Functions: tar
2

Sometimes it is handy to be able to list contents of a tar file within a compressed archive, such as 7Zip in this instance, without having to extract the archive first. This is especially helpful when dealing with larger sized files.

tar cf - /path/to/data | 7z a -si archivename.tar.7z
2009-07-14 14:21:30
User: slashdot
Functions: tar
8

Using 7z to create archives is OK, but when you use tar, you preserve all file-specific information such as ownership, perms, etc. If that's important to you, this is a better way to do it.

tar -tf <file.tar.gz> | xargs rm -r
On target: "nc -l 4000 | tar xvf -" On source: "tar -cf - . | nc target_ip 4000"
2009-06-30 19:36:19
User: tiagofischer
Tags: tar nc
5

It bypasses encryption overhead of SSH and depending on configuration can be significantly faster.

It's recommended to use only in trusted networks.

pax -r -s ',^/,,' -f file.tar
2009-06-26 19:10:57
User: res0nat0r
Functions: pax
Tags: tar
0

Don't have GNU tar installed that supports the redirect option (-C)? Use this.

cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
2009-06-11 18:33:27
User: ElAlecs
Functions: cd tar
-3

Very simple and useful, you need to change the word "directory" for your directory

tar cvf - foodir | gzip > foo.tar.gz
2009-05-19 11:33:51
User: sharfah
Functions: gzip tar
Tags: tar gzip
-9

Where foodir is the directory you want to zip up.

gunzip < foo.tar.gz | tar xvf -
tar --exclude='.svn' -c -f /path/to/file.tar /path/to/directory