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 m33600 from sorted by
Terminal - Commands by m33600 - 23 results
echo "disable" > /sys/firmware/acpi/interrupts/gpeXX
2013-07-16 03:53:20
User: m33600
Functions: echo
0

change gpeXX by the culprit you discovered on phase 1

In case of this example, the culprit is the biggest number, ie, gpe1C

/sys/firmware/acpi/interrupts/ff_gbl_lock: 0 enabled

/sys/firmware/acpi/interrupts/gpe01: 0 enabled

/sys/firmware/acpi/interrupts/gpe06: 0 enabled

/sys/firmware/acpi/interrupts/gpe17: 2 enabled

/sys/firmware/acpi/interrupts/gpe18: 0 enabled

/sys/firmware/acpi/interrupts/gpe1C: 19 enabled

This procedure,if solved this universal issue all linix distros are experimenting for more than 2 years, may be included at startup, via cron. But try first commandline.

grep enabled /sys/firmware/acpi/interrupts/*
2013-07-16 03:46:23
User: m33600
Functions: grep
0

Goto phase 2 to clobber the interrupt that is problematic.

synclient TapButton1=1 TapButton2=2 TapButton3=3
2013-07-16 03:37:21
User: m33600
0

Knoppix is Debian running in RAM, one of the best distros I've seen, but I had to left click the hardware button to use the system, because touchpad ignored taps. Not anymore

sendEmail -f anything@anithing.com -u subject of nessage -t youfriend@hisdomain -m message to him
curl -i -m 60 -k -u user:password 'https://updates.opendns.com/account/ddns.php?'
2010-02-07 02:40:38
User: m33600
2

Your IP is resolved by OpenDns Server (like a caller ID telephone, every server knows who is calling ;-)

Change user:password by yours

Be Happy

curl -u user:passwd -T /home/dir/local_file_to_upload ftp://your_host.com/subdir/
wmctrl -o 1280,0
2009-11-18 11:06:29
User: m33600
1

0-1279 = desktop 1 region = face 1

1280-2559 = face 2 ==>> wmctrl 1280 = wmctrl (1281,...2559) are all the same

for a 1280 monitor resolution

math: argument of wmctrl -o = ( DesiredFace * HorizontalResolution - 1)

curl http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg | xli -onroot -fill stdin
2009-11-12 22:00:19
User: m33600
Tags: kalarm
9

Changes the wallpaper for the last IR picture of the sun taken by SOHO satellite.

Lesser size, try

curl http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg | xli -onroot -fullscreen -xzoom 120 -yzoom 120 -border black stdin

I use inside kalarm(kde), updating every 15 minutes

needs xli , curl

curl http://www.cpa.unicamp.br/imagens/satelite/ult.gif | xli -onroot -fill stdin
2009-11-12 21:52:19
User: m33600
Tags: kalarm
4

Changes the wallpaper to the last satellite image.

Tha url above shows latin america. Seek the best url for your location

Now I have a usefull background image in my desktop

I use it inside kalarm updating every 15 minutes. May be done with 'watch' instead

It s an option to xplanet ( kde ) and xearth

needs xli , curl

curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i 40 -d 30 -l 2
2009-11-12 21:33:06
User: m33600
Functions: awk grep
-1

I have a custmer's Geovision DVR installed on a closed proxi (only logme-in reaches it).

I have to check for reliability but logmein hangs and is too slow a process

I made the Geovision software send e-mail every minute to the www.spam.la site.

All this script does is to retrieve the e-mail header from spam.la ( no login!), filtering sender, stopping at the first occurrence of the word "secs" ( the age of the last e-mail ).

The result is the age of the sender's last e-mail, tiny published on top of my screen once a minute.

I can refresh www.spam.la via web browser, but have other things to do.

I use it inside Kalarm ( kde task schedule ) set to 1 minute repeat.

It can be done without kalarm, using Watch outside the script.

Try it out now using my account = geo1 ( change sender by geo1 in this script)

Needs curl , osd-bin

STAT=`curl http://www.whatismyip.org/`; curl -u YourUserName:YourPassword -d status=$STAT http://twitter.com/statuses/update.xml
2009-10-26 23:02:30
User: m33600
-1

Easy way to find your computers IP in one place, ie, twitter

It suppress the need of dyndns clients and remembering the complex names they give you.

I put it inside KAlarm ( the cron GUI for KDE, ubuntu), to update my ip every 3 minutes.

I did not add the cron statements to keep the code clean.

wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0
2009-10-23 10:00:51
User: m33600
Functions: echo sleep
5

Strip my code to:

wmctrl -o 0,0 # autorotates to the first face. In fact [0-1279],0

wmctrl - 1280,0 # goes to the second face

wmctrl -o 2560,0 # goes to the third face, and so on.

# Use multiples of the horizontal display resolution.

My example work for 1280x800 display, been 1280 the number of interest.

Tweak the number, try a biiiig one and see your cube spinning...

I put a complex example to show how fun things can be, even for my ademco and paradox alarm central network advisor interface xpto etc. It rotates two faces, print the alarm message, and goes back tho where it was.

Tested on BIGLINUX 4.2, equivalent to ubuntu LTS hardy.

Do not forget to activate 3D efects ( compiz cube )

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
2009-10-23 07:56:30
User: m33600
Functions: date echo export printf watch
0

already described on the other two versions, this one uses ascii characters on game style to display elapsed time.

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
2009-10-23 07:47:11
User: m33600
Functions: date echo export printf watch
0

Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small.

Try changing fonts and sizes of osd_cat

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
2009-10-23 07:31:44
User: m33600
Functions: date echo export printf watch
3

Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch

Shows elapsed time from start of script in hh:mm:ss format

Non afected by system slow down due to the use of date.

acpi -t | osd_cat -p bottom
2009-10-23 05:22:01
User: m33600
Functions: acpi
2

My firefox overheats my cpu, sometimes above 90 degrees Celsius ( hence the name? )

To keep an eye on temperature, I put this command inside KAlarm ( a kind of cron) to be repeated every minute, for 5 seconds, color red ( default for osd_cat).

Its pretty, ultra small, displays a micro 2 lines text on every desktop and over everything and do not steal focus or interrupt any task. I get the information passively, in the low profile bottom of the screen.

Of course you can use it inside a terminal. Just do it:

watch -n 60 'acpi -t | osd_cat -p bottom'

xset led 3
2009-10-23 00:25:56
User: m33600
6

Usefull as a light blink to remember events, mails, intrusions, etc... yet another output

Since nobody ever uses the scroll lock function...

Usefull to interface a linux system with some hardware, for example, opto interfacing the keyboard led to a relay to remotely reset, etc. ( a simple LDR glued over the LED will do the trick )

xset led 3 turns on the third led, ie, Scroll lock

xset -led 3 turns it off

xset led 1 turns on Numerical Lock led ( doesn t work on all computer )

xset led 2 turns on Caps Lock led ( idem )

Using it as a reset watchdog, the relay expected light pulses. Shall the computer hangs, the relay releases and reset the machine ( discharge of a capacitor ) ;-)

echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
2009-10-19 05:28:15
User: m33600
Functions: acpi echo watch
1

This time I added a print to reemaining energy, every minute, time stamped.

The example shown here is complete and point to large discrepancies as time passes, converging to accuracy near the end.

echo start > battery.txt; watch -n 60 'date >> battery.txt'
2009-10-18 07:00:26
User: m33600
Functions: echo watch
0

Fully recharge your computer battery and start this script.

It will create or clean the file named battery.txt, print a start on it and every minute it will append a time stamp to it.

Batteries last few hours, and each hour will have 60 lines of time stamping. Really good for assuring the system was tested in real life with no surprises.

The last time stamp inside the battery.txt file is of interest. It is the time the computer went off, as the battery was dead!

Turn on your computer after that, on AC power of course, and open battery.txt. Read the first and last time stamps and now you really know if you can trust your computer sensors.

If you want a simple line of text inside the battery.txt file, use this:

watch -n 60 'date > battery.txt'

The time of death will be printed inside

curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml
2009-06-27 21:47:48
User: m33600
Tags: twitter
2

Found it on snipt, pok3, is it yours?

I put my user = m33600, the password and the status was my robot message:

Settima robot message: ALARM ZONE 3 (sent via command line).

Now bots may have their identity on twitter...

w3m -dump_head www.fiat.com | awk '/Date+/{print $6, $7}'
2009-06-08 00:06:01
User: m33600
Functions: awk
-1

w3m is a commanline web browser, full of options, I used -dump_head for less unnecessary page download.

With awk, I can retrieve dynamic changes in webpages in this very econnomical fashion

watch '/home/mm/bash/keypress.sh |/home/mm/bash/evento.sh'
2009-06-07 20:57:49
User: m33600
Functions: watch
-7

evento.sh needed for awk syntax

the aplay command makes a camera sound. It takes a picture of who looked at the display

#!/bin/bash

# evento.sh: deteta evento e fala

awk '{print}' | espeak -v pt -stdin

awk '/e/{print "emergencia"}' | espeak -v pt -stdin

aplay -q /home/mm/bash/camera.wav # -q inibe verbose do comand aplay

exit 0

awk '{print}' | espeak -v pt -stdin
2009-06-07 20:45:44
User: m33600
Functions: awk
0

Speaks whatever comes in via stdin (-v pt = portuguese, default = englisg)

..speech part of keyboard event talker. Made to accomplish a simple alarm central based on a cheap keyboard circuit. This way I have one zone per direct keypress. Depends on keypress.sh. It speaks out loud wich zone (key) has been pressed ( faulted ). Here is keypress.sh :

#!/bin/bash

# keypress.sh: Detect a user keypress ("hot keys").

echo

old_tty_settings=$(stty -g) # Save old settings (why?).

stty -icanon

Keypress=$(head -c1) # or $(dd bs=1 count=1 2> /dev/null)

# on non-GNU systems

aplay -q /home/mm/bash/beep-1.wav

echo

echo "Chamada quarto \""$Keypress"\"."

echo

stty "$old_tty_settings" # Restore old settings.

# Thanks, Stephane Chazelas.

exit 0