Show me your aliases and i'll show you mine ;-)

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

Aztaroth wrote: Sat Sep 04, 2021 2:45 pm ...
Good idea for an alias.
I'm also Terminalforlife on GitHub.
c.f.a.j
Level 1
Level 1
Posts: 2
Joined: Tue Dec 24, 2013 12:19 am

Re: Show me your aliases and i'll show you mine ;-)

Post by c.f.a.j »

I have no aliases. As the bash man page says, "For almost every purpose, aliases are superseded by shell functions."
Chris F.A. Johnson
sofasurfer
Level 1
Level 1
Posts: 18
Joined: Sat Nov 13, 2021 6:02 pm

Re: Show me your aliases and i'll show you mine ;-)

Post by sofasurfer »

Code: Select all

alias m4a='cd Downloads; for f in *m4a; do ffmpeg -i "$f" -vn "$f".mp3;rm "$f";done;cd
alias batvol='cd Downloads; mkdir -p louder; for f in *.mp3; do   ffmpeg -i "$f" -filter:a "volume=3.5" "louder/$f";rm "$f"; done;cd ~
alias mp3='cd Downloads/louder; for f in *.mp3 ;do mv "$f" /media/daryl/"Clip Sport"/Podcasts ;done; cd ~'
[.code]
AwesomeOpossum74
Level 3
Level 3
Posts: 118
Joined: Fri Jan 21, 2022 2:29 pm

Re: Show me your aliases and i'll show you mine ;-)

Post by AwesomeOpossum74 »

Linux was designed to be efficient, which is why we have terse/short commands; typing 3 letters is better than 10. Aliases are great at facilitating that functionality.

I think it's great for adding things like --color=auto, that we wouldn't want to type every time, but that grant much usability.

As mentioned, and as was my first thought, they can cause you to forget the actual commands and parameters, so we must be careful. But, we have a backup in case we're on a foreign machine ... man. So all is not lost.

I tend to disagree with the way they aliased ll,la,l separately in our .bashrc files. That's getting too superfluous and clogged, IMO. What if you installed a utility executed as ll or la or l? You'd 1: not have access to those commands until you removed the alias. 2: You'd have to unlearn the aliased version.

I think .bash_aliases is a superfluous file, and just adds another item to our home directory lists. It's not like it's hard to manage aliases in our .bashrc files.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

AwesomeOpossum74 wrote: Tue Jan 25, 2022 1:07 pm I think .bash_aliases is a superfluous file, and just adds another item to our home directory lists. It's not like it's hard to manage aliases in our .bashrc files.
I find it very useful to keep these things separate. My BASH configuration files aren't especially short and simple, so that would make for a rather large file if I slammed them all together.

My '.bashrc' is 169 lines long, my '.bash_functions' file is 474 lines long. I no longer use '.bash_aliases', because I converted all of my aliases to functions a while ago. I just prefer having them separate, plus it means I can easily source one without the other(s). For a simpler/smaller configuration, I'd certainly agree with you, however. I actually removed a lot of functions/aliases from my configuration, so there used to be quite a bit more.
I'm also Terminalforlife on GitHub.
LittleScriptMan
Level 3
Level 3
Posts: 158
Joined: Thu Jan 13, 2022 8:42 am

Re: Show me your aliases and i'll show you mine ;-)

Post by LittleScriptMan »

