Command Line Magic
From SusoSight
Command Line Magic is a twitter account that posts a few useful command line phrases a day. They are from a variety of categories and range from the simple one command job to complex multi piped commands with loops and branches. All within 140 characters each.
- http://www.twitter.com/climagic
- http://www.identi.ca/climagic
- Video tutorials: http://www.youtube.com/user/climagic
Contents
Ohio Linux Fest 2010 Presentation
I gave an hour long presentation at OLF 2010 that was pretty successful. Around 40 people attended, thank you to those that did and thank you to OLF for allowing me to speak. If you attended that talk and were looking for the slides that I had, below is a link to the Open Office Impress file. The presentation is more than just the typical slides, there are several slides that have in slide animations to emphasize parts of the commands. Unfortunately, I ran out of time and didn't do this for all the commands.
Something else that you might want to check out is the command quick reference sheet that is linked to in External Links section at the bottom of this page.
CLI Magic Posting App
If you came here from the User agent link from twitter saying "CLI Magic Posting App" you might be wondering about the software I use to post updates to twitter. Its just a Perl program I wrote using the Net::Twitter module. Nothing too special. Although perhaps the execution of it is interesting.
Basically, to make things easier on my schedule, I have a queue file with commands that I want to post to twitter/identica, that queue file uses ---- to comment out previous commands that have been run and also records the date that they were posted. Then from a cronjob, I run this script every so often like this:
0 */4 * * * [ $(( $RANDOM \% 100 )) -lt 65 ] && sleep $(( $RANDOM \% 3600 )) && /path/to/climagic-poster.pl
Might seem kinda strange but I was trying to mix up the times that it posts so its more like a human posting it. The $(( $RANDOM % 100 )) -lt 65 part makes it so taht there is a 65% chance that it will succeed in running it every 4 hours and then it waits a random time less than an hour before actually posting. Sometimes entropy is high and it posts every 4 hours, sometimes its low and it goes a whole day without posting. Either way, it keeps things interesting.
Some of the original submissions
- 2010-01-06 - echo -n "measure the length of this text" | wc -c #Print out the number of characters in a string. The -n option omits the default newline.
- 2010-01-06 - cat file | tr "\n" "," | sed 's/,$/\n/' #Turn multiple lines of a file into 1 line seperated by commas and fix the trailing comma.
- 2010-01-05 - echo DOMAINNAME.COM | tr A-Z a-z #translate the letters in DOMAINNAME.COM from uppercase to lowercase. Can be used for any string of course.
- 2010-01-04 - comm -12 <(sort file1) <(sort file2) #Determine what lines two different files have in common. The comm program requires sorted files.
- 2009-12-30 - while V=$((`date +%s -d"2010-01-01"`-`date +%s`));do if [ $V == 0 ];then figlet 'Happy New Year!';break;else figlet $V;sleep 1;clear;fi;done #new years countdown timer.
- 2009-12-30 - diff -uNr dir1 dir2 > diff.patch #generate a patch called diff.patch with all the differences between two source directories
- 2009-12-30 - alias coffee='VALUE=$( cat ~/.cupsocoffee ) ; VALUE=$(( $VALUE + 1 )); echo $VALUE > ~/.cupsocoffee ; echo $VALUE' #make your own counter
- 2009-12-29 - for i in IMG_3[0-4]*.JPG ;do convert -quality 60 -geometry 300 $i thumbs/$i ;done #Create thumbnails for images IMG_3000.JPG - IMG_3499.JPG
- 2009-12-29 - cat file1 file2 file3 > joinedfile #join 3 files in the order listed and write it to a file called joinedfile.
- 2009-12-28 - split -b 1M largefile #Split a file called largefile into 1 megabyte pieces called xaa, xab, xac, etc...
- 2009-12-28 - nc -q1 -lvp 1234 < file.txt #poor man's fileserve. Use nc remotehostname 1234 > output.txt to retreive file from remote host.
- 2009-12-23 - find ~/ -mindepth 2 -type f -ls | sort -n -r -k 7 | head -20 #show the 20 largest files located in subdirectories and lower of your homedir.
- 2009-12-23 - while true ; do NUM=$(( $RANDOM % 80 )) ; for i in $( seq 1 $NUM ) ; do echo -n " " ; done ; echo \* ; done #snow storm in your terminal
- 2009-12-22 - shasum *.jpg | awk {'print $1'} | sort | uniq -c | grep -v " 1 " #Find out if any duplicate image files exist in the current directory.
- 2009-12-22 - echo -e "GET / HTTP/1.0\nHost: news.google.com\n" | nc news.google.com 80 | html2text #GET news without browser. extra \n at end required
- 2009-12-21 - \ls #run the non-aliased version of ls. Putting a \ in front of a command name will bypass any aliases of the same name.
- 2009-12-21 - lsb_release -a #Show Linux distro release information. Available on most newer distros.
- 2009-12-18 - TZ=GMT xclock #display the time in xclock, but use the GMT timezone. This works for almost any program and timezone, not just xclock and GMT
- 2009-12-18 - mkdir -p /parentdir/sub1/sub2/sub3 #Create directory sub3 and create sub2, sub1 and parentdir if any of them don't exist yet
- 2009-12-17 - ps auxwf #process output in a tree view so you can see the parent -> child process relationships.
- 2009-12-17 - egrep -v "^#|^$" httpd.conf #display the httpd.conf file contents and exclude blank lines and lines that start with comment character.
- 2009-12-16 - ps auxw | grep [h]ttpd #grep out the process called httpd without including the grep command itself in the output.
- 2009-12-16 - echo 'mail -s "Remember to eat lunch" youremail@example.com < /dev/null' | at 12pm #one time scheduled reminder
- 2009-12-16 - cat file | cut -c 1-80 #trim output data width to 80 characters per line.
- 2009-12-15 - for i in `seq 1 254` ; do ping -W1 -c 1 10.0.0.$i > /dev/null && echo 10.0.0.$i ; done #scan network 10.0.0.0 for active hosts
- 2009-12-15 - ls -ltraSh | grep -v ^d #size ordered listing of files, excluding directory entries
- 2009-12-15 - du -sh */ #space usage of directories only
License
climagic's posts, where applicable are released under the Creative Commons Attribution Share Alike license. You have permission to distribute posts that could be copyrighted so long as you include a note about it being from @climagic on twitter/identica and you release the work under the same license. You should also send a direct message or a reply to @climagic on twitter/identica about the usage.
Details of the license are available at http://creativecommons.org/licenses/by-sa/3.0/
Note: Obviously not all of the posts made by climagic could be copyrighted and some where taken from other places. I try to give credit where possible and where known. You should probably ask before using a post just to make sure.
Thanks for the interest.