Commands by isaacs (7)

  • Mouse around the title of this item, and note that your cookies are being logged to the console. If I were evil, I could instead send everyone's cookies to my site, and then post up-votes on all my submissions using their cookies, and try to delete every other submission, until clfu was completely pwned by me, redirecting people to malware and porn sites, and so on. Update - now fixed.

    perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-weight:normal;">xss</a>/<\/a>/g'
    isaacs · 2009-07-08 22:26:15 5
  • There's probably a more efficient way to do this rather than the relatively long perl program, but perl is my hammer, so text processing looks like a nail. This is of course a lot to type all at once. You can make it better by putting this somewhere: clf () { (curl -d "q=$@" 2>/dev/null) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/<a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +|\([0-9]+ votes,//g;s/^\//http:\/\/\//g'; } Then, to look up any command, you can do this: clf diff This is similar to except that it's just one line, so more in the spirit of CLF, in my opinion. Show Sample Output

    (curl -d q=grep | egrep 'autocomplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/\//g'
    isaacs · 2009-07-08 22:10:49 4
  • Pipe any command through figlet to make the output more awesome. Example: ls | figlet Show Sample Output

    command | figlet
    isaacs · 2009-05-03 21:20:46 3
  • Get the svn info, grep for the "URL" of the repository, pull out the tag/branch/trunk, and then just show the helpful/meaningful bit. Show Sample Output

    svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'
    isaacs · 2009-04-09 20:08:45 1
  • If you put this in your .bashrc, you might also want to add this to make it use the colors by default: alias ls="ls --color=auto"

    eval "`dircolors -b`"
    isaacs · 2009-03-27 05:37:04 1
  • This is useful for piping to other commands, as well: svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$' | xargs $EDITOR

    svn status | egrep '^(M|A)' | egrep -o '[^MA\ ].*$'
    isaacs · 2009-03-27 05:18:24 2
  • I got really tired of having tree always show me tons of .svn and .git stuff that I don't care about. With this alias, "tree" uses pretty colors, snazzy line graphics, and ignores any source control and package mumbojumbo. (Customize the *.*.package glob, of course.) Show Sample Output

    alias tree="tree -CAFa -I 'CVS|*.*.package|.svn|.git' --dirsfirst"
    isaacs · 2009-03-27 05:13:39 0

What's this? 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

Extract title from HTML files
Case Insensitive! and Works even if the "<title>...</title>" spans over multiple line. Simple! :-)

Cleanup Docker
# Delete all containers docker rm $(docker ps -a -q) # Delete all images docker rmi $(docker images -q)

Display the top 10 running processes - sorted by memory usage
A pretty nice display of processes.

Takes and displays screenshot of Android phone over adb.
Dependencies on phone: adb access, screencap command, base64 command. Dependencies on computer: adb, sed, base64, display (from imagemagick, but can substitute other image viewer which reads from stdin). This should work around adb stupidies (i.e. that it replaces \n with \r\n) with base64.

Getting a domain from url, ex: very nice to get url from squid access.log

Count the total amount of hours of your music collection
First the find command finds all files in your current directory (.). This is piped to xargs to be able to run the next shell pipeline in parallel. The xargs -P argument specifies how many processes you want to run in parallel, you can set this higher than your core count as the duration reading is mainly IO bound. The -print0 and -0 arguments of find and xargs respectively are used to easily handle files with spaces or other special characters. A subshell is executed by xargs to have a shell pipeline for each file that is found by find. This pipeline extracts the duration and converts it to a format easily parsed by awk. ffmpeg reads the file and prints a lot of information about it, grep extracts the duration line. cut and sed cut out the time information, and tr converts the last . to a : to make it easier to split by awk. awk is a specialized programming language for use in shell scripts. Here we use it to split the time elements in 4 variables and add them up.

display a smiling smiley if the command succeeded and a sad smiley if the command failed
you could save the code between if and fi to a shell script named with the first argument as and then do a to see if the command succeeded. a bit needless but who cares ;)

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

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

A function to find the newest file in a directory

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.


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: