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

Go to the Nth line of file [text editor]
This is not printing, real editing using the text editor.

Keep a copy of the raw Youtube FLV,MP4,etc stored in /tmp/
Certain Flash video players (e.g. Youtube) write their video streams to disk in /tmp/ , but the files are unlinked. i.e. the player creates the file and then immediately deletes the filename (unlinking files in this way makes it hard to find them, and/or ensures their cleanup if the browser or plugin should crash etc.) But as long as the flash plugin's process runs, a file descriptor remains in its /proc/ hierarchy, from which we (and the player) still have access to the file. The method above worked nicely for me when I had 50 tabs open with Youtube videos and didn't want to have to re-download them all with some tool.

Benchmark SQL Query
Benchmark a SQL query against MySQL Server. The example runs the query 10 times, and you get the average runtime in the output. To ensure that the query does not get cached, use `RESET QUERY CACHE;` on top in the query file.

Get line number of all matches in a file

Put uppercase letters in curly brackets in a BibTeX database
It is often recommended to enclose capital letters in a BibTeX file in braces, so the letters will not be transformed to lower case, when imported from LaTeX. This is an attempt to apply this rule to a BibTeX database file. DO NOT USE sed '...' input.bib > input.bib as it will empty the file! How it works: $ /^\s*[^@%]/ Apply the search-and-replace rule to lines that start (^) with zero or more white spaces (\s*), followed by any character ([...]) that is *NOT* a "@" or a "%" (^@%). $ s===g Search (s) for some stuff and replace by other stuff. Do that globally (g) for all matches in each processed line. $ \([A-Z][A-Z]*\)\([^}A-Z]\|},$\) Matches at least one uppercase letter ([A-Z][A-Z]*) followed by a character that is EITHER not "}" and not a capital letter ([^}A-Z]) OR (|) it actually IS a "}", which is followed by "," at the end of the line ($). Putting regular expressions in escaped parentheses (\( and \), respectively) allows to dereference the matched string later. $ {\1}\2 Replace the matched string by "{", followed by part 1 of the matched string (\1), followed by "}", followed by the second part of the matched string (\2). I tried this with GNU sed, only, version 4.2.1.

Sort a character string
Sorts a character string, using common shell commands.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Happy Days
This never gets old

Calculate your total world compile time. (Gentoo Distros)
From Gentoo Forum, greetings to rudregues & steveL.

display date of last time a process was started in `date` format
STARTED Mon Oct 18 04:02:01 2010


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: