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 Alanceil from sorted by
Terminal - Commands by Alanceil - 12 results
python -m http.server
2010-12-17 12:52:45
User: Alanceil
Functions: python
23

In Python version 3, the module was merged into http.server. Gentlemen, change your aliases.

qdbus org.kde.screenlocker /MainApplication quit
2009-08-27 13:57:00
User: Alanceil
6

The unlock command for KDE 4.3 has changed from krunner_lock, this process doesn't exist anymore. So here's the update :-)

If qdbus complains about not being able to find X, put a "DISPLAY=:0 " (:0 being your X server display) in front of the command.

equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
2009-07-30 01:12:10
User: Alanceil
Functions: gawk sed sort
0

On a Gentoo system, this command will tell you which packets you have installed and sort them by how much space they consume. Good for finding out space-hogs when tidying up disk space.

wget -q --user=<username> --password=<password> 'https://updates.opendns.com/nic/update?hostname=your_opendns_hostname&myip=your_ip' -O -
2009-06-22 18:08:42
User: Alanceil
Functions: wget
5

Intended for dynamic ip OpenDNS users, this command will update your OpenDNS network IP.

For getting your IP, you can use one of the many one-liners here on commandlinefu.

Example:

I use this in a script which is run by kppp after it has successfully connected to my ISP:

---

#!/bin/bash

IP="`curl -s http://checkip.dyndns.org/ | grep -o '[[:digit:].]\+'`"

PW="hex-obfuscated-pw-here"

if [ "$IP" == "" ] ; then echo 'Not online.' ; exit 1

else

wget -q --user=topsecret --password="`echo $PW | xxd -ps -r`" 'https://updates.opendns.com/nic/update?hostname=myhostname&myip='"$IP" -O -

/etc/init.d/ntp-client restart &

fi

---

PS: DynDNS should use a similar method, if you know the URL, please post a comment. (Something with members.dyndns.org, if I recall correctly)

shopt -s globstar
2009-05-05 16:02:44
User: Alanceil
11

Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification.

In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application.

xvkbd -xsendevent -text "Hello world"
2009-03-20 18:58:05
User: Alanceil
15

This is a (last resort) way to automate applications that provide no other ways for automation, it would send 'Hello world' to the currently active window. See the manpage (and the -text and -window entries) for how to send special characters and target specific windows.

An example:

Using xwininfo, I get the id of my XPlanet background window:

alanceil@kvirasim:19:51:0:~> xwininfo

xwininfo: Please select the window about which you

would like information by clicking the

mouse in that window.

xwininfo: Window id: 0x3600001 "Xplanet 1.2.0"

Absolute upper-left X: 0

(..etc..)

Now I use xvkbd to tell it to close itself:

xvkbd -xsendevent -window 0x3600001 -text "Q"

Obviously, the best way is to put these commands in a shellscript - just make sure to include a short sleep (sleep .1 should suffice) after each xvkbd call, or some programs will become confused.

stty -F "/dev/ttyUSB0" 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke time 5 min 1 line 0
2009-03-20 14:48:32
User: Alanceil
Functions: stty time
1

I had a hard time in finding the correct settings to get reasonable output from a coin selector which sends its data over a serial line. In the end, minicom came to the rescue and pointed me on the right track.

So, if you need to do something similar, these settings may help you.

Replace ttyUSB0 with your device file, 9600 with your baud rate, 5 with your read timeout (10ths of a second), and 1 with the minimum numbers of characters you want to read.

You can then open the device file like you are used to do, example:

DATA="`xxd -ps -l 5 \"$DEV\"`"
lynx -accept_all_cookies -cmd_script=/your/keystroke-file
2009-03-17 00:38:36
User: Alanceil
25

This command will tell lynx to read keystrokes from the specified file - which can be used in a cronjob to auto-login on websites that give you points for logging in once a day *cough cough* (which is why I used -accept_all_cookies).

For creating your keystroke file, use:

lynx -cmd_log yourfile
INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
6

Suppose you made a backup of your hard disk with dd:

dd if=/dev/sda of=/mnt/disk/backup.img

This command enables you to mount a partition from inside this image, so you can access your files directly.

Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img).

wrestool -x --output . -t14 /path/to/your-file.exe
taskset -c 0 your_command
2009-02-28 22:38:02
User: Alanceil
Functions: taskset
19

This is useful if you have a program which doesn't work well with multicore CPUs. With taskset you can set its CPU affinity to run on only one core.

mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"
2009-02-28 22:18:17
User: Alanceil
9

I use this command to save RTSP video streams over night from one of our national TV stations, so I won't have to squeeze the data through my slow internet connection when I want to watch it the next day.

For ease of use, you might want to put this in a file:

#!/bin/bash

FILE="`basename \"$1\"`"

mplayer -dumpstream -dumpfile "$FILE" -playlist "$1"