How many aliases do you have?

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. ;)
Aliases work the same in all distros.
How come you don't have any default aliases? I've seen those (so far) in all known Debian-based distros - Mint, Ubuntu, even in Bodhi Linux which is modified Ubuntu. In Mint 18.3 aliases didn't work at all but the default ones were there and they worked.

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.
That was just an example meaning that you need to put the longer code in a bash file. And yes, obviously, you need to specify the path. I thought that was implied which is why I didn't mention it.
 


How come you don't have any default aliases?
I do have default aliases... just not 21 of them. I'm using Linux Mint (Cinnamon), and I think there are 11 default aliases in ~/.bashrc... and I added one of my own, so I had 12. When your script subtracts 21 from 12, my result was -9.

I think the goal of your script is to detect that one alias of my own, or count more if I had them, count all of my custom aliases... right? But it relies on the fixed value of 21 which does not apply to me. Your script runs fine, but each user needs to know their own default number to get an accurate result.

Still... nice job! I can see its usefulness for folks with a large number of aliases.
 
Yup! Nice job.

So far I have 6 alias files and I modded the script as such:

"num1=$(grep -o "alias " /root/Z-VICS-BASH/ALIASES/.bashrc-*** | wc -l)

result=$(($num1))

echo $result"

and the result is 916

Thanks rado84

Vektor
 
And I added your code to my aliases.

This is so cool.

Vektor
 
I do have default aliases... just not 21 of them. I'm using Linux Mint (Cinnamon), and I think there are 11 default aliases in ~/.bashrc... and I added one of my own, so I had 12. When your script subtracts 21 from 12, my result was -9.

I think the goal of your script is to detect that one alias of my own, or count more if I had them, count all of my custom aliases... right? But it relies on the fixed value of 21 which does not apply to me. Your script runs fine, but each user needs to know their own default number to get an accurate result.

Still... nice job! I can see its usefulness for folks with a large number of aliases.
Then they must have changed them at some point bc I remember seeing some of these in 18.3:

Code:
alias cls="clear"
alias ..="cd .."
alias cd..="cd .."
alias ls="ls -CF --color=auto"
alias ll="ls -lisa --color=auto"
alias lsl="ls -lhFA | less"
alias home="cd ~"
alias df="df -ahiT --total"
alias userlist="cut -d: -f1 /etc/passwd"
alias fhere="find . -name "
alias free="free -mt"
alias du="du -ach | sort -h"
alias ps="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"
alias wget="wget -c"
alias histg="history | grep"
alias myip="curl http://ipecho.net/plain; echo"
alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'
alias grep='grep --color=auto'

As for the number of difference, I'll add something to the first post.
 
Then they must have changed them at some point bc I remember seeing some of these in 18.3:
I can't speak to that... 18.3 released in 2017 and reached EOL in 2021. (Wikipedia)

The correct default number of working aliases in Cinnamon Edition of Linux Mint 21.3 (Virginia) and 22.0 (Wilma) is 8.... determined with alias | wc -l. I can only guess the MATE or XFCE Editions are the same, but Linux Mint Debian Edition (Faye) is different... it only has one default alias, and others that are commented out in .bashrc.

Using grep alias .bashrc | wc -l counts a total of 16 times "alias" is found in a default Mint Cinnamon .bashrc, including the word "aliases." Many of these instances are in comments and are not actual alias commands.

Your script creates num1 with the command grep -o "alias " .bashrc | wc -l to count the number of aliases. It gets close to the right number by not counting the word "aliases" in 5 places in .bashrc (it wants a space after alias to accept it).... but it does not catch "alias " that is found in comments, and there are 3 of those that are missed in Mint. The script needs to ignore all lines with comments, AND it still needs to filter with the space after "alias " to catch the 2 instances in the if statement looking for ~/.bash_aliases file.

I have removed my personal aliases (both of them LOL) to show you the contents of a default .bashrc in the recent versions of Mint Cinnamon. I hope it helps.
aliases.png

To get an accurate count, each user needs to know their own default number of aliases provided with their distro/desktop so those can be subtracted to show the number of custom aliases. It's harder than it seems to figure that out if you have already added custom aliases to the .bashrc file. If you don't mind the small error, you could just simply include the defaults to get a total of all aliases with alias | wc -l... which would make a nice new alias itself without the need of a script. For example, "calias" for "count alias" could be something like: alias calias='alias | wc -l'.

