Commands by h3xx (20)

  • Real gurus don't need fancy tools like iftop or jnettop. Show Sample Output


    9
    tcpdump -w - |pv -bert >/dev/null
    h3xx · 2011-12-14 00:24:02 7
  • For when you need a quick spell check. Show Sample Output


    10
    aspell -a <<< '<WORDS>'
    h3xx · 2011-11-30 01:47:46 7
  • This causes cp to detect and omit large blocks of nulls. Sparse files are useful for implying a lot of disk space without actually having to write it all out. http://en.wikipedia.org/wiki/Sparse_file You can use it in a pipe too: dd if=/dev/zero bs=1M count=5 |cp --sparse=always /dev/stdin SPARSE_FILE Show Sample Output


    4
    cp --sparse=always <SRC> <DST>
    h3xx · 2011-09-07 08:02:50 58
  • This is shorter and actually much faster than >/dev/null (see sample output for timings) Plus, it looks like a disappointed face emoticon. Show Sample Output


    22
    <COMMAND> |:
    h3xx · 2011-08-28 23:48:29 23
  • Ever ask yourself "How much data would be lost if I pressed the reset button?" Scary, isn't it? Show Sample Output


    34
    grep ^Dirty /proc/meminfo
    h3xx · 2011-08-24 08:48:49 16
  • Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too. On my Slackware box, this gets set upon login: LS_OPTIONS='-F -b -T 0 --color=auto' and alias ls='/bin/ls $LS_OPTIONS' which works great. Show Sample Output


    2
    lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
    h3xx · 2011-08-15 03:10:58 3

  • 0
    echo $(($(ulimit -u)-$(pgrep -u $USER|wc -l))
    h3xx · 2011-07-30 05:03:36 3
  • These are way better than fortune(6). Show Sample Output


    2
    grep -2riP '\b(fuck|shit|bitch|tits|ass\b)' /usr/src/linux/
    h3xx · 2011-07-27 23:11:02 7
  • For instance: find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8 will encode all .wav files into FLAC in parallel. Explanation of xargs flags: -P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage]. -n [max-args]: Max number of arguments from the list to send to each invocation. -0: Stdin is a null-terminated list. I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa


    2
    xargs -P 3 -n 1 <COMMAND> < <FILE_LIST>
    h3xx · 2011-07-25 22:53:32 34
  • Crash Override, man! Apparently the exec call tricks BASH into setting the output buffer size to 0 under the assumption that the system (or the calling shell) will handle the output buffering. trapping the ERR signal will stop the subshell from dying and sending the ERR signal to the main script--which will terminate immediately if it does--when the program fails. The only problem is that the kernel will output a whole bunch of stack trace garbage directly to the console device once the process segfaults, so there's no way to prevent it from being output [that I know of].


    0
    (trap 'true' ERR; exec <SEGFAULT_PRONE_PROGRAM>)
    h3xx · 2011-07-25 02:30:52 4
  • Even adds a newline.


    1
    xxd -p <<< <STRING>
    h3xx · 2011-07-24 19:16:32 3

  • 0
    read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2
    h3xx · 2011-07-24 18:56:30 3
  • You can also save EXIF information by copying it to temp.jpg: jpegtran -optimize -outfile temp.jpg <JPEG> && jhead -te temp.jpg "$_" && mv temp.jpg "$_"


    0
    jpegtran -optimize -outfile temp.jpg <JPEG> && mv temp.jpg "$_"
    h3xx · 2011-07-24 08:55:46 3
  • Or, aumix -v -5 Map these to key combinations in your window manager and who needs special buttons?


    0
    aumix -v +5
    h3xx · 2011-07-24 07:41:40 3
  • This forces X back to its maximum resolution configured. To get a list, type `xrandr'.


    2
    xrandr -s 0
    h3xx · 2011-07-24 07:38:01 3
  • Works really well for playing DVDs, which have the volume turned way down for some reason. The `2' method is better IMHO because it will adjust to changing loud/soft parts. If you want to add it to your ~/.mplayer/config: # format: volnorm[=method:target] # method: # 1: use single sample (default) # 2: multiple samples # target: # default is 0.25 af-add=volnorm=2:0.75


    3
    mplayer -af volnorm=2:0.75 dvd://
    h3xx · 2011-07-24 07:26:51 4
  • Make sure the file contents can't be retrieved if anyone gets ahold of your physical hard drive. With hard drive partition: gpg --default-recipient-self -o /path/to/encrypted_backup.gpg -e /dev/sdb1 && shred -z /dev/sdb1 WARNING/disclaimer: Be sure you... F&%k it--just don't try this.


    0
    gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_"
    h3xx · 2011-07-24 05:51:47 3
  • Skip forward and back using the < and > keys. Display the file title with I.


    1
    mplayer -playlist <(find "$PWD" -type f)
    h3xx · 2011-07-24 03:27:03 6
  • zless /proc/config.gz


    0
    zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz
    h3xx · 2011-07-24 02:06:09 4
  • This will affect all invocations of grep, even when it is called from inside a script.


    1
    export GREP_OPTIONS='--color=auto'
    h3xx · 2011-07-24 01:32:10 3

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

List .log files open by a pid
Uses lsof to display the full path of ".log" files opened by a specified PID.

Lists the supported memory types and how much your board can support.

generate iso

Reset terminal that has been buggered by binary input or similar

Find default gateway

mail with attachment
An easy one but nice to keep in mind.

list block devices
Shows all block devices in a tree with descruptions of what they are.

Getting the last argument from the previous command

Search gpg keys from commandline

Select and Edit a File in the Current Directory
This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file. * Without the break statement, the select command will loop forever * Setting the PS3 prompt is optional * If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string. * For more information, look up the bash's select command


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: