Commands tagged decimal (6) the last day the last week the last month all time sorted by date votes

• 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
• I've corrected the function. My octal conversion formula was completely wrong. Thanks to pgas at http://mywiki.wooledge.org/BashFAQ/071 for setting me straight. The new function is from pgas and is very fast. Show Sample Output

5
chr () { printf \\\$((\$1/64*100+\$1%64/8*10+\$1%8)); }
· 2009-10-15 07:01:54
• 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

• 2
chr() { printf \\\$(printf %o \$1); }
· 2009-10-16 19:10:44

1
awk {'print rshift(and(\$1, 0xFF000000), 24) "." rshift(and(\$1, 0x00FF0000), 16) "." rshift(and(\$1, 0x0000FF00), 8) "." and(\$1, 0x000000FF)'}
· 2018-08-16 11:46:26
• Doesn't fail for percent sign now.

0
chr () { echo -en "\0\$(printf %x \$1)"}
· 2009-10-16 21:54:58

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

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" }

Change pidgin status
Thanks for the comment oshazard, i wasn't aware of purple-remote existence.

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"

Convert CSV to JSON

Show which programs are listening on TCP ports
Alternative: \$ ss -tlpn

Reload all sysctl variables without reboot
Reload all defined kernel variables from /etc/sysctl.conf(if no parameter after -p is given) without the old myth "Ah, you'll need to reboot to apply those variables"...

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Function to split a string into an array
It works as a method applicated to a variable, converts the string variable into an array

Print a horizontal line

check open ports without netstat or lsof