DEV Community

Abhinav Kumar
Abhinav Kumar

Posted on • Updated on

What are the most used commands in your shell history?

Recently I came across a thread on reddit which asked users the most used command in their shell history.

My results:

     1  419  13.0489%    git
     2  265  8.25288%    cd
     3  239  7.44316%    sudo
     4  122  3.79944%    cat
     5  77   2.39801%    which
     6  76   2.36686%    dkr
     7  72   2.24229%    rm
     8  60   1.86858%    rg
     9  57   1.77515%    yarn
    10  57   1.77515%    nvim
Enter fullscreen mode Exit fullscreen mode

Obviously git is my most used command because I ran it on my work laptop. It should be a lot more but I have been using prezto's git aliases lately. Other common commands are dkr which is an alias for sudo docker and rg, the binary for ripgrep.

I wonder how is it for the dev.to community?

Use this command from linux.byexample.com to list your most used commands:

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10
Enter fullscreen mode Exit fullscreen mode

I use zsh and it was not working for me because zsh's history command just prints a few most recent commands only. I had to tweak it a bit:

history 1 | cat | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a; }' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
# or
fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a; }' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
Enter fullscreen mode Exit fullscreen mode

Top comments (31)

Collapse
 
dmfay profile image
Dian Fay
     1  179  17.9179%   git
     2  88   8.80881%   ls
     3  86   8.60861%   cd
     4  79   7.90791%   rm
     5  74   7.40741%   cat
     6  57   5.70571%   vi
     7  44   4.4044%    pacman
     8  37   3.7037%    mocha
     9  28   2.8028%    sudo
    10  25   2.5025%    tree

Outside the usual suspects, pacman is the Arch Linux package manager and mocha is a JavaScript test framework. I'm actually a little surprised the latter made the top 10.

Collapse
 
rhymes profile image
rhymes

for a moment I thought you had a version of Pacman installed in the terminal

Collapse
 
dmfay profile image
Dian Fay

I mean, it exists, but I was never any good at Pacman :D

a command-line implementation of the Pacman game

Thread Thread
 
rhymes profile image
rhymes

ahhahaha me neither.

I'm more of a Space Invaders person.

Collapse
 
nmcain profile image
Noah Cain

     1  43  17.0635%   cd
     2  37  14.6825%   flutter
     3  31  12.3016%   ls
     4  27  10.7143%   git
     5  22  8.73016%   webdev
     6  14  5.55556%   nano
     7  11  4.36508%   sudo
     8  10  3.96825%   adb
     9  8   3.1746%    pub
    10  7   2.77778%   rm

Flutter, am I right?

Collapse
 
simov profile image
simo
     1  301  30.1%  g
     2  162  16.2%  cd
     3  105  10.5%  ll
     4  87   8.7%   npm
     5  43   4.3%   s
     6  32   3.2%   sudo
     7  30   3%     rm
     8  20   2%     node
     9  19   1.9%   mocha
    10  17   1.7%   nvm

g - git, s - sublime

Collapse
 
abhinav profile image
Abhinav Kumar

Are you using self-defined aliases for git or the ones defined by a bash/zsh framework?

Collapse
 
simov profile image
simo

I've manually added the following lines in my .bashrc file:

# git alias and autocomplete
alias g='git'
source /usr/share/bash-completion/completions/git
complete -o default -o nospace -F _git g
Collapse
 
igormp profile image
Igor Moura
     1  997  12.7023%    exit
     2  992  12.6386%    git
     3  916  11.6703%    sudo
     4  295  3.75844%    ping
     5  266  3.38897%    cd
     6  261  3.32526%    yaourt
     7  212  2.70098%    ls
     8  138  1.75819%    startx
     9  126  1.6053%     cat
    10  110  1.40145%    qemu-system-x86_64

I honestly didn't expect qemu to be there lol

Collapse
 
rhymes profile image
rhymes
     1  355  35.5355%   git
     2  106  10.6106%   yarn
     3  48   4.8048%    pipenv
     4  28   2.8028%    brew
     5  26   2.6026%    rm
     6  25   2.5025%    zgrep
     7  25   2.5025%    cd
     8  22   2.2022%    curl
     9  19   1.9019%    pyenv
    10  18   1.8018%    redis-cli
Collapse
 
abhinav profile image
Abhinav Kumar

How is pipenv working out for you? Is it comparable to yarn or cargo in your experience?

Collapse
 
rhymes profile image
rhymes • Edited

I use pyenv (to have multiple Python versions installed) and pipenv a lot.

I don't know about cargo but pipenv is not that different from yarn. It has a file with the list of dependencies and a lock file. It tends to consume less resources than yarn because Python dependencies trees are usually much smaller than those of JS libraries.

Collapse
 
phlash profile image
Phil Ashby


1 146 14.6% vi
2 137 13.7% ls
3 96 9.6% cd
4 64 6.4% eog
5 52 5.2% git
6 44 4.4% ssh
7 38 3.8% cat
8 32 3.2% rm
9 26 2.6% su
10 26 2.6% make

I've been doing some facial recognition scripting recently (hello eog), and apparently I like other computers (ssh), nuking stuff (rm) and root :)

quite glad to see make get in at 10!

Collapse
 
val_baca profile image
Valentin Baca

No surprise here. git, cd, ls, vim, build, search

     1  3663  36.6337%   g
     2  938   9.38094%   cd
     3  534   5.34053%   igs        # inall git status (runs 'git status' in each dir in pwd)
     4  516   5.16052%   ..
     5  277   2.77028%   vim        # <3
     6  258   2.58026%   ls
     7  216   2.16022%   <redacted> # company build command, aliased to be 2 letters :)
     8  200   2.0002%    ws         # alias to cd to my workspace dir
     9  175   1.75018%   <redacted> # company workspace information command, aliased to be 2 letters
    10  167   1.67017%   ag         # the silver searcher > (grep or awk or find)
Collapse
 
abhinav profile image
Abhinav Kumar • Edited

You might want to look into autojump or autojump-rs to quickly jump to your workspace directories.

Also, ripgrep is a competent (not drop-in though) alternative to ag/grep.

Collapse
 
val_baca profile image
Valentin Baca

Thanks. I've found that autojump and the like are too non-determistic to be reliable.

ripgrep is missing two very critical features: -G (--file-search-regex) and the ability to grep gzip'd files. The ripgrep vim plugin is also sub-par to ag's.

ripgrep is certainly faster, but they're both so fast their difference is often in ms.

Collapse
 
vlasales profile image
Vlastimil Pospichal
     1  117  12.4468%   ll
     2  113  12.0213%   xmllint
     3  92   9.78723%   vim
     4  45   4.78723%   php
     5  39   4.14894%   cd
     6  36   3.82979%   mv
     7  34   3.61702%   git
     8  28   2.97872%   cat
     9  27   2.87234%   docker
    10  24   2.55319%   mongo
Collapse
 
andy profile image
Andy Zhao (he/him)
     1  137  27.4%  git
     2  50   10%    cd
     3  47   9.4%   ls
     4  43   8.6%   brew
     5  26   5.2%   br (bin/rails)
     6  24   4.8%   brg (bin/rails guard)
     7  13   2.6%   heroku
     8  12   2.4%   pg_upgrade
     9  12   2.4%   pg_restore
    10  11   2.2%   rm

Surprised that brew,pg_upgrade, and pg_restore are there. Wonder if it take your most recent commands from the previous week.

Collapse
 
ferricoxide profile image
Thomas H Jones II

Probably depends on how your shell history is set up. Things like whether concurrent sessions are set up to aggregate history, whether session's shell-history is configured to save to disk at all, how large you've set your HISTSIZE, etc. will all play in.

Collapse
 
fynn_it profile image
Fynn
     1  378  6.77784%    ga (git add .)
     2  358  6.41922%    gc (git commit -m)
     3  346  6.20405%    gulp
     4  319  5.71992%    ls
     5  292  5.23579%    gpll (git pull && echo ' --pulled -- ' && git push && echo ' --pushed -- ')
     6  232  4.15994%    gs (git status)
     7  202  3.62202%    npm
     8  182  3.2634%     ..
     9  178  3.19168%    git
    10 156  2.7972%     gpl (git pull)