bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Test git archive before actually creating an archive // fake dry run

git archive master some/project/subdir | tar t

December 22, 2015openiduser146

List all non Git comited files and make a gzip archive with them

GITFOLDER="/srv/some/folder"   ls-files --others --exclude-standard | tar czf ${GITFOLDER}-archives/uploads-$(date '+%Y%m%d%H%M').tar.gz -T -

April 2, 2014renoirb

Do something in another directory without going there

(cd /path/to/somewhere; tar c .) > somewhere.tar

April 2, 2012bashoneliners

Create a compressed tar file that rsync will transfer efficiently

GZIP='--rsyncable' tar cvzf bobsbackup.tar.gz /home/bob

February 15, 2012Anon6y5E4Use

Export a git project to a directory

git archive master | tar x -C /path/to/dir/to/export

January 12, 2012bashoneliners

Copy a directory with a large number of files to another server

tar cp -C /path/to/dir . | ssh server2 'tar x -C /path/to/target'

November 17, 2011bashoneliners

Unpack all of the .tar.bz2 files in current directory

for FILE in *; do tar -jxf $FILE; done

October 17, 2011versorge

Create an encrypted tar file with openssl

tar c paths_to_files_and_dirs | gzip -c | openssl des3 > encrypted.tar.gz

August 9, 2011bashoneliners