Command Line Interface Tricks

Command Line Interface Tricks

Various tips & tricks to be used on the command line and other types of short code and configuration snippets. This post will be updated often.


  • Switching back and forth between the bash shell and an application with Ctrl-Z by putting this in your profile:
    • bind '"\C-z":"\C-e\C-ufg\C-m"' trap "stty susp ^z" ERR PS1="$(stty susp undef)$PS1"
  • Play your webcam like a video:
    • mplayer -tv driver=v4l2:gain=1:width=640:height=480:device=/dev/video0:fps=30:outfmt=rgb16 tv://
  • Quick way to enable QoS on eth0 to create balanced network traffic:
    • tc qdisc add dev eth0 root sfq perturb 10
  • To check current QoS state:
    • tc -s -d -p qdisc
  • Type this in top for a better layout:
    • Azxa-azxa-a1Wy
  • Speedup firefox by optimizing the internal database:
    • for i in ~/.mozilla/firefox/*/*.sqlite; do echo "VACUUM;" | sqlite3 $i; done
  • Check all md-raid for errors:
    • find /sys -name sync_action -exec echo 'echo check > {}' \;
  • Passwords that do not need to be typed should be generated with 42 alphanumerical characters to be optimized for an underlying 256 bit hash:
    • alias pwgen="echo $(tr -dc A-Za-z0-9 < /dev/urandom | head -c42)"
  • Simple expression to strip all html/xml markup tags:
    • perl -pe "s/<[^ ].*?>//g"
  • Quick webserver that hosts the current working directory as a HTTP server on port 8000:
    • python -m SimpleHTTPServer
  • List all installed perl modules:
    • perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
  • Rescan all disk drives, this will always find new hotswapped drives or disk size adjustments:
    • for i in /sys/class/scsi_host/*/scan; do echo "- - -" > $i; done for i in /sys/class/scsi_device/*/device/rescan; do echo 1 > $i; done for i in /sys/block/*/device/rescan; do echo 1 > $i; done


I'll admit this isn't really CLI, but this is the best place to post these kinds of tricks.

  • Add a Bookmark named Gray and enter this as location:

    • javascript:var%20items%20=%20document.getElementsByTagName('*');for(i%20in%20items)%20{%20item%20=%20items[i];'#EEEEEE';'#4A525A';%20}%20;%20void(0)
  • Add a Bookmark named Black Background and enter this as location:

  • Add a Bookmark named Google Verbatim and enter this as location:
    • javascript:document.location=document.location+"&tbs=li:1";void(0);
  • Add a Bookmark named Edit Page and enter this as location:
    • javascript:if(document.body.contentEditsdable)%7Bif(document.body.contentEditable=='false')%7Bdocument.body.contentEditable='true';%7Delse%7Bdocument.body.contentEditable='false';%7D%7Delse%7Bif(document.designMode=='on')%7Bdocument.designMode='off';%7Delse%7Bdocument.designMode='on';%7D%7Dvoid%200;
  • Add a Bookmark named Referrer and enter this as location:
    • javascript:document.location=document.referrer;void(0);
  • Add a Bookmark named CoralCache and enter this as location:
    • javascript:document.location.hostname=document.location.hostname+"";void(0);
  • Add a Bookmark named No Images and enter this as location:
    • javascript:var%20i=(document.getElementsByTagName("img").length-1);while(i>=0){document.getElementsByTagName("img")[i].parentNode.removeChild(document.getElementsByTagName("img")[i]);i--};(document.getElementsByTagName("img").length-1);while(i>=0){document.getElementsByTagName("img")[i].parentNode.removeChild(document.getElementsByTagName("img")[i]);i--};function%20clear(node){if(node.childNodes.length>0){var%20j=0;while(j<node.childNodes.length){clear(node.childNodes[j]);j++;}}try{"none";}catch(ex){}}clear(document.getElementsByTagName("body")[0]);void(0);
  • Add a Bookmark named Show Images and enter this as location:
    • javascript:var%20x=$(".content").find("a").each(function(){var%20href=$(this).attr("href");if((!$(this).hasClass("drowsapMorphed"))&&($(this).next(".drowsapMorphed").length==0)&&href&&(href.indexOf('imgur')>=0||href.indexOf('jpeg')>=0||href.indexOf('jpg')>=0||href.indexOf('gif')>=0||href.indexOf('png')>=0)){var%20ext=(href.indexOf('imgur')>=0&&href.indexOf('jpg')<0&&href.indexOf('png')<0)?'.jpg':'';var%20img=$("<a%20class='drowsapMorphed'%20href='"+href+"'%20target='blank'%20style='display:block'><img%20style='display:block;'%20src='"+href+ext+"'%20/></a>");$(this).after(img);}});void(0);
  • Some interesting privacy settings you can make on the about:config page:
    • network.http.referer.XOriginPolicy = 1 network.http.sendSecureXSiteReferrer = false privacy.trackingprotection.enabled = true geo.enabled = false browser.safebrowsing.enabled = false browser.safebrowsing.malware.enabled = false dom.event.clipboardevents.enabled = false dom.event.contextmenu.enabled = false geo.wifi.logging.enabled = false network.cookie.alwaysAcceptSessionCookies = false network.cookie.cookieBehavior = 1 browser.send_pings = false network.dns.disableIPv6 = true network.dns.disablePrefetch = true network.prefetch-next = false media.peerconnection.enabled = false


  • Check cluster status:
    • curl "http://localhost:9200/_cluster/health?pretty=true"
  • Fix some yellow/red states by reassigning shards, do enter the correct amount of replicas:
    • curl -XPUT 'http://localhost:9200/_settings' -d '{ "index" : { "number_of_replicas" : 2 } }'


comments powered by Disqus