I store mine in ~/.bash_aliases, however.
This is also a great solution to allow accurate counting of custom aliases.
 
Last edited:
Then they must have changed them at some point bc I remember seeing some of these in 18.3:

Code:
alias cls="clear"
alias ..="cd .."
alias cd..="cd .."
alias ls="ls -CF --color=auto"
alias ll="ls -lisa --color=auto"
alias lsl="ls -lhFA | less"
alias home="cd ~"
alias df="df -ahiT --total"
alias userlist="cut -d: -f1 /etc/passwd"
alias fhere="find . -name "
alias free="free -mt"
alias du="du -ach | sort -h"
alias ps="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"
alias wget="wget -c"
alias histg="history | grep"
alias myip="curl http://ipecho.net/plain; echo"
alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'
alias grep='grep --color=auto'

As for the number of difference, I'll add something to the first post.

Hi, thanks for sharing your alias list. I was looking at your folders alias.

Code:
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'

What does this one do? Seems to me like it's listing the number of folders in previous directories. I may be wrong though...
 
Hi, thanks for sharing your alias list. I was looking at your folders alias.

Code:
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'

What does this one do? Seems to me like it's listing the number of folders in previous directories. I may be wrong though...
IDK, I've never used it.
 
Hey paffett

I ran it from /home --
214598

Vektor
There appears to be a problem with the alias (shown in post #29) in so far as it runs the results through the "sort" command at the end which leads one to believe that the output should be a sorted list of directory sizes.

As found in your post #30, there is no list in the output, so nothing is sorted for the user, but just a single result which happens to derive from the "du -sk" command which outputs disk usage in kilobytes.

A similarly useful result as that proposed "find" command in the alias can be obtained with the simpler command:
Code:
du -sk .
This can be tested by running both commands in the same directory, that is, running the find command extracted from the alias, and the du command just above.

Perhaps the intended outcome of the command was to list the disk usage of the directories from which it is run, outputting the disk usage of each directory under it and listing them from largest to smallest. The following command can achieve that:
Code:
find . -maxdepth 1 -type d -exec du -sk {} \; | sort -rn | head -10

This command will produce a list of 10 directories from the directory in which it is run with the size in kilobytes of the respective disk usages. It has added the "head" command at the end to restrict the results to 10 lines of output. This is to limit the output in the case of a directory which contains too many underlying directories which would result in too many lines of output. There can be a a big difference running this proposed command from a small directory tree in the home directory, and running it over a system directory like /usr/lib. In the latter case, a small number of lines whether it's 10 or more makes sense, compared to not having a limit at all by excluding the head command at the end of the find command. I do not recommend running the command without a limit provided by the head command. The number of output lines can be adjusted by altering the 10 to another desired number.
 
Hey paffett

I ran it from /home --
214598

Vektor
Mine returns 476 from /home

I added a test folder and ran it again, it returned 480.

There appears to be a problem with the alias (shown in post #29) in so far as it runs the results through the "sort" command at the end which leads one to believe that the output should be a sorted list of directory sizes.

As found in your post #30, there is no list in the output, so nothing is sorted for the user, but just a single result which happens to derive from the "du -sk" command which outputs disk usage in kilobytes.

A similarly useful result as that proposed "find" command in the alias can be obtained with the simpler command:
Code:
du -sk .
This can be tested by running both commands in the same directory, that is, running the find command extracted from the alias, and the du command just above.

Perhaps the intended outcome of the command was to list the disk usage of the directories from which it is run, outputting the disk usage of each directory under it and listing them from largest to smallest. The following command can achieve that:
Code:
find . -maxdepth 1 -type d -exec du -sk {} \; | sort -rn | head -10

This command will produce a list of 10 directories from the directory in which it is run with the size in kilobytes of the respective disk usages. It has added the "head" command at the end to restrict the results to 10 lines of output. This is to limit the output in the case of a directory which contains too many underlying directories which would result in too many lines of output. There can be a a big difference running this proposed command from a small directory tree in the home directory, and running it over a system directory like /usr/lib. In the latter case, a small number of lines whether it's 10 or more makes sense, compared to not having a limit at all by excluding the head command at the end of the find command. I do not recommend running the command without a limit provided by the head command. The number of output lines can be adjusted by altering the 10 to another desired number.

Thank you for the in-depth explaination. When you say disk usage, is that meaning the directory size? Sorry I'm a bit of a newbie haha.
 
Code:
grep -o "alias " .zshrc | wc -l
51
 

Members online


Top