### Commands tagged binary (13) the last day the last week the last month all time sorted by date votes

• Create a binary clock. Show Sample Output

36
watch -n 1 'echo "obase=2;`date +%s`" | bc'
· 2009-11-04 02:04:00
• 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}
· 2009-06-23 17:30:20
• Upload/download newer version of any file with less size and high speed. To remake the new file use `bspatch <oldfile> <newfile> <patchfile>`

7
bsdiff <oldfile> <newfile> <patchfile>
· 2011-09-13 18:22:40
• Binary clock with separate H:M:S. Show Sample Output

6
watch -n 1 'date "+obase=2; print %H,\":\",%M,\":\",%S" |bc'
· 2011-02-02 00:01:48
• Convert some decimal numbers to binary numbers. You could also build a general base-converter: `function convBase { echo "ibase=\$1; obase=\$2; \$3" | bc; }` then you could write `function decToBun { convBase 10 2 \$1; }` Show Sample Output

4
function decToBin { echo "ibase=10; obase=2; \$1" | bc; }
· 2009-11-24 22:57:58
• Replace (as opposed to insert) hex opcodes, data, breakpoints, etc. without opening a hex editor. HEXBYTES contains the hex you want to inject in ascii form (e.g. 31c0) OFFSET is the hex offset (e.g. 49cf) into the binary FILE

2
echo -n \$HEXBYTES | xxd -r -p | dd of=\$FILE seek=\$((0x\$OFFSET)) bs=1 conv=notrunc
· 2009-03-11 17:02:24
• Print out your age in days in binary. Today's my binary birthday, I'm 2^14 days old :-) . This command does bash arithmatic \$(( )) on two dates: Today: \$(date +%s) Date of birth: \$(date +%s -d YYYY-MM-DD) The dates are expressed as the number of seconds since the Unix epoch (Jan 1970), so we devide the difference by 86400 (seconds per day). . Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary. (obase == output base) Show Sample Output

2
echo "obase=2;\$(((\$(date +%s)-\$(date +%s -d YYYY-MM-DD))/86400))" | bc
· 2015-10-19 15:40:32
• 'od -c' works like 'hexdump -c' but is available on other operating systems that don't ship with hexdump (e.g. solaris).

1
od -c <file>
· 2011-09-09 18:55:28
• This will show you any links that a command follows (unlike 'file -L'), as well as the ultimate binary or script. Put the name of the command at the very end; this will be passed to perl as the first argument. For obvious reasons, this doesn't work with aliases or functions. Show Sample Output

0
perl -le 'chomp(\$w=`which \$ARGV[0]`);\$_=`file \$w`;while(/link\b/){chomp(\$_=(split/`/,\$_)[1]);chop\$_;\$w.=" -> \$_";\$_=`file \$_`;}print "\n\$w";' COMMAND_NAME
· 2010-07-30 19:26:35
• - View non printable characters. - view binary files Show Sample Output

0
hexdump -c <file>
· 2011-09-09 09:54:16
• xxd can convert a hexdump back to binary using the -r option which can be useful for patching or editing binary files.

0
xxd <file>
· 2011-09-09 21:52:30
• Use this function with bash version 4+ to convert arbitrary hexadecimal sequences to binary. If you don't have bash 4+ then modify the lowercase to uppercase demangling statement `s=\${@^^}` to set s equal to the uppercase hex input or the bc command throws an input parser error. Show Sample Output

0
hex2bin () { s=\${@^^}; for i in \$(seq 0 1 \$((\${#s}-1))); do printf "%04s" `printf "ibase=16; obase=2; \${s:\$i:1};\n" | bc` ; done; printf "\n"; }
· 2018-10-02 22:02:33
• Use this like the cat command with the additional feature to strip out unprintable characters from the input, newlines will stay. Show Sample Output

-1
strings -1 <file>
· 2012-11-23 11:33:25

### 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.

### Check These Out

Create a favicon
Create a favicon suitable for use on your web site. Note: ppmtowinicon is part of libpbm, not ImageMagick.

Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale.

Batch file name renaming (copying or moving) w/ glob matching.

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

execute your commands and avoid history records
\$ secret_command;export HISTCONTROL= This will make "secret_command" not appear in "history" list.

Put split files back together, without a for loop
After splitting a file, put them all back together a lot faster then doing \$cat file1 file2 file3 file4 file5 > mainfile or \$for i in {0..5}; do cat file\$i > mainfile; done When splitting, be sure to do split -d for getting numbers instead of letters

Make a dedicated folder for each zip file
\${f%*.zip} strips off the extension from zip filenames

Find where a kind of file is stored
In this case searches for where .desktop files are stored. The resulted is a sorted list of the top directories containing such files.

Remux an avi video if it won't play easily on your media device
When playback of AVI files (containing a video format like XviD or DivX) is stuttering, it in 90% of the files is caused by a poorly or wrongly interleaved file. The issue can be permanently resolved by RE-MUXING the AVI video-files that have this problem

Make ISO image of a folder
Create ISO image of a folder in Linux. You can assign label to ISO image and mount correctly with -allow-lowercase option.