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,492 results
find . -name "*.txt" -exec WHATEVER_COMMAND {} \;
num_errs=`grep ERROR /var/log/syslog | tee >(cat >&2) | wc -l`
2014-03-12 00:04:24
Functions: cat tee wc
0

Many circumstances call for creating variable of a summary result while still printing the original pipe. Inserting "tee >(cat >&2)" allows the command output to still be printed while permitting the same output to be processed into a variable.

lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{printf ">/proc/%s/fd/%d\n", $2,$4}'
2014-03-11 10:40:32
User: wejn
Functions: gawk
Tags: awk lsof gawk
1

While the posted solution works, I'm a bit uneasy about the "%d" part. This would be hyper-correct approach:

lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{sub(/.$/,"",$4);printf ">/proc/%s/fd/%s\n", $2,$4}'

Oh, and you gotta pipe the result to sh if you want it to actually trim the files. ;)

Btw, this approach also removes false negatives (OP's command skips any deleted files with "txt" in their name).

lsof | grep -i deleted | grep REG | grep -v txt | ruby -r 'pp' -e 'STDIN.each do |v| a = v.split(/ +/); puts `:> /proc/#{a[1]}/fd/#{a[3].chop}`; end'
2014-03-11 06:02:09
User: jim80net
Functions: grep
0

Be careful, first run:

lsof | grep -i deleted | grep REG | grep -v txt

Then, give it the boot!

killall conky
find . \( -iname "*.doc" -o -iname "*.docx" \) -type f -exec ls -l --full-time {} +|sort -k 6,7
ffmpeg -i $video -c:v prores -profile:v 2 -c:a copy ${video}.mov
cat skype_log | sed -s 's/\(\[.*\]\) \(.*\): \(.*\)/<\2> \3/'
read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait
trash-put junkfolder
2014-03-09 00:24:09
User: Sepero
Tags: trash
0

apt-get install trash-cli

Commandline program that allows you put folders or files in the standard KDE/Unity desktop trash.

inotifywait -mr -e CREATE $HOME/bin/ | while read i; do chmod +x $(echo "$i" | sed 's/ \S* //'); done
/opt/homebrew-cask/Caskroom/vlc/2.1.0/VLC.app/Contents/MacOS/VLC --sout-avcodec-strict=-2 -I dummy $video :sout="#transcode{vcodec=h264,vb=1024,acodec=mpga,ab=256,scale=1,channels=2,audio-sync}:std{access=file,mux=mp4,dst=${video}.m4v}" vlc://quit
2014-03-08 13:53:13
User: brainstorm
0

Transcodes mpg2 files, that cannot be read by iMovie to m4v files.

sudo lshw -html > /tmp/hardware.html && xdg-open /tmp/hardware.html
2014-03-08 10:40:21
User: Sadi
Functions: sudo
0

entering this command as root may give more complete results, creating a tmp file, and immediately opening the file might be more useful

grep -r --include=*.php "something" /foo/bar
2014-03-07 13:26:12
User: avpod2
Functions: grep
0

Actually grep can do recursive search based on file extensions.

ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName
2014-03-07 05:52:11
User: unni9946
0

This command is used to stream a video file as live to some streaming server like Wowza, Red5 . etc

sar -n DEV -f /var/log/sa/sa05 |awk '{if ($3 == "IFACE" || $3 == "eth0" || $2 == "eth0") {print}}'
2014-03-06 21:32:54
Functions: awk
0

Choose the /var/log/sa/saXX log based on what day you want to view. You can use ifconfig to find the name of the interface.

You can use the -s flag to specify a certain time period, e.g. -s 12:00:00 -e 14:00:00

dsquery group -samid "group_name" | dsmod group "cn=group_name",dc=example,dc=com" -addmbr
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