### Commands using awk (1,400) the last day the last week the last month all time sorted by date votes

• seq -s ' ' 1 9 | sed -n ':a;p;s/ *\w\$//;h;/^\$/t;b a;q' | tac | awk '{for(i=1;i 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81

11
seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}'
· 2011-10-22 18:41:09
• A more efficient way, with reversed order to put the focus in the big ones. Show Sample Output

11
du -x --max-depth=1|sort -rn|awk -F / -v c=\$COLUMNS 'NR==1{t=\$1} NR>1{r=int(\$1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", \$1/t*100, b, \$2}'|tac
· 2015-09-12 10:36:49

• 10
while true; do X=\$Y; sleep 1; Y=\$(ifconfig eth0|grep RX\ bytes|awk '{ print \$2 }'|cut -d : -f 2); echo "\$(( Y-X )) bps"; done
· 2009-03-27 08:26:39
• This is useful if you have need to do port forwarding and your router doesn't assign static IPs, you can add it to a script in a cron job that checks if you IP as recently changed or with a trigger script. This was tested on Mac OSX.

10
ifconfig en1 | awk '/inet / {print \$2}' | mail -s "hello world" [email protected]
· 2009-04-28 06:01:52
• Show time and date when you installed your OS. Show Sample Output

10
ls -lct /etc | tail -1 | awk '{print \$6, \$7}'
· 2009-09-03 10:26:37
• Just refining last proposal for this check, showing awk power to make more complex math (instead /1024/1024, 2^20). We don't need declare variable before run lsof, because \$(command) returns his output. Also, awk can perform filtering by regexp instead to call grep. I changed the 0.0000xxxx messy output, with a more readable form purging all fractional numbers and files less than 1 MB. Show Sample Output

10
lsof -p \$(pidof firefox) | awk '/.mozilla/ { s = int(\$7/(2^20)); if(s>0) print (s)" MB -- "\$9 | "sort -rn" }'
· 2010-01-13 22:45:53
• man dmidecode [look for type] Show Sample Output

10
dmidecode -t 17 | awk -F":" '/Speed/ { print \$2 }'
· 2010-02-19 12:15:13
• poorman's ifstat using just sh and awk. You must change "eth0" with your interface's name. Show Sample Output

10
while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = \$2 - oi; o = \$10 - oo; oi = \$2; oo = \$10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
· 2011-11-21 05:24:44

• 10
awk '{ \$1="";print}'
· 2015-05-26 20:55:36
• This command is useful when you want to know what process is responsible for a certain GUI application and what command you need to issue to launch it in terminal. Show Sample Output

9
xprop | awk '/PID/ {print \$3}' | xargs ps h -o pid,cmd
· 2009-02-16 07:55:19
• Very useful set of commands to know when your file system was created. Show Sample Output

9
df / | awk '{print \$1}' | grep dev | xargs tune2fs -l | grep create
· 2009-02-16 18:45:03
• You can use multiple field separators by separating them with | (=or). This may be helpful when you want to split a string by two separators for example. #echo "one=two three" | awk -F "=| " {'print \$1, \$3'} one three

9
awk -F "=| "
· 2009-03-02 21:09:51
• This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system. Show Sample Output

9
zgrep "Failed password" /var/log/auth.log* | awk '{print \$9}' | sort | uniq -c | sort -nr | less
· 2009-03-03 13:45:56
• This create an array 'a' with wole lines. only one occurrence of each line - Not Get lines ++ !

9
awk '!a[\$0]++' file
· 2009-08-23 15:28:43

• 9
tail -f file | awk '{now=strftime("%F %T%z\t");sub(/^/, now);print}'
· 2010-11-25 04:11:52
• Booting the VM headless via VBoxHeadless requires knowledge of the VM's network in order to connect. Using VBoxManage in this way and you can SSH to the VM without first looking up the current IP, which changes depending on how you have your VM configured. Show Sample Output

9
ssh [email protected]`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print \$2 }'`
· 2011-05-04 18:01:36

• 8
svn st | grep "^\?" | awk "{print \\$2}" | xargs svn add \$1
· 2009-02-05 17:28:53

• 8
gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log /var/log/auth.log.0 | grep "Invalid user" | awk '{print \$8;}' | sort | uniq -c | less
· 2009-03-03 04:26:57
• Searches the /var/log/secure log file for Failed and/or invalid user log in attempts. Show Sample Output

8
cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print \$11}' | sort | uniq -c | sort -n
· 2009-03-30 15:48:24
• Also useful with iostat, or pretty much anything else you want timestamped. Show Sample Output

8
vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now \$0}'
· 2009-07-17 07:41:57

• 8
awk -F ',' '{ x = x + \$4 } END { print x }' test.csv
· 2009-08-11 12:10:33
• Connect to a machine running ssh using mac address by using the "arp" command Show Sample Output

8
ssh [email protected]`for ((i=100; i<=110; i++));do arp -a 192.168.1.\$i; done | grep 00:35:cf:56:b2:2g | awk '{print \$2}' | sed -e 's/(//' -e 's/)//'`
· 2009-09-09 04:32:20
• This function uploads images to http://omploader.org and then prints out the links to the file. Some coloring can also be added to the command with: `ompload() { curl -F [email protected]"\$1" http://omploader.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");\$1=\$1;sub(/^/,"\033[0;34m");sub(/:/,"\033[0m:");print}';}` Show Sample Output

8
· 2009-11-07 20:56:52
• This can show all ls colors, with a demo.

8
echo \$LS_COLORS | sed 's/:/\n/g' | awk -F= '!/^\$/{printf("%s \x1b[%smdemo\x1b[0m\n",\$0,\$2)}'
· 2009-12-15 01:17:46

8
grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print \$4}' | uniq | xargs apt-get -y remove
· 2010-01-12 09:42:22
•  < 1 2 3 4 5 >  Last ›

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

Show IP Address in prompt --> PS1 var
when working with many machines in a computer lab need to know the IP addr is very large, this is a simplistic solution to make things easier

Show how old your linux OS installtion is
..not guaranteed to always be accurate but fun to see how old you Linux installation is based on the root partitions file system creation date.

mysqlcheck --defaults-file=/etc/mysql/debian.cnf --auto-repair --all-databases

check open ports without netstat or lsof

backup local MySQL database into a folder and removes older then 5 days backups

Look at your data as a greymap image.
Keep width to a power of 2 to see patterns emerge. 512 is good. So is 4096 for huge maps. PNM headers are super basic. http://netpbm.sourceforge.net/doc/pbm.html

Burn CD/DVD from an iso, eject disc when finished.
cdrecord -scanbus will tell you the (x,y,z) value of your cdr (for example, mine is 3,0,0)

Pronounce an English word using Dictionary.com
This one uses dictionary.com

Pick a random line from a file

Extract audio stream from an video file using mencoder
This command extracts the audio stream of the video in \$file and stores it in a file where the original suffix is changed to .mp3