Termy wrote: Tue Jan 25, 2022 3:33 pm I find it very useful to keep these things separate. My BASH configuration files aren't especially short and simple, so that would make for a rather large file if I slammed them all together.
I quite agree. I have even a 3rd file besides aliases (small) and functions (large) which is a file with constant values containing for example color and attributes for tput and echo (more easy to remember TRedfg or ERedfg than tputsetaf1 or '\033[0;30m' or dir variables like FFDir which points to the Firefox directory so that if one day Mozilla changes its dir location or if I have to install a flatpak, I'll just have to change this constant to let all my FF scripts work fine again. This file adds custom variables to the system environment and I'm using a first-letter-upcase naming in order to avoid collisions with system variables using only uppercase and shell commands always using lowercase.
Interests : Firefox, Cinnamon & Bash Scripts
LM Version : LMDE5 (LMDE4 just in case)
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

LittleScriptMan wrote: Tue Jan 25, 2022 6:46 pm ...
Sounds interesting. Do you have your configurations on GitHub at all? I'd like to check them out.
I'm also Terminalforlife on GitHub.
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5819
Joined: Tue Jan 07, 2020 3:12 pm
Location: AZ, SSA (Squabbling States of America)

Re: Show me your aliases and i'll show you mine ;-)

Post by Lady Fitzgerald »

AwesomeOpossum74 wrote: Tue Jan 25, 2022 1:07 pm ...As mentioned, and as was my first thought, they can cause you to forget the actual commands and parameters, so we must be careful...
Then you have people like me who either can't remember the commands in the first place or can't type them out without typos. :?
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

Lady Fitzgerald wrote: Tue Jan 25, 2022 8:31 pm Then you have people like me who either can't remember the commands in the first place or can't type them out without typos. :?
I suppose that's one of the reasons why we have GUIs. ;)
I'm also Terminalforlife on GitHub.
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5819
Joined: Tue Jan 07, 2020 3:12 pm
Location: AZ, SSA (Squabbling States of America)

Re: Show me your aliases and i'll show you mine ;-)

Post by Lady Fitzgerald »

Termy wrote: Wed Jan 26, 2022 11:32 am
Lady Fitzgerald wrote: Tue Jan 25, 2022 8:31 pm Then you have people like me who either can't remember the commands in the first place or can't type them out without typos. :?
I suppose that's one of the reasons why we have GUIs. ;)
Prexactly!
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
ganamant
Level 4
Level 4
Posts: 384
Joined: Sun Mar 29, 2015 4:08 pm

Re: Show me your aliases and i'll show you mine ;-)

Post by ganamant »

I always like using the -h option for human-readable output when the commands support it. Here are some of my favourite aliases:

Code: Select all

alias ll='ls -lh'
alias du='du -h'
alias df='df -h'
alias free='free -h'
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

ganamant wrote: Mon Apr 04, 2022 9:34 am I always like using the -h option for human-readable output when the commands support it. Here are some of my favourite aliases:
Fun fact, regarding human-readable format: you can use numfmt(1) to convert raw numbers to a human-readable size. There are some caveats, but in the right situation, it's awesome. I got that tip from xenopeek a while back on this board, IIRC. Here's an example, showing the total RAM found on the system, using the --from-unit flag to specify that it starts at Kibibyte:

Code: Select all

awk '$1 == "MemTotal:" {print($2)}' /proc/meminfo | numfmt --from-unit=K --to=iec
Also, I'm bored stuff right now, so here's a random command you might like:

Code: Select all

du -h --max-depth=1 "$HOME" | sort -rhk 1 | sed -r "1d; s/^(.+\t+)\/home\/$USER(\/.*)\$/\1~\2/" | column
It shows a sorted and columnized list of space-hungry directories in your HOME, with a more user-friendly path display.
I'm also Terminalforlife on GitHub.
User avatar
AZgl1800
Level 20
Level 20
Posts: 11184
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by AZgl1800 »

me?

fun one.

OkieNotFromMuskogee :lol: :mrgreen:
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
User avatar
Koentje
Level 7
Level 7
Posts: 1578
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Show me your aliases and i'll show you mine ;-)

Post by Koentje »

Old habits.. :oops:

Code: Select all

alias cd..='cd ..'
alias cls='echo -en "\033c"'
LittleScriptMan
Level 3
Level 3
Posts: 158
Joined: Thu Jan 13, 2022 8:42 am

Re: Show me your aliases and i'll show you mine ;-)

Post by LittleScriptMan »

Koentje wrote: Thu Apr 21, 2022 2:27 am

Code: Select all

alias cls='echo -en "\033c"'
Is the clear command not doing the same job ?
Interests : Firefox, Cinnamon & Bash Scripts
LM Version : LMDE5 (LMDE4 just in case)
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Show me your aliases and i'll show you mine ;-)

Post by Termy »

LittleScriptMan wrote: Thu Apr 21, 2022 1:06 pm Is the clear command not doing the same job ?
clear(1) is part of NCurses; specifically, the 'ncurses-bin' package, which may not have been around back in the day, hence "old habits". ;) Nowadays, yes, clear(1) and tput clear should more than suffice. In scripts, it might be quite nice to use the escape sequence, because it's more efficient, but it's not nearly as portable, if you assume all systems have tput(1) or clear(1).
I'm also Terminalforlife on GitHub.
User avatar
mrcat
Level 1
Level 1
Posts: 3
Joined: Mon May 02, 2022 12:43 pm

Re: Show me your aliases and i'll show you mine ;-)

Post by mrcat »

I like to have these aliases :)

Code: Select all

alias llt='ls -ltrh'
alias lla='ls -la'

alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias h='history'
Last edited by SMG on Mon May 02, 2022 7:47 pm, edited 1 time in total.
Reason: Removed signature to comply with forum rules.
Locked

Return to “Scripts & Bash”