Commands by b_t (21)

  • -Qdt Lists dependencies/packages which are no longer required by any packages -q Output only package name (not the version number) -R Remove package(s) Rest is self-explanatory. I just started out with Arch - so if there is any better/standard method to achieve the same - please suggest.

    pacman -Qdt -q | xargs pacman --noconfirm -R
    b_t · 2014-02-27 05:17:57 0
  • The -W switch of netstat makes it print complete URL of the connections, which otherwise by default is truncated to fit its default column size. Now to compensate for irregular column sizes, pipe the output to column (-t switch of column prints in tabular form). The only downside to this part is that the very first row, the header, goes pear shape. Show Sample Output

    netstat -tup -W | column -t
    b_t · 2014-01-08 22:39:01 0
  • sort command can sort month-wise (first three letters of each month). See the sample output for clarification. Sorting Stable ? NO. Take note if that matters to you. Sample output suggests that sort performs unstable sorting (see the relative order of two 'feb' entries). Show Sample Output

    sort -M filename
    b_t · 2011-12-10 12:50:30 0
  • By default bash history of a shell is appended (appended on Ubuntu by default: Look for 'shopt -s histappend' in ~/.bashrc) to history file only after that shell exits. Although after having written to the history file, other running shells do *not* inherit that history - only newly launched shells do. This pair of commands alleviate that. Show Sample Output

    $ history -a #in one shell , and $ history -r #in another running shell
    b_t · 2011-11-05 01:19:30 0
  • This revision to my command (command #8851) was called for when it failed to find the parent package of 'rlogin', which is really a deep symbolic link to /usr/bin/ssh. This revision fixes this newfound issue, while ensuring fixes of other older issues work too. Show Sample Output

    function whichpkg() { readlink -f "$(which $1)" | xargs --no-run-if-empty dpkg -S; }
    b_t · 2011-10-28 02:53:19 0
  • Bash history commands are those that begin with the character ! (eg. the most popular 'sudo !!' Explained here => By default bash immediately executes the history command. Setting this shell option will make bash first allow you to verify/edit an history command before executing it. To set this option permanently, put this command in ~/.profile or ~/.bashrc file. To unset this option issue following command. shopt -u histverify Show Sample Output

    shopt -s histverify
    b_t · 2011-10-27 00:33:34 0
  • Advanced revision to the command 8776 . This revision follows symbolic links. The quotation-marks surrounding $(which $1) allows for graceful handling of errors ( ie. readlink does not complain incase 'which' command generates (null) output) Show Sample Output

    whichpkg () { dpkg -S $1 | egrep -w $(readlink -f "$(which $1)")$; }
    b_t · 2011-07-17 13:39:56 0
  • This version builds on my command 8776 (Find the package a command belongs to on debian-based distros). So if you use that command to find package name then you could alternatively use following for package summary: function summpkg { dpkg -s $(whichpkg $1 | awk -F: '{print $1}'); } Show Sample Output

    function summpkg { dpkg -s $(dpkg -S $1 | egrep -w $(which $1)$ | awk -F: '{print $1}') ; }
    b_t · 2011-07-05 23:06:37 0
  • Similar to command 7822, but handles errors gracefully. Show Sample Output

    function whichpkg { dpkg -S $1 | egrep -w $(which $1)$; }
    b_t · 2011-07-05 22:56:48 0
  • This example command fetches '' webpage and then fetches+saves all PDF files listed (linked to) on that webpage. [*Note: of course there are no PDFs on This is just an example]

    curl -s | grep -o -P "<a.*href.*>" | grep -o "http.*.pdf" | xargs -d"\n" -n1 wget -c
    b_t · 2011-06-09 14:42:46 1
  • Say your dependencies specified in your Makefile (or dates on your source files) is causing 'make' to skip some source-files (that it should not) or on the other other end, if it is causing make to always build some source-files regardless of dates of target, then above command is handy to find out what 'make' thinks of your date v/s target date-wise or what dependencies are in make's view-point. The egrep part removes the extra noise, that you might want to avoid. Show Sample Output

    make -d | egrep --color -i '(considering|older|newer|remake)'
    b_t · 2011-06-03 01:55:08 1
  • This will delete the branch 'featureless' on the origin remote. Do not forget to delete the branch locally using: git branch -d featureless 'I got it here'-credit: I duplicated here incase you stumbled here first. Show Sample Output

    git push origin :featureless
    b_t · 2011-06-02 14:53:31 0
  • Some source package have many 'README' kind of files, among many other regular files/directories. This command could be useful when one wants to list only 'README' kind of files among jungle of other files. (e.g. I came across this situation after downloading source for module-init-tools) Warning: This command would miss a file like => README.1 (or one with spaces in-between) Corrections welcome. Show Sample Output

    ls | grep '^[A-Z0-9]*$'
    b_t · 2010-12-19 21:45:53 1
  • This command seems to achieve the similar/same goal.

    kill -l
    b_t · 2010-11-17 23:48:51 0
  • Your version works fine except for someone who's interested in commands 'sudo' was prefixed to i.e. in your command, use of sudo appears as number of times sudo was used. Slight variation in my command peeks into what commands sudo was used for and counts the command (ignores 'sudo')

    history | awk '{print $2,$3}' | sed s/sudo// | awk '{print $1}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
    b_t · 2010-11-17 12:15:04 0
  • I wanted to view only executables installed by a package. This seemed to work. There's got to be easier way, please share. Note: (1) Replace iptables with the package name of your interest (2) The command will trash any existing environment variable named 'lst' (3) Instead if you are interested in viewing just .ko or .so files installed by this package, then that would be easy: $ dpkg -L iptables | grep "\.[sk]o$" Show Sample Output

    lst=`dpkg -L iptables` ; for f in $lst; do if [ -x $f ] && [ ! -d $f ] ; then echo $f; fi; done;
    b_t · 2010-10-30 14:47:45 1
  • Note: 1) Replace 'wonder' with any word you looking the meaning for in the above example 2) Need to install these packages: wordnet & wordnet-base (latter should be automatically installed because of dependency) 3) Combined size of packages is about 30MB on my old ubuntu system (I find it worth it) Show Sample Output

    wn wonder -over
    b_t · 2010-10-05 13:56:06 0
  • Need package: gksu Note: Launching gui app in background that needs sudo, won't work great with our old friendly style of launching: sudo gedit /etc/passwd & because this would put sudo in background ! Using gksudo as demonstrated, would popup a gui sudo window. May be this is a common knowledge, but not knowing this frustrated me during my newbie year.

    gksudo gedit /etc/passwd &
    b_t · 2010-10-05 13:11:04 1
  • By default sudo 'remembers' password for a few minutes, so that you do not need to re-enter password for a series of sudo commands that might follow within a short time duration. However, sometime you might want sudo to instantly 'forget' the password. (Next sudo command will need you to reenter the password) Credit: I first learned this while listening to one of the 'tuxradar' podcast. Show Sample Output

    sudo -K
    b_t · 2010-10-05 12:44:26 0
  • Note: 1) -n option of watch accepts seconds 2) -t option of notify-send accepts milliseconds 3) All quotes stated in the given example are required if notification message is more than a word. 4) I couldn't get this to run in background (use of & at the end fails). Any suggestions/improvements welcome.

    watch -n 900 "notify-send -t 10000 'Look away. Rest your eyes'"
    b_t · 2010-10-05 09:39:31 1
  • Notes: 1) -n-1 means sort key is the last field 2) -l is important if each separate record is on a new line (usually so for text files) 3) -j tells msort not to create log file (msort.log) in the working directory 4) may need to install msort package. 5) msort does lot more. Check man msort Show Sample Output

    file /bin/* | msort -j -l -n-1 -n2 2> /dev/null
    b_t · 2010-10-05 00:37:33 1

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

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: