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 8
  • For when you need a quick spell check. Show Sample Output


    10
    aspell -a <<< '<WORDS>'
    h3xx · 2011-11-30 01:47:46 8
  • 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 63
  • 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 24
  • 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 17
  • 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 4

  • 0
    echo $(($(ulimit -u)-$(pgrep -u $USER|wc -l))
    h3xx · 2011-07-30 05:03:36 4
  • 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 8
  • 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 35
  • 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 5
  • Even adds a newline.


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

  • 0
    read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2
    h3xx · 2011-07-24 18:56:30 4
  • 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 4
  • 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 4
  • 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 4
  • 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 7
  • 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 4
  • 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 7
  • zless /proc/config.gz


    0
    zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz
    h3xx · 2011-07-24 02:06:09 5
  • 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 4

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

Grep Recursively Through Single File Extension
Trac 0.12.2-stable

To get the CPU temperature continuously on the desktop
There is no need for variables. I also added sleep to reduce cpu usage, however I didn't test it.

Ping xxx.xxx.xxx.xxx ip 100000 times with size 1024bytes

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"

dump 1KB of data from ram to file

about how using internal separate field and store file content on variable

download newest adminer and rename to it's version accordingly
If the version already downloaded. it will not download again

tar exclude files or directories
If you want to exclude only one file or directory you should use as --exclude=file_or_directory

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

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.


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: