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

Find and copy scattered mp3 files into one directory
No problem with word splitting. That should works on many Unix likes.

Stop Flash from tracking everything you do.
Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.

Enter parameter if empty (script becomes interactive when parameters are missing)
Can be used for command line parameters too. If you have a more complicated way of entering values (validation, GUI, ...), then write a function i.e. EnterValue() that echoes the value and then you can write: $ param=${param:-$(EnterValue)}

Change user within ssh session retaining the current MIT cookie for X-forwarding
When you remotely log in like "ssh -X userA:host" and become a different user with "su UserB", X-forwarding will not work anymore since /home/UserB/.Xauthority does not exist. This will use UserA's information stored in .Xauthority for UserB to enable X-forwarding. Watch http://prefetch.net/blog/index.php/2008/04/05/respect-my-xauthority/ for details.

Cut out a piece of film from a file. Choose an arbitrary length and starting time.
With: -vcodec, you choose what video codec the new file should be encoded with. Run ffmpeg -formats E to list all available video and audio encoders and file formats. copy, you choose the video encoder that just copies the file. -acodec, you choose what audio codec the new file should be encoded with. copy, you choose the audio encoder that just copies the file. -i originalfile, you provide the filename of the original file to ffmpeg -ss 00:01:30, you choose the starting time on the original file in this case 1 min and 30 seconds into the film -t 0:0:20, you choose the length of the new film newfile, you choose the name of the file created. Here is more information of how to use ffmpeg: http://www.ffmpeg.org/ffmpeg-doc.html

Validating a file with checksum
Makes sure the contents of "myfile" are the same contents that the author intended given the author's md5 hash of that file ("c84fa6b830e38ee8a551df61172d53d7").

find files ignoring .svn and its decendents

Converts multiple youtube links to mp3 files
Usage: ytmp3 "YTurl" "YTurl2" "YTurl3" "YTurlN" Uses the shift command to let you extract the .mp3 from as many youtube urls as you like (or wherever else youtube-dl is supported) *Requires youtube-dl Orginal chunk of code: youtube-dl -q -t --extract-audio --audio-format mp3 URL taken from here http://www.commandlinefu.com/commands/view/9701/convert-youtube-videos-to-mp3

list files recursively by size

Run a script in parrallel over ssh
Runs a local script over ssh assuming ssh keys are in place. -P argument prints results to stdout. # Uses - https://code.google.com/p/parallel-ssh/


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: