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.
Fuzzy
Level 4
Level 4
Posts: 251
Joined: Thu Jul 28, 2011 11:54 am

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

Post by Fuzzy »

deck_luck wrote: Fri Jul 17, 2020 6:00 pm It is common for the ~/.bashrc script to source the ~/.bash_aliases file. The ~/.bash_aliases file should contain user specific aliases.

The alias command is a builtin bash command. As long you are using bash as your shell, the alias command will display your bash aliases.
Thanks, deck_luck! I learned something new again!

Warmest Regards,
Fuzzy
;^)>>>
Aztaroth
Level 5
Level 5
Posts: 769
Joined: Mon Jan 11, 2021 1:48 am

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

Post by Aztaroth »

Hi. Some of mine :

Code: Select all

#OS
alias mint='cat /etc/os-release'
alias lskern='dpkg -l | grep linux-image | awk '{print$2}''
alias grubup='sudo update-grub2'
alias pc='inxi -S'
# Errors
alias err='dmesg --level=err -T'
alias warn='dmesg --level=warn -T'
alias logerr='journalctl -p 3 -xb'
alias chkenv='sudo find ~/ -user root'
# CleanUp
alias clearec='echo -n '' > ~/.local/share/recently-used.xbel'
alias clearthb='sudo rm -r ~/.cache/thumbnails/*'
# Material
alias mat='inxi -Fxz'
alias usb='lsusb -t'
alias diskstat='df -x tmpfs -Th | sort -n'
# Config
alias pcid='cat /etc/machine-id'
alias broken='apt search ?broken'
alias ban='xed /etc/modprobe.d/blacklist.conf'
alias baned='xed admin:///etc/modprobe.d/blacklist.conf'
# CSS
alias gtk='xed ~/.config/gtk-3.0/gtk.css'
About memorizing, a script of mine adds history as first line of .bash_history and alias as second. So !1 and !2 refreshes my brain when needed.
dual boot LMDE4 (mostly) + LM19.3 Cinnamon (sometimes)
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5695
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 »

majpooper wrote: Sat Jul 18, 2020 11:41 am Well I suppose whatever works for each individual - if you work on the same computer all the time doing the same routine repetitive tasks aliases might make things easier and faster. For me I tried them and found they were actually inconvenient because:
1.) I had to remember the alias - which I forgot
2.) I had to remember what I actually put in the alias when the output was not what I expected
Exactly; each user has different needs. I have a lousy memory (actually, it's good, just really, really short) so I put a tiny label on my laptop with a list of the aliases I made to remind me what they are (I have several labels on the laptop to remind me of several things). The only ones I made were to streamline manually TRIMming four external drives (or all, if I want to TRIM all four of my internal drives plus four external ones in one operation). The alias names are short, ranging from two to four characters (examples: TA is for TRIM All and TB is to TRIM the laptop Backup drives). I know the code to TRIM drives individually (or all one after the other) but typing it is tedious and prone to error; using an alias is faster and easier. My big laptop is currently the only machine I need the aliases on (when I was temporarily using a notebook while my laptop was being repaired, I just cheated and typed the TRIM All command when TRIMming the external drives).

Anyhoo, here 'tis:

Code: Select all

alias ta='sudo fstrim -av'
alias tb='sudo fstrim -v /media/jeannie/lt1_Data1_bu ; sudo fstrim -v /media/jeannie/lt1_TS_bu ; sudo fstrim -v /media/jeannie/lt1_Data2_bu ; sudo fstrim -v /media/jeannie/lt1_Data3_bu ; sudo fstrim -v /media/jeannie/lt1_Data4_bu'
alias td='sudo fstrim -v /media/jeannie/dt1_Data1 ; sudo fstrim -v /media/jeannie/dt1_Data2 ; sudo fstrim -v /media/jeannie/dt1_Data3 ; sudo fstrim -v /media/jeannie/dt1_Data4'
alias tdb1='sudo fstrim -v /media/jeannie/dt1_Data1_bu_1_3 ; sudo fstrim -v /media/jeannie/dt1_Data2_bu_1_3 ; sudo fstrim -v /media/jeannie/dt1_Data3_bu_1_3 ; sudo fstrim -v /media/jeannie/dt1_Data4_bu_1_3'
alias tdb2='sudo fstrim -v /media/jeannie/dt1_Data1_bu_2_4 ; sudo fstrim -v /media/jeannie/dt1_Data2_bu_2_4 ; sudo fstrim -v /media/jeannie/dt1_Data3_bu_2_4 ; sudo fstrim -v /media/jeannie/dt1_Data4_bu_2_4'
Last edited by Lady Fitzgerald on Tue Jun 15, 2021 2:49 pm, edited 1 time in total.
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

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

Post by Flemur »

These are for zsh; most will work with bash except as noted and the ones which use history, which is different (and worse) in zsh than bash:

Code: Select all

cdm='cd /mnt; HOME=. cd'
data='cd /mnt/DATA; HOME=. cd'
down='cd /mnt/DATA/download; HOME=. cd'
h='(){ history "-"$1 }'
hg='history 1 | grep '
run-help=man
sud='sudo env PATH=$PATH'
ud='sudo apt update && apt list --upgradable'
ug='sudo apt-get upgrade'
zs='source ~/.zshrc'
zv='    vi ~/.zshrc'
# These won't work with bash:
G=' | grep '
L=' | less '
S=' | sort '
SH=' | sort -h'
SN=' | sort -n'
The first three make it easier to cd to often-used directories:

Code: Select all

$ data do*/te*/j*
$ pwd
/mnt/DATA/download/temp/junk 
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
ajgringo619

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

Post by ajgringo619 »

Using fish shell:

Code: Select all

$ alias
alias b-list 'btrfs subvolume list -st --sort=path'
alias bk-logs 'journalctl -u btrfs_backup.service -S today'
alias btrfs 'sudo /usr/bin/btrfs'
alias cp 'cp -v'
alias dd 'dd status=progress'
alias df 'pydf -h'
alias f-list 'flatpak list --user --columns=name,description,application,version,size'
alias fd 'fdfind -H -E .snapshots -E OneDrive'
alias grep '/usr/bin/grep --color=auto'
alias hist 'history --show-time="[%Y-%m-%d %H:%M:%S] "'
alias inxi 'sudo inxi -Faz'
alias lan-scan 'nmap -sP 192.168.0.0/24'
alias lgrep '/usr/bin/grep --line-number --color=auto'
alias ls 'exa -aghHlm@ --group-directories-first --time-style long-iso --git --icons'
alias ls-timers 'systemctl list-timers --all'
alias lsblk 'lsblk -o NAME,LABEL,SIZE,FSTYPE,MOUNTPOINT,UUID'
alias mkdir 'mkdir -pv'
alias more 'less -MR'
alias mv 'mv -v'
alias n-list 'nmcli device show enp6s0'
alias ncdu 'ncdu -rxe --color dark'
alias pwd 'pwd -P'
alias py38-back '. $HOME/Development/projects/Linux/Backup_Scripts/venv/bin/activate.fish; cd $HOME/Development/projects/Linux/Backup_Scripts'
alias py38-crypto '. $HOME/Development/projects/Linux/Crypto_GUI/venv/bin/activate.fish; cd $HOME/Development/projects/Linux/Crypto_GUI'
alias py38-jupyter-crypto '. $HOME/Development/projects/Linux/Crypto_Jupyter/venv/bin/activate.fish; cd $HOME/Development/projects/Linux/Crypto_Jupyter'
alias py38-other '. $HOME/Development/projects/Linux/Other_Scripts/venv/bin/activate.fish; cd $HOME/Development/projects/Linux/Other_Scripts'
alias quit 'xfce4-session-logout --suspend'
alias reboot 'xfce4-session-logout --reboot'
alias rm 'rm -Iv'
alias s-list 'snapper -t 2 list --all-configs --columns number,type,date,used-space,cleanup,description,userdata'
alias s-list-nospace 'snapper -t 2 list --all-configs --disable-used-space --columns number,type,date,cleanup,description,userdata'
alias shutdown 'xfce4-session-logout --halt'
alias snapper 'sudo /usr/bin/snapper'
alias tarb 'tar --use-compress-program="lbzip2 --best -n 12"'
alias vi vim
alias wget 'wget -cv'
User avatar
Termy
Level 12
Level 12
Posts: 4254
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 »

All of my aliases, functions, and other BASH configurations can be found here:

https://github.com/terminalforlife/BashConfig

Cool thread. I love aliases, but remember not to overdo it, as they can dumb you down a bit on the terminal, making you far too reliant on them.

Regarding your `dpath` alias, here's a substantial improvement, taking advantage of variable expansion's pattern substitution with the printf builtin:

Code: Select all

printf '%s\n' ${PATH//:/ }
If you have some utterly bizarre and non-standard entries in your `PATH`, then don't use it.
I'm also Terminalforlife on GitHub.
Moonstone Man
Level 16
Level 16
Posts: 6078
Joined: Mon Aug 27, 2012 10:17 pm

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

Post by Moonstone Man »

Termy wrote: Thu Jun 24, 2021 5:06 am All of my aliases, functions, and other BASH configurations can be found here:
All of mine are here...

Code: Select all

alias soodo='sudo'
alias sodo='sudo'
alias sudoo='sudo'
alias suddo='sudo'
alias suudo='sudo'
alias soudo='sudo'
alias sudu='sudo'
alias sodit='sudo'
User avatar
Termy
Level 12
Level 12
Posts: 4254
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: Tue Jun 15, 2021 2:40 am ...
I was curious about what your apt cache ?broken command, but all I got was a broken REGEX error. :lol: I'm not familiar with apt.
Kadaitcha Man wrote: Thu Jun 24, 2021 5:12 am ...
:lol: Are you mocking me for having a sudo alias? If so, it's there for a reason. ;)
Last edited by Termy on Thu Jun 24, 2021 5:15 am, edited 1 time in total.
I'm also Terminalforlife on GitHub.
Moonstone Man
Level 16
Level 16
Posts: 6078
Joined: Mon Aug 27, 2012 10:17 pm

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

Post by Moonstone Man »

Termy wrote: Thu Jun 24, 2021 5:14 am :lol: Are you mocking me for having a sudo alias?
No. I'm mocking myself :)
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5695
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 »

Kadaitcha Man wrote: Thu Jun 24, 2021 5:12 am
Termy wrote: Thu Jun 24, 2021 5:06 am All of my aliases, functions, and other BASH configurations can be found here:
All of mine are here...

Code: Select all

alias soodo='sudo'
alias sodo='sudo'
alias sudoo='sudo'
alias suddo='sudo'
alias suudo='sudo'
alias soudo='sudo'
alias sudu='sudo'
alias sodit='sudo'
Auto correcting spell check for the terminal? :lol: :lol: :lol: :lol: :lol: I love it!
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5695
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: Thu Jun 24, 2021 5:06 am ...Cool thread. I love aliases, but remember not to overdo it, as they can dumb you down a bit on the terminal, making you far too reliant on them...
I agree but they can save a lot of time typing in some cases (critical for me since I type slowly and frequently make mistakes). In my case, I also have a lousy memory and have to look up most commands. I have to have crib notes on labels on my laptop for some critical ones; I even have one reminding me what my aliases are. :roll:
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
ajgreeny
Level 7
Level 7
Posts: 1635
Joined: Mon Nov 19, 2007 3:27 pm

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

Post by ajgreeny »

I am quite happy to admit that I use a lot of aliases, though I also run command alias fairly often to remind myself what is possible using them as it is quite easy to forget some of them.
The one I use most is undoubtedly alias q='exit', every time I use terminal; you use the keyboard in terminal so why move to the mouse just to close it and why type exit when it can just as easily be q?

Here's my list

Code: Select all

alias am='alsamixer'
alias addppa='sudo add-apt-repository'
alias ud='sudo apt update && apt list --upgradable'
alias ug='sudo apt full-upgrade'
alias autoclean='sudo apt-get autoclean'
alias autoremove='sudo apt-get autoremove'
alias bbc1='vlc http://vs-hls-pushb-uk-live.akamaized.net/x=3/i=urn:bbc:pips:service:bbc_one_south/mobile_wifi_main_sd_abr_v2_akamai_hls_live_http.m3u8'
alias bbc2='vlc https://vs-hls-push-uk-live.akamaized.net/x=3/i=urn:bbc:pips:service:bbc_two_hd/mobile_wifi_main_sd_abr_v2.m3u8'
alias bbc4='vlc http://vs-hls-pushb-uk-live.akamaized.net/x=3/i=urn:bbc:pips:service:bbc_four_hd/mobile_wifi_main_sd_abr_v2_akamai_hls_live_http.m3u8'
alias bbcnews='vlc https://vs-hls-push-uk-live.akamaized.net/x=3/i=urn:bbc:pips:service:bbc_news_channel_hd/mobile_wifi_main_sd_abr_v2.m3u8'
alias blk='sudo blkid -c /dev/null'
alias c='clear'
alias cat='cat -n'
alias cp='cp -aiv'
alias db='sudo updatedb'
alias df='df -hT'
alias dl='vnstat -d'
alias dll='vnstat -l'
alias dlm='vnstat --months'
alias dld='vnstat -d > /tmp/$(date +%F-%T)-DLs && mousepad /tmp/*DLs'
alias dlna+='systemctl start minidlna.service'
alias dlna-='systemctl stop minidlna.service'
alias dlnar='systemctl force-reload minidlna.service'
alias du='du -h -d 1 | sort -h'
alias emby+='systemctl start emby-server.service'
alias emby-='systemctl stop emby-server.service'
alias eo='exo-open'
alias xo='xdg-open'
alias fdisk='sudo fdisk -l'
alias free='free -mw'
alias fstab='cat /etc/fstab'
alias gip='get_iplayer'
alias gip*='get_iplayer "*"'
alias gipghd='cd Videos/BBC_iPlayer && get_iplayer -g --file-prefix="<nameshort><-senum><-episodeshort>"'
alias gipg='cd Desktop && get_iplayer -g --tvmode=better --file-prefix="<nameshort><-senum><-episodeshort>"'
alias gipi='get_iplayer --info'
alias gipr='get_iplayer --type radio'
alias gipu='get_iplayer --release-check'
alias glx='glxinfo && vblank_mode=0 glxgears'
alias grep='grep -n --color'
alias gpgupdate='echo "sudo apt-key adv --keyserver hkp://subkeys.pgp.net --recv-keys ##########"'
alias hw='sudo lshw -html > $(date +%F-%I%M)hw.html'
alias h='history'
alias iperf='iperf3 -c 192.168.1.40 -i 1 -t 13 -P 4 -O 3'
alias install='grep -i " install " /var/log/dpkg.log.1 /var/log/dpkg.log'
alias remove='grep -i " remove " /var/log/dpkg.log.1 /var/log/dpkg.log'
alias upgrade='grep -i " upgrade " /var/log/dpkg.log.1 /var/log/dpkg.log'
alias k='kill'
alias la='ls -Ap --group-directories-first'
alias ll='ls -lhp --group-directories-first --time-style="+%a %b %d %Y %H:%M"'
alias lla='ls -alhp --group-directories-first --time-style="+%a %b %d %Y %H:%M"'
alias l='ls -CFp --group-directories-first'
alias ls='ls -p --color=auto --group-directories-first'
alias lshw='sudo lshw -html > hardware.html'
alias menu='grep "menuentry " /boot/grub/grub.cfg | cut -c 1-82'
alias mv='mv -iv'
alias nano='nano -B -w -$'
alias p='xfce4-panel -r'
alias pag='ps aux | grep'
alias parted='sudo parted -l'
alias ping='ping -c 5'
alias pkx='pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY'
alias q='exit'
alias rm='rm -iv'
alias soff='sleep 3; xset dpms force off'
alias server='python2 -m SimpleHTTPServer 1111'
alias shred='shred -n 1 -vfzu'
alias ssh+='systemctl start ssh.service'
alias ssh-='systemctl stop ssh.service'
alias sw='sudo swapoff -a; sudo swapon -a'
alias zsync64='zsync http://cdimage.ubuntu.com/xubuntu/xenial/daily-live/current/xenial-desktop-amd64.iso.zsync -i /home/andrew/Downloads/ISOs/xenial-xubuntu-desktop-amd64.iso -o /home/andrew/Downloads/ISOs/xenial-xubuntu-desktop-amd64.iso'
That final zsync is one that I edit whenever I use it to update an iso image of a distro; it saves a huge amount of downloading and is incredibly useful.
Unfortunately Mint does not seem to offer any zsync capability which is a great shame, but then it does not have the same daily downloadable development versions that are available for all the Ubuntu DE versions.
mmphosis
Level 1
Level 1
Posts: 25
Joined: Sat Apr 11, 2020 11:22 pm

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

Post by mmphosis »

To show my aliases, I type aliases which only shows the names of my aliases.

Code: Select all

_functions	builtins	functions	ll		t
alert		cage		gray		ls		tally
aliases		clean		green		newest		task
alpha		cyan		grep		normal		to
b		egrep		grey		p		variables
beta		exports		inverse		r		violet
blue		fgrep		keywords	red		white
bold		fit		ktask		release		yellow
build		flash		la		run
So now, I will show the alias named aliases by typing alias aliases

Code: Select all

alias aliases=compgen -a|fit
My aliases alias contains another alias fit

Code: Select all

alias fit=column -c $(tput cols)
I use the fit alias, in my ktask and task alaises, alias ktask task

Code: Select all

alias ktask='ps -A h -o pid,ruser=RealUser -o comm=Command | fit'
alias task='ps -A h -o pid,ruser=RealUser -o comm=Command | grep -v '\'' kworker/'\'' | fit'
I also use the fit alias with other aliases to query other things, alias $(alias|grep fit|grep -v -e task -e aliases -e 'alias fit'|cut -d = -f 1|cut -d ' ' -f 2|xargs)

Code: Select all

alias _functions='compgen -A function|fit'
alias builtins='compgen -b|fit'
alias exports='export|sed -e '\''s/^declare -x //'\'' -e '\''s/=.*$//'\''|fit'
alias functions='declare -F|sed -e '\''s/^declare -f //'\''|sed '\''/^_/d'\''|fit'
alias keywords='compgen -b|fit'
alias variables='declare -p|grep '\''declare -- '\''|sed -e '\''s/^declare -- //'\'' -e '\''s/=.*$//'\''|fit'
I have a bunch of aliases to set colors and attributes in the terminal, alias $(alias|grep 'echo -ne'|cut -d = -f 1|cut -d ' ' -f 2|xargs)

Code: Select all

alias blue='echo -ne "\e[34m"'
alias bold='echo -ne "\e[1m"'
alias cyan='echo -ne "\e[36m"'
alias flash='echo -ne "\e[7m\e[5m"'
alias gray='echo -ne "\e[90m"'
alias green='echo -ne "\e[32m"'
alias grey='echo -ne "\e[90m"'
alias inverse='echo -ne "\e[7m"'
alias normal='echo -ne "\e(B\e[m"'
alias red='echo -ne "\e[31m"'
alias violet='echo -ne "\e[35m"'
alias white='echo -ne "\e[37m"'
alias yellow='echo -ne "\e[33m"'
Aztaroth
Level 5
Level 5
Posts: 769
Joined: Mon Jan 11, 2021 1:48 am

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

Post by Aztaroth »

Termy wrote :
I was curious about what your apt cache ?broken command, but all I got was a broken REGEX error. :lol: I'm not familiar with apt.
You're right, this alias is a non-sense.
I did a lot of copy/paste to share my aliases, because I wanted to exclude those referring to specific locations of my disk which wouldn't work on other systems. Some mix must have happened.
What works is :

Code: Select all

alias ?broken='sudo apt-get check'
and is just designed to check if all dependencies are OK.
Thanks for the correction.
I'll be more careful now 'cause I know someone reads my posts. :lol:
dual boot LMDE4 (mostly) + LM19.3 Cinnamon (sometimes)
thatchunkylad198966
Level 2
Level 2
Posts: 53
Joined: Wed May 05, 2021 9:11 am

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

Post by thatchunkylad198966 »

Hi! What is this and what do I do with them?
For my commands I use a lot I just place them in /usr/local/bin/ and chmod +x them.

Is there a better way?
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5695
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 »

thatchunkylad198966 wrote: Fri Jun 25, 2021 5:06 pm Hi! What is this and what do I do with them?
For my commands I use a lot I just place them in /usr/local/bin/ and chmod +x them.

Is there a better way?
I think so. An alias is essentially a shortcut for a terminal command or even multiple commands. You can reduce a long string of characters in a terminal command to one character or a combination of characters to simplify or speed up running a terminal command.

For example, to TRIM all the SSDs in my laptop plus any that are connected to the laptop via USB, I could type out sudo fstrim -av and hit ENTER or, with the alias I made, just type ta and hit ENTER.

I also have aliases that allow two to four characters to replace consecutive TRIM commands for up to four external SSDs in one shot (without having to also TRIM the four SSDs in my computer). The actual terminal commands are rather large, especially since I have to include the file path to each of the four drives, making them extremely time consuming to type out (especially for me) and prone to errors.

See here for one explanation on how to create aliases.

https://www.tecmint.com/create-alias-in-linux/

I attached a tutorial I made for myself on how to create persistent aliases that you may find useful.
How to Create Persistent Alias in Linux Mint.odt
(22.22 KiB) Downloaded 57 times
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: 4254
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 »

ajgreeny wrote: Thu Jun 24, 2021 11:39 am I am quite happy to admit that I use a lot of aliases, though I also run command alias fairly often to remind myself what is possible using them as it is quite easy to forget some of them.
You might like my wee LAD (List & Describe) program, then. It basically lists (sorted) and describes your aliases and functions in a pretty and easy-to-digest way. You have to write the descriptions yourself, of course, but once it's done, it's done. Here's what it shows for me:

Code: Select all

$ lad
FUNCTIONS (/home/ichy/.bash_functions)

  bins - A lite version of what lsbins(1) achieves.
  brn - Batch-rename a bunch of files or directories.
  suppress - Execute command ($1) and omit specified ($2) output.
  touched - Tell the user how many commits have touched the given file(s).

ALIASES (/home/ichy/.bash_aliases)

  alertme - Sound the bell and flash the terminal (white) thrice.
  apt-get - Much nicer output for the apt-get command.
  bat - Output the percentage of battery power remaining.
  sd - Change the CWD to: /media/$USER
I have plenty more than what is listed, but I drastically shrunk it to save taking up tons of space.
Lady Fitzgerald wrote: Fri Jun 25, 2021 6:13 pm For my commands I use a lot I just place them in /usr/local/bin/ and chmod +x them.

Is there a better way?
Depending on the use-case, yes.

An alias is a string (a single unit of one or more characters) which acts as a placeholder that is expanded to its true value (one or more commands to which it's assigned) when the user enters the string on the command-line. For example: I have an alias called sd ('sd' being the string), which, when I enter it on the terminal, gets expanded to the command cd /media/$USER prior to execution.

This:

Code: Select all

sd
Becomes this:

Code: Select all

cd /media/$USER
Then that is executed.

The reason I say it depends on the use-case is because your method affects all users on the system, which is especially not ideal in professional environments or for aliases involving some sort of sensitive information. Furthermore, if you install something which overwrites one of those files, you lose the ability to use it. It can also be easier to transfer your BASH configuration along with all of your aliases than it is to transfer each of your '/usr/local/bin' scripts.

While more advanced, another solution, which is sometimes a much better solution, is to use functions. Finally, for more complicated matters, people write scripts or programs, and it's then they typically install them into $PATH directory, or, if it's just for personal use, '~/bin' is a popular location.

To clarify, $PATH is an environment variable storing primary directories the system looks for executable files to be executed as commands, such as mkdir(1), ls(1), and find(1). Something you might find interesting to know, is that builtins, aliases, and functions all take priority over $PATH executables.
I'm also Terminalforlife on GitHub.
modele62
Level 2
Level 2
Posts: 64
Joined: Sun Apr 10, 2016 5:28 am

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

Post by modele62 »

One year+ later: many thanks to all the people who gently replied to my initial question (even the grumpy ones, yes), i learned some useful stuff
Nicolas

Custom laptop (i7 / 16 Gb RAM / 256 Gb NVMe + 2 Tb SSD) LM 21.2 Cinnamon, LM 21.2 XFCE, Fedora 39 KDE
Clevo W670 (i5 / 8 Gb RAM / 2 Tb SSHD) LM 20.3 XFCE
Acer Swift 1 (Pentium N4200 / 4 Gb RAM / 128 Gb SSD) LM 21.2 XFCE
roncraig
Level 1
Level 1
Posts: 44
Joined: Tue Jul 14, 2015 5:37 pm
Location: Ohio

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

Post by roncraig »

alias update='sudo apt update && sudo apt upgrade'
alias clean='sudo apt autoclean && sudo apt autoremove'
OS: Linux Mint 20.3 Una
Kernel: 5.15.0-33
DE: Cinnamon
Mobo: ASRock model: X299 Taichi CLX
CPU: Intel Core i9-10900X
GPU: NVIDIA GeForce RTX 3080
Memory: 64GB
Aztaroth
Level 5
Level 5
Posts: 769
Joined: Mon Jan 11, 2021 1:48 am

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

Post by Aztaroth »

Code: Select all

alias alien='find $HOME \! -user $USER'
Just checking if, in your /home there are files which don't belong to you (root or other users). No output is fine.
dual boot LMDE4 (mostly) + LM19.3 Cinnamon (sometimes)
Locked

Return to “Scripts & Bash”