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

All commands from sorted by
Terminal - All commands - 11,605 results
dsadd group cn=group_name,dc=example,dc=com -secgrp yes -scope g -samid group_name
2014-03-06 15:25:17
Functions: yes
Tags: windows group cmd
0

-secgrp no for distribution

-scope u for distribution

alias t__s='date "+%FT%T"'
2014-03-06 04:37:55
User: UncleLouie
Functions: alias
0

This can be easier to look at in ls output. Not as clean as +%Y%m%dT%H%M%S, but quicker to write.

while true; do xdotool mousemove_relative 1 1; xdotool mousemove_relative -- -1 -1; sleep $((60 * 4)); done
2014-03-06 00:04:45
User: FreedomBen
Functions: sleep
Tags: xdotool
2

Moves the mouse 1 pixel down and to the right, then immediately back again, every 4 minutes. This keeps screensavers from turning on. I have used this extensively and I've never even noticed the mouse movement because it is so subtle.

grep -o -P '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}\s->\s{5}[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}' <capture file> | tr -d ' ' | sed 's/:.....//g' | sort -n | uniq -c | sort -nr
2014-03-05 21:34:42
User: santizo
Functions: grep sed sort tr uniq
1

Sort netflow packet capture by unique connections excluding source port.

rename *.JPG *.jpg
2014-03-05 14:54:33
User: gtoal
Functions: rename
Tags: batch rename
-1

# Limited and very hacky wildcard rename

# works for rename *.ext *.other

# and for rename file.* other.*

# but fails for rename file*ext other*other and many more

# Might be good to merge this technique with mmv command...

mv-helper() {

argv="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //'`"

files="`echo \"$argv\"|sed -e \"s/ .*//\"`"

str="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //' | tr -d \*`"

set -- $str

for file in $files

do

echo mv $file `echo $file|sed -e "s/$1/$2/"`

mv $file `echo $file|sed -e "s/$1/$2/"`

done

}

alias rename='mv-helper #'

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

perldoc -m Some::Module
kill `pidof conky`
bashrc-reload() { builtin unalias -a; builtin unset -f $(builtin declare -F | sed 's/^.*declare[[:blank:]]\+-f[[:blank:]]\+//'); . ~/.bashrc; }
2014-03-02 14:24:18
User: Xk2c
Functions: sed unalias unset
2

Simply sourcing .bashrc does not function correctly when you edit it and change an alias for a function or the other way round with the *same name*.

I therefor use this function. Prior to re-sourcing .bashrc it unsets all aliases and functions.

pdftk *.pdf cat output merged.pdf
2014-03-02 01:53:37
User: o0110o
Functions: cat
2

Merge Multiple PDFs In Alphabetical Order

lspci -vv | grep 'Ethernet\|Serial' | awk 'NR == 1{ printf $1 } NR == 2 { print " mac " $7 }' | sed ?e 's/-/:/g' -e 's/:f[ef]:f[ef]//g' -e 's/01:00.0/eth0/g' -e 's/01:00.1/eth1/g' -e 's/01:00.2/eth2/g' -e 's/01:00.3/eth3/g' > /etc/iftab && ifrename
2014-03-01 20:07:18
User: PROJAK_SX
Functions: awk grep lspci printf sed
0

for redhat systems works sometimes :S tested on dell poweredge r7+ systems

esxcli network ip interface ipv4 set -i vmk1 -I 10.27.51.143 -N 255.255.255.0 -t static
df -h --total | awk 'NR==1; END{print}'
cat /proc/cpuinfo | grep BogoMIPS | uniq | sed 's/^.*://g' | awk '{print($1 / 4) }'
locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|less
2014-02-28 13:52:15
Functions: grep locate xargs
0

Another way to view some code by keyword and basic regular expression

htop -p `pgrep firefox`
git tag rel--`date +%Y-%m-%d--%H-%M-%S` -m "(%) rel: stage"
find . -name "*.txt" | xargs -n 1 perl -pi -w -e "s/text([0-9])/other\$1/g;"
2014-02-28 06:38:38
User: kennethjor
Functions: find perl xargs
0

Does a search and replace across multiple files with a subgroup replacement.

arecord -q -f cd -d 1 recvol.wav;sox recvol.wav -n stat 2>&1|grep RMS|grep amplitude|cut -d"." -f2|cut -c 1-2>recvol;echo $((`cat recvol`+1))>recvol;rec -t wav - silence 1 0.1 `cat recvol` -1 1.0 `cat recvol`%|lame -s 44.1 -a -v - >record.mp3
2014-02-27 23:23:55
User: geaplanet
Functions: arecord cd cut echo grep stat
0

It find out the mic recording level at the moment of run the command and if a noise level is higher it starts to record an mp3 file. The resulting file will have only the sounds not the silences.

sudo update-grub
2014-02-27 19:50:25
User: Anshik
Functions: sudo
-5

sudo gedit /etc/default/grub

This would open the Grub configuration file. In this file we have to edit the line

GRUB_CMDLINE_LINUX=""

to

GRUB_CMDLINE_LINUX="acpi_backlight=vendor"

for i in $(find . -regex '.*\/C.*\.cpp'); do svn mv `perl -e 'my $s=$ARGV[0]; $s=~m/(.*\/)C(.*)/; print "$s $1$2"' "$i"`; done
eval $(history | cut -c 8- | grep "adb connect [0-9]" | tail -1)
2014-02-27 14:44:27
User: CanOrhan
Functions: cut eval grep tail
0

Connects to the last adb connection in history.

pacman -Qdt -q | xargs pacman --noconfirm -R
2014-02-27 05:17:57
User: b_t
Functions: xargs
1

-Qdt Lists dependencies/packages which are no longer required by any packages

-q Output only package name (not the version number)

-R Remove package(s)

Rest is self-explanatory.

I just started out with Arch - so if there is any better/standard method to achieve the same - please suggest.