Commands using od (28)

  • This is a bit of a bash hack to catch STDERR and append a log level to it. So for example, if your script has pseudo loglevels like so: echo "INFO - finding files" [ -f ${files} ] || echo "WARN - no files found" Any subcommands that write to STDERR will screw that up Adding 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err") to the command does the following: 2> Redirect STDERR >( Spawn a subshell (STDERR is then redirected to the file descriptor for this subshell) fb=$(....) get the first byte of input [ "$fb" ] test if there's a first byte && err=$(printf....) save the output to the $err variable && echo "ERROR - $err" append your pseudo loglevel and the error message Heavily borrowed from https://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt Show Sample Output


    0
    [command] 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err")
    tyzbit · 2017-10-16 22:22:42 22
  • Grab 4 bytes from www.random.org over ssl and format them as an integer


    -1
    curl -s "https://www.random.org/cgi-bin/randbyte?nbytes=4" | od -DAn
    PhillipNordwall · 2010-11-09 18:26:24 5

  • -1
    2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 |sed '2d;s/^0\+ //;s/ /:/g'
    flyc0r · 2011-05-17 21:04:35 4
  •  < 1 2

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 bash functions defined in .bash_profile or .bashrc
If you issue the "set" command, you'll see a list of variables and functions. This command displays just those functions' names.

Show sorted list of files with sizes more than 1MB in the current dir

rsync with progress bar.
transfer files from localhost to a remotehost.

most used unix commands

Remove a range of lines from a file
Deletes lines to of a file. You must put the end line first in the range for the curly brace expansion, otherwise it will not work properly.

Remove executable bit from all files in the current directory recursively, excluding other directories
Useful if you have copied files from an OS without a permission structure (for example, DOS) and you need to disable all executable files but want to be able to descend into your directories.

Safe Delete
remove file that has sensitive info safely. Overwrites it 33 times with zeros

Block an IP address from connecting to a server
This appends (-A) a new rule to the INPUT chain, which specifies to drop all packets from a source (-s) IP address.

Alias for getting OpenPGP keys for Launchpad PPAs on Ubuntu
Makes it easy to add keys to new ppa sources entries in apt sources.list Now to add the key for the chromium-daily ppa: $ launchpadkey 4E5E17B5

let the cow suggest some commit messages for you


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: