All commands (14,187)

  • If you should happen to find yourself needing some binary numbers, this is a quickie way of doing it. If you need more digits, just add more "{0..1}" sequences for each digit you need. You can assign them to an array, too, and access them by their decimal equivalent for a quickie binary to decimal conversion (for larger values it's probably better to use another method). Note: this works in bash, ksh and zsh. For zsh, though, you'll need to issue a setopt KSH_ARRAYS to make the array zero-based. binary=({0..1}{0..1}{0..1}{0..1}) echo ${binary[9]} Show Sample Output


    18
    echo {0..1}{0..1}{0..1}{0..1}
    dennisw · 2009-06-23 17:30:20 11
  • order the files by modification (thanks stanishjohnd) time, one file per output line and filter first 10


    7
    ls -1t | head -n10
    wires · 2009-06-23 12:15:12 9
  • ditto can be used to "thinnify" Mach-O Universal binaries to separate unncessary code from your machine. For example, doubleTwist.app shaved off around 10 MB while Google Earth went from 112 MB to 62 MB after extracting only the i386 code from them.


    0
    ditto --arch i386 doubleTwist.app doubleTwist_i386.app
    thebillywayne · 2009-06-22 23:59:14 12
  • Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command. Remeber if you want a priviliged port on your machine, you must use root or sudo account. Show Sample Output


    9
    ssh -L :: -L :: @
    starchox · 2009-06-22 19:12:48 1651
  • 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
  • This command gives you the number of lines of every file in the folder and its subfolders matching the search options specified in the find command. It also gives the total amount of lines of these files. The combination of print0 and files0-from options makes the whole command simple and efficient. Show Sample Output


    2
    find . -name "*.sql" -print0 | wc -l --files0-from=-
    vincentp · 2009-06-22 17:45:03 12
  • It works like a "tail -f" on several files. Use the number keys 0-9 to set a baseline in the numbered window. Pressing "b" let you scroll back in one of the windows.


    4
    multitail /var/log/messages /var/log/apache2/access.log /var/log/mail.info
    Neo23x0 · 2009-06-22 06:51:11 10
  • Uses logger in a while loop to log memory statistics frequently into the local syslog server.


    3
    while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done &
    Neo23x0 · 2009-06-22 00:29:53 7
  • Command binds a set of commands to the F12 key. Feel free to alter the dashboard according to your own needs. How to find the key codes? Type read Then press the desired key (example: F5) ^[[15~ Try bind '"\e[15~"':"\"ssh su@ip-address\C-m""" or bind '"\e[16~"':"\"apachectl -k restart\C-m""" Show Sample Output


    18
    bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""
    Neo23x0 · 2009-06-21 23:57:20 81
  • !* is all of the arguments to the previous command rather than just the last one. This is useful in many situations. Here's a simple example: vi cd /stuff oops! [exit vi, twice] !* expands to: cd /stuff


    99
    !*
    Neo23x0 · 2009-06-21 17:58:01 20
  • This command securely erases all the unused blocks on a partition. The unused blocks are the "free space" on the partition. Some of these blocks will contain data from previously deleted files. You might want to use this if you are given access to an old computer and you do not know its provenance. The command could be used while booted from a LiveCD to clear freespace space on old HD. On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives. NB depending on the size of the partition, this command could take a while to complete. Show Sample Output


    8
    # cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
    mpb · 2009-06-21 14:17:22 12

  • 3
    sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;# replace firefox
    plasticdoc · 2009-06-21 09:47:02 9
  • This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit. A couple of variants: A little bit bigger text: watch -t -n1 "date +%T|figlet -f big" You can try other figlet fonts, too. Big sideways characters: watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)' This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here). Show Sample Output


    48
    watch -t -n1 "date +%T|figlet"
    dennisw · 2009-06-21 01:02:37 39
  • sudo pmset -a hibernatemode 1 sets hiberate on. sudo pmset -a hibernatemode 0 sets hibernate off. from the pmset man page: 0001 (bit 0) enables hibernation; causes OS X to write memory state to hibernation image at sleep time. On wake (without bit 1 set) OS X will resume from the hibernation image. Bit 0 set (without bit 1 set) causes OS X to write memory state and immediately hibernate at sleep time. I often change my MacBook's sleep state. So I created a function for bash to make it a little easier. Usage: hibernate (on | off) "hibernate on" will set your laptop to hibernate if the lid is closed. "hibernate off" will set your laptop to sleep if the lid is closed. ### note : "proper" indentation isn't preserved on the website function hibernate() { case "${1}" in on) sudo pmset -a hibernatemode 1 echo Hibernate mode on. ;; off) sudo pmset -a hibernatemode 0 echo Hiberate mode off. ;; *) echo "I'm sorry Dave, but I can't do that." ;; esac } To make things easier, add the proper line in your /etc/sudoers file so that your user may invoke pmset without a password. Here's how mine looks: bwayne luna = NOPASSWD: /usr/bin/pmset Don't forget that you must edit sudoers with `sudo visudo` from Terminal.app, and not by another text editor. Sorry this is so Mac OS specific. Show Sample Output


    -1
    sudo pmset -a hibernatemode 1
    thebillywayne · 2009-06-20 22:52:10 8

  • 2
    svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
    tarzantiger · 2009-06-20 13:01:07 6

  • 3
    mplayer dvdnav:// -dvd-device foo.img -mouse-movements
    dezza · 2009-06-19 23:03:04 7

  • 6
    unrar p -inul foo.rar|mplayer -
    dezza · 2009-06-19 22:40:01 7
  • The option -an disables audio recording, -f forces the use of video4linux for the input, -s sets the video to the size 320x240, -b sets the recording bitrate, -r sets the frame rate to 15fps, -i gives the input device, -vcodec sets the output format. Press Q to stop recording or you can specify the recording time with the -t option like -t 00:1:30


    3
    ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi
    dcabanis · 2009-06-19 17:41:43 7
  • Encode video.avi into newvideo.avi using the libav codec to produce an MPEG4 file with a bitrate of 800


    1
    mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi
    dcabanis · 2009-06-19 17:30:46 7
  • video.avi is the resulting file. Press Ctrl+c to stop the recording. You can change the OVC option to another to record into a different format.


    1
    mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi
    dcabanis · 2009-06-19 17:21:33 7
  • GNU Sed can 'address' between two regex, but it continues parsing through to the end of the file. This slight alteration causes it to terminate reading the input file once the STOP match is made. In my example I have included an extra '/START/d' as my 'start' marker line contains the 'stop' string (I'm extracting data between 'resets' and using the time stamp as the 'start'). My previous coding using grep is slightly faster near the end of the file, but overall (extracting all the reset cycles in turn) the new SED method is quicker and a lot neater. Show Sample Output


    3
    sed -n '/START/,${/STOP/q;p}'
    mungewell · 2009-06-19 15:27:36 11

  • -5
    ga
    miccaman · 2009-06-19 12:20:10 5
  • insert filename Normal mode: "%p Insert mode: %


    1
    :r! echo %
    miccaman · 2009-06-19 12:17:28 13
  • src: daily vim blog


    3
    :source ~/.vimrc
    miccaman · 2009-06-19 12:14:55 6

  • 2
    :set nomore :argdo %s/foo/bar/g | update
    miccaman · 2009-06-19 12:12:33 25
  • ‹ First  < 483 484 485 486 487 >  Last ›

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

get newest jpg picture in a folder
search the newest *.jpg in the directory an make a copy to newest.jpg. Just change the extension to search other files. This is usefull eg. if your webcam saves all pictures in a folder and you like the put the last one on your homepage. This works even in a directory with 10000 pictures.

See system users

Create a new file

tar and bz2 a set of folders as individual files
This version will work if "*screenflow" returns any results with weird characters, and will actually compress the tarballs.

Change the extension of a filename by using rename to convert
This will change all files ending in .JPG to .jpg and will work with any file extension

Convert decimal numbers to binary
Convert some decimal numbers to binary numbers. You could also build a general base-converter: $ function convBase { echo "ibase=$1; obase=$2; $3" | bc; } then you could write $ function decToBun { convBase 10 2 $1; }

Auto Rotate Cube (compiz)
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 )

Print all git repos from a user

Find the package that installed a command

Keep one instance of an irc chat client in a screen session
This command attempts to attach to existing irssi session, if one exists, otherwise creates one. I use "irc" because I use different irc clients depending on what system I am working on. Consistency is queen.


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: