Commands by Alanceil (12)

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


    39
    python -m http.server
    Alanceil · 2010-12-17 12:52:45 43
  • 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.


    6
    qdbus org.kde.screenlocker /MainApplication quit
    Alanceil · 2009-08-27 13:57:00 4
  • 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. Show Sample Output


    1
    equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
    Alanceil · 2009-07-30 01:12:10 6
  • 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) Show Sample Output


    5
    wget -q --user=<username> --password=<password> 'https://updates.opendns.com/nic/update?hostname=your_opendns_hostname&myip=your_ip' -O -
    Alanceil · 2009-06-22 18:08:42 24
  • 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. Show Sample Output


    11
    shopt -s globstar
    Alanceil · 2009-05-05 16:02:44 8
  • 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.


    15
    xvkbd -xsendevent -text "Hello world"
    Alanceil · 2009-03-20 18:58:05 13
  • 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\"`"


    1
    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
    Alanceil · 2009-03-20 14:48:32 8
  • 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


    26
    lynx -accept_all_cookies -cmd_script=/your/keystroke-file
    Alanceil · 2009-03-17 00:38:36 13
  • 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). Show Sample Output


    8
    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 ]
    Alanceil · 2009-03-06 21:29:13 10
  • wrestool can be found in icoutils (http://www.nongnu.org/icoutils) Show Sample Output


    1
    wrestool -x --output . -t14 /path/to/your-file.exe
    Alanceil · 2009-02-28 22:51:32 7
  • 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.


    20
    taskset -c 0 your_command
    Alanceil · 2009-02-28 22:38:02 17
  • 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"


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

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Replicate a directory structure dropping the files

find out how many days since given date
You can also do this for seconds, minutes, hours, etc... Can't use dates before the epoch, though.

Count number of files in subdirectories
For each directory from the current one, list the counts of files in each of these directories. Change the -maxdepth to drill down further through directories.

Adequately order the page numbers to print a booklet
Useful if you don't have at hand the ability to automatically create a booklet, but still want to. F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed. In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en : 1) Click File ▸ Print. 2) Choose the General tab. Under Range, choose Pages. Type the numbers of the pages in this order (this is what this one-liner does for you): n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11... ...until you have typed n-number of pages. 3) Choose the Page Setup tab. - Assuming a duplex printer: Under Layout, in the Two-side menu, select Short Edge (Flip). - If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages. In the Pages per side option, select 2. In the Page ordering menu, select Left to right. 4) Click Print.

Sort files by date
Show you the list of files of current directory sorted by date youngest to oldest, remove the 'r' if you want it in the otherway.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

reverse-i-search: Search through your command line history
"What it actually shows is going to be dependent on the commands you've previously entered. When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it). If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental. Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

Get the list of local files that changed since their last upload in an S3 bucket
Can be useful to granulary flush files in a CDN after they've been changed in the S3 bucket.

print DateTimeOriginal from EXIF data for all files in folder
see output from `identify -verbose` for other keywords to filter for (e.g. date:create, exif:DateTime, EXIF:ExifOffset).

Change every instance of OLD to NEW in file FILE
Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)


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: