How many aliases do you have?

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
857
Reaction score
704
Credits
5,770
When you install the OS, by default there are 21 aliases in ~/.bashrc, so we don't count these - only the ones you wrote yourself. How many do you have? Mine are 241 at the moment. :D

You can use this script, even use it as an alias to count your aliases number. If you make an alias of it, it will be included in the final number.

Code:
alias-count-number-of-aliases.sh

Code:
#!/usr/bin/env bash

num1=$(grep -o "alias " .bashrc | wc -l)

result=$(($num1 - 21))

echo $result
This script is useful, if you have a large number of aliases. If it returns a negative number, open ~/.bashrc and scroll to its bottom. There you should see aliases that come with the distro installation by default. Count the number of these aliases and replace "21" with yours. This will change the script in a way to tell you how many aliases of your own you have.
 
Last edited:


When you install the OS, by default there are 21 aliases in ~/.bashrc
You should have probably put your thread in an OS-specific forum... Arch, I guess from your signature.

My OS must not have 21 aliases because your script returns -9.

I obviously do not use a lot of additional aliases. ;)
 
I wonder how did OP come up with this default number?
Mine had 0 (zero) aliases fresh after installation if I remember it correctly (I installed it more than 3yrs ago). So you do it yourself is the idea.
Unless Arch is is the only Linux distro? ;)
 
As a user in fedora/kde i get 21. As root I get 15.
As a user in fedora/server ( no GUI ) I get 12.

I imagine it's different for every distro?
 
You should have probably put your thread in an OS-specific forum... Arch, I guess from your signature.

Good idea and done.

I use different aliases based on the package manager, with quite a lot of overlap. I store mine in ~/.bash_aliases, however.
 
Hi rado84

I currently have over 800 aliases in 40 .bashrc-xxx files.
I access the files with 3 digit codes to see that group of aliases.
The aliases range from common commands, program start menus and file manager locations. Much easier to find what I want than the KDE Application menu.

Vektor
 
Here's mine.

Code:
alias-count-number-of-aliases.sh
alias-count-number-of-aliases.sh: command not found

Apparently the command doesn't work in Ubuntu 24.04 LTS or official Ubuntu 24.04 LTS flavors.
 
Last edited:
Apparently the command doesn't work in Ubuntu 24.04 LTS or official Ubuntu 24.04 LTS flavors.

I haven't tried it. Did you set the executable bit prior to running it? What happens if you use the absolute path (such as ~/Downloads/alias-count-number-of-aliases.sh)?
 
Here's mine.

Code:
alias-count-number-of-aliases.sh
alias-count-number-of-aliases.sh: command not found

Apparently the command doesn't work in Ubuntu 24.04 LTS or official Ubuntu 24.04 LTS flavors.
You don't need the script, just do cd ~/ and run grep -o "alias " .bashrc | wc -l directly in terminal.
 
I haven't tried it. Did you set the executable bit prior to running it? What happens if you use the absolute path (such as ~/Downloads/alias-count-number-of-aliases.sh)?
I just copied and pasted the command I wasn't aware that I had to set anything although I may have missed that part.
 
You don't need the script, just do cd ~/ and run grep -o "alias " .bashrc | wc -l directly in terminal.
That works.
Code:
grep -o "alias " .bashrc | wc -l
11
 
What happens if you use the absolute path (such as ~/Downloads/alias-count-number-of-aliases.sh)?

I copy and paste this.
Code:
~/Downloads/alias-count-number-of-aliases.sh)?


I get this.
Code:
bash: syntax error near unexpected token `)'
 
One can run the bash command "alias" and it will show the aliases. To get a total, then one can use the command "wc". No need for grep in the first instance.
Code:
[tom@min ~]$ alias
alias abc='abcm2ps'
alias cal='ncal -b'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias firefox='firefox &'
alias grep='grep --color=auto'
alias l.='ls -d .*'
alias ll='ls -lh'
alias ll.='ls -lhd .*'
alias ls='ls --color=auto'
alias rxvt='rxvt &'
alias sss='startx'
alias who='who -aH'
alias xpdf='xpdf -rv'


[tom@min ~]$ alias | wc -l
14

The bash alias command is a bash builtin, so I can't speak for other shells:
Code:
[tom@min ~]$ type alias
alias is a shell builtin

As for differentiating the default aliases provided by the system and the user created ones, one system commonly used is to create a .bash_aliases file for user created ones and source it from the .bashrc file. The command: alias, would nevertheless pick them all up, but simple commands on either dotfile would reveal the information on what was default and what was user created.
 
Last edited:
I copy and paste this.
Code:
~/Downloads/alias-count-number-of-aliases.sh)?


I get this.
Code:
bash: syntax error near unexpected token `)'

Assuming we're following the same page, there should be no parentheses in your command.
 
I haven't tried it. Did you set the executable bit prior to running it? What happens if you use the absolute path (such as ~/Downloads/alias-count-number-of-aliases.sh)?
Assuming we're following the same page, there should be no parentheses in your command.
I copied and pasted what was posted in post #8 so I don't know.
 
I copied and pasted what was posted in post #8 so I don't know.

You need to adjust it to your actual path, as suggested in said post.
 
Hi rado84

Thanks for the script. It made me rearrange my aliases to make them simpler to organize.

Vektor
 
Hi rado84

Thanks for the script. It made me rearrange my aliases to make them simpler to organize.

Vektor

For me, my organization is putting them all in their own file. I load 'em into ~/.bash_aliases and call it good.
 
Here's mine.

Code:
alias-count-number-of-aliases.sh
alias-count-number-of-aliases.sh: command not found

Apparently the command doesn't work in Ubuntu 24.04 LTS or official Ubuntu 24.04 LTS flavors.
While you've soled it, for future reference, you need to specify custom path where you keep your scripts in your .bashrc

Also I want to apologize to OP for my comment above, this is Arch thread, so obviously it will work with Arch and not necessary with other distros.
 
Last edited:

Members online


Latest posts

Top