Welcome to bashoneliners.com, a growing collection of practical and well-explained Bash tips and tricks. We are committed to review every contributed one-liner to ensure its high quality, practical usefulness, and a solid explanation of how it works. We want to document one-liners for frequent (non-trivial) tasks executed in the shell, written in the best possible way, following good practices known in the industry. To get the latest Bash one-liners, follow @bashoneliners on Twitter. If you find any problems, please report on GitHub Issues.
0 score

Use rsync instead of cp to get a progress indicator when copying large files

 $ rsync --progress largefile.gz somewhere/else/

Oct. 19, 2011, 12:48 a.m.Janos

0 score

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

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

Oct. 17, 2011, 11:23 p.m.versorge

0 score

Create and restore backups using cpio

 $ find . -xdev -print0 | cpio -oa0V | gzip > path_to_save.cpio.gz

Oct. 17, 2011, 11:06 p.m.Janos

0 score

Alert me by email when a disconnected or unreachable server comes back online

 $ while ! ping -c1 the_host_down; do sleep 1; done && date | mail -s 'the host is back!' me@example.com

Oct. 10, 2011, 8:26 p.m.janos

0 score

Add timestamp to the output of ping

 $ ping some_host | while read LINE; do echo $(date): $LINE; done

Oct. 10, 2011, 8:13 p.m.janos

0 score

Test a one-liner with echo commands first, pipe to bash when ready

 $ paste <(ls) <(ls | tr A-Z a-z) | while read OLD NEW; do echo mv -v $OLD $NEW; done | sh

Oct. 8, 2011, 1 p.m.janos

0 score

Find the most recently modified files in a directory and all subdirectories

 $ find /path/to/dir -type f | perl -ne 'chomp(@files = <>); my $p = 9; foreach my $f (sort { (stat($a))[$p] <=> (stat($b))[$p] } @files) { print scalar localtime((stat($f))[$p]), "\t", $f, "\n" }' | tail

Oct. 4, 2011, 10:25 p.m.janos

0 score

Delete unversioned files in a Subversion checkout directory and all subdirectories

 $ svn st | grep ^? | sed -e 's/^? *//' | xargs -i{} echo rm -fr "{}"

Oct. 3, 2011, 8:22 p.m.janos

0 score

Get the available space on a partition as a single numeric value

 $ df /path/to/dir | sed -ne 2p | awk '{print $4}'

Oct. 2, 2011, 5:41 p.m.Janos

0 score

Schedule a one-time task using "at" command and intuitive date specifications

 $ at now + 30 minutes

Sept. 25, 2011, 11:30 a.m.Janos

0 score

Aliases the ls command to display the way I like it

 $ alias ls='ls -lhGpt --color=always'

Sept. 22, 2011, 12:25 a.m.versorge

0 score

Find video files cached by the flash plugin in browsers

 $ file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:

Aug. 27, 2011, 1:46 p.m.Janos

0 score

Force the preferred language when downloading a web page with wget

 $ wget -–header='Accept-Language: en-us' http://www.timeanddate.com/calendar/index.html?year=2008&country=26 -O calendar.html

Aug. 21, 2011, 1:40 p.m.Janos

0 score

Burn the contents of a directory to dvd without needing a gui application

 $ growisofs -dvd-compat -Z /dev/scd0 -R -J -pad /path/to/dir

Aug. 14, 2011, 9:35 p.m.Janos

0 score

Convert all flac files in the current directory to mp3 format using "lame"

 $ for i in *.flac; do flac -c -d "$i" | lame -m j -b 192 -s 44.1 - "${i%.flac}.mp3"; done

Aug. 9, 2011, 9:57 p.m.Janos

0 score

Halt the system in Linux without the halt command or gui

 $ echo o > /proc/sysrq-trigger

Aug. 9, 2011, 9:55 p.m.Janos

0 score
0 score

Create an encrypted tar file with openssl

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

Aug. 9, 2011, 1:30 a.m.Janos

0 score

Make another user superuser in Ubuntu

 $ for i in $(grep :boss /etc/group | cut -f1 -d:); do adduser wife $i; done

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Change the label of a USB drive in Linux without a gui

 $ sudo mlabel -i /dev/sdd1 ::NewLabel

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Mirror from one Subversion repository to another Subversion repository

 $ bzr co https://repo1/proj1/trunk proj1 && cd proj1 && bzr push https://repo2/vendor/proj1/trunk

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Find Flash videos stored by browsers on a Mac

 $ find /private/ 2>/dev/null | grep /Flash

Aug. 5, 2011, 8:57 p.m.Janos