awesome one-liners

+2 jan burg · November 8, 2014
Post your favorite one-liners, short or long, complicated or beautifully simple.

Double space a file:

sed G <filename>

Lower mtu values in /proc/sys:

sysctl -a 2>/dev/null | grep -i mtu | grep -v " 0" | awk "{ print \$1 }" | while IFS= read -r -- i; do sysctl -w "$i=200"; done >/dev/null 2>&1

Post a Reply


Oldest  Newest  Rating
0 jan burg · November 14, 2014
Nice use of tr, tr is just the coolest isn't it.

Here's a neat one I use in Android to lower brightness:

find /sys -type f | grep brightness | bash -c 'readarray i && for j in ${i_[_*_]_}; do echo 66 > $j; done 2>/dev/null'

**** Remove underscores.
+2 Colonel Panic · November 12, 2014
Break up files into batches folders of 100.  (Great for zone files)
i=0;for f in *;do d=$(printf %03d $((i/50+1)));let i++;mkdir -p $d;mv "$f" $d;done

Removes Mime Type extension of file ( => foo)  (also great for zone files before importing into bind, since .zone is a TLD now)
for file in $( find . -name "*zone") ; do mv $file $( echo $file | sed s/\.zone// ); done

Great function that will output a line of dashes to the exact width of the console.  Great for separating standard output. 
separator(){ printf '%*s\n' $(tput cols) '' | tr ' ' -; }
+1 jan burg · November 11, 2014
Very cool. I just tested this with a song I found, "Adventure Club: Do I see Color", starts off real nice but turns into dubstep :-( My repositories didn't have youtube-dl, but I downloaded the tarball here: There's also a windows exe at that url.

Find all files folders with a [:space:] in them and change it to an underscore:

find . | grep " " | while IFS= read -r -- i; do mv "${i}" "${i// /_}"; done

Find params can be changed to find only files, or folders, search a max or min depth, etc., all that cool find stuff.

Totally forgot to add this one lol, which checks if you're shellshock vulnerable:

env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
+1 Susan Moss · November 11, 2014

You can install youtube-dl from command line using pip:

$ sudo pip install youtube-dl
  • 1

Shell Scripting


A shell script is a computer program designed to be run by the Unix shell, a command line interpreter. The various dialects of shell scripts are considered to be scripting languages.

Bucky Roberts Administrator