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

Commands by DaveQB from sorted by
Terminal - Commands by DaveQB - 9 results
watch -n1 'date "+%T"'
2011-02-16 00:33:51
User: DaveQB
Functions: watch
4

A console clock with the current time.

df /media/mountpoint |egrep -o '^[/a-z0-9]*'
2011-01-24 21:14:55
User: DaveQB
Functions: df egrep
Tags: grep,df
-1

Shorter way to find the device for a given mountpoint

sed '/'"<opening tag>"'/,/'"<closing tag>"'/{/'"<closing tag>"'/d;p};d' "<file>"
find * -maxdepth 1 -type f ! -name abc -delete
2010-07-19 00:29:59
User: DaveQB
Functions: find
5

Finds all files in the current directory and deletes them besides file called "abc"

echo "${1}" | egrep '^[[:digit:]]*$' ; if [ "$?" -eq 0 ] ; then sed -i "${1}"d $HOME/.ssh/known_hosts ; else printf "\tYou must enter a number!\n\n" ; exit 1 ; fi
2010-07-11 23:09:11
User: DaveQB
Functions: echo egrep exit printf sed
Tags: sed
-13

I have this as a file called deletekey in my ~/bin.

Makes life a little easier.

free -m | awk '/buffer/ {print $4}'
2010-06-27 23:30:27
User: DaveQB
Functions: awk free
Tags: ram free
3

Here we instead show a more real figure for how much free RAM you have when taking into consideration buffers that can be freed if needed.

Unix machines leave data in memory but marked it free to overwrite, so using the first line from the "free" command will mostly give you back a reading showing you are almost out of memory, but in fact you are not, as the system can free up memory as soon as it is needed.

I just noticed the free command is not on my OpenBSD box.

cd /some/empty/folder/website_diffs/sitename && wget -N http://domain.com/ 2>&1 |grep -q "o newer" || printf "Sites web page appears to have updated.\n\nSuggest you check it out.\n\n"|mail -s "Sites page updated." david@email.com
2010-05-09 07:28:42
User: DaveQB
Functions: cd grep mail printf wget
2

A cronjob command line to email someone when a webpages homepage is updated.

date +%A | cut -c $(( $(date +%A | wc -c) - 1 ))
2010-04-07 00:23:15
User: DaveQB
Functions: cut date wc
Tags: bash echo cut date wc
0

A command to find out what the day ends in. Can be edited slightly to find out what "any" output ends in.

NB: I haven't tested with weird and wonderful output.

INPUT=<input_video> && ffmpeg -i "$INPUT" -vn -f wav - | oggenc -o ${INPUT%%.*}.ogg -
2009-05-19 07:57:43
User: DaveQB
1

Assumes you have ffmpeg and oggenc.

Similar to other scripts here, but this time outputting to Ogg Vorbis.

I added the variable assignment for a nice output name.

This is part of an interactive bash script I have with a few little multimedia tasks in it.

http://www.dward.us/software/VSAK.sh