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

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

A command's package details
In Debian based distros, this command will list 'binutils' package details which contains 'nm' command. You can replace 'nm' to any other command.

Backup your OpenWRT config (only the config, not the whole system)
You only have to fill in your administrative account and password, and the router FQDN! I recommand to execute this command not over the internet, because there is no encryption (the username and password will be transmitted in plaintext!)

locate bin, src, and man file for a command

lotto generator

Use wget to download one page and all it's requisites for offline viewing

Print all lines between two line numbers
This command uses awk(1) to print all lines between two known line numbers in a file. Useful for seeing output in a log file, where the line numbers are known. The above command will print all lines between, and including, lines 3 and 6.

Unlock more space form your hard drive
This command changes the reserved space for privileged process on '/dev/sda' to 1 per cent.

RTFM function
Sometimes you don't have man pages only '-h' or '--help'.

Create a git alias that will pull and fast-forward the current branch if there are no conflicts
This command will first add an alias known only to git, which will allow you to pull a remote and first-forward the current branch. However, if the remote/branch and your branch have diverged, it will stop before actually trying to merge the two, so you can back out the changes. http://www.kernel.org/pub/software/scm/git/docs/git-pull.html Tested on git 1.5.6.1, msysgit (Windows port) Actually this is not really the way I want it. I want it to attempt a fast-foward, but not attempt to merge or change my working copy. Unfortunately git pull doesn't have that functionality (yet?).


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: