Difference between revisions of "Aliases in .bashrc"

formatting and removal of unnecessary whitespace
imported>Fhdk
(remove yay)
(formatting and removal of unnecessary whitespace)
Line 1: Line 1:
 
==What's .bashrc? What is an alias?==
== What's .bashrc? What is an alias? ==
* '''.bashrc''' is the ''configuration file'' for bash, a linux shell/command interpreter.
 
* An '''alias''' is a ''substitute for a (complete) command''. It can be thought of as a shortcut.
 
* '''.bashrc''' is found in the ''home folder'' of a user ( ~ ) . It is a hidden file, to see it show hidden files in your file manager or use '''ls -a'''
'''.bashrc''' is the ''configuration file'' for bash, a linux shell/command interpreter.
==Backup your current .bashrc==
 
It can be useful to backup the ~/.bashrc before editing it, as it allows one to be able to easily recover from the unexpected. To make a backup of your current .bashrc . Open a terminal and execute
An '''alias''' is a ''substitute for a (complete) command''. It can be thought of as a shortcut.
{{UserCmd|command=cp ~/.bashrc ~/.bashrc.bak}}
 
The original .bashrc can be restored with by executing
'''.bashrc''' is found in the ''home folder'' of a user ( ~ ) . It is a hidden file, to see it show hidden files in your file manager or use '''ls -a'''
{{UserCmd|command=cp -i ~/.bashrc.bak ~/.bashrc}}
 
==Note==
== Backup your current .bashrc ==
 
It can be useful to backup the ~/.bashrc before editing it, as it allows one to be able to easily recover from the unexpected.
 
To make a backup of your current .bashrc . Open a terminal and type -
 
cp ~/.bashrc ~/.bashrc.bak
 
The original .bashrc can be restored with -
 
cp -i ~/.bashrc.bak ~/.bashrc
 
== Note ==
 
Any changes made to the .bashrc will have no effect on any currently open terminal windows. To test newly updated changes in your .bashrc open a new terminal or use the command:
Any changes made to the .bashrc will have no effect on any currently open terminal windows. To test newly updated changes in your .bashrc open a new terminal or use the command:
 
{{UserCmd|command=source .bashrc}}
source .bashrc
 
== Aliases Examples ==
== Aliases Examples ==
Aliases can turn a complex command string into a simple custom made command that one can type in the Terminal.  
Aliases can turn a complex command string into a simple custom made command that one can type in the Terminal.  
The following can be added to the .bashrc file.
The following can be added to the .bashrc file.
=== For updating your system ===
=== For updating your system ===
 
To upgrade the system via pacman, the command used is  
To upgrade the system via pacman, the command used is '''''sudo pacman -Syu'''''
{{UserCmd|command=sudo pacman -Syu}}
 
This can be aliased in .bashrc with
This can be aliased in .bashrc with-
{{File|file=~/.bashrc|
 
content=<pre>...
alias pacup="sudo pacman -Syu"  
alias pacup="sudo pacman -Syu"
 
...</pre>}}
 
To upgrade packages installed from the AUR via pamac, the command used is  
To upgrade packages installed from the AUR via pamac, the command used is '''''pamac upgrade --aur'''''
{{UserCmd|command=pamac upgrade --aur}}
 
This can be aliased with
This can be aliased with-
{{File|file=~/.bashrc|
 
content=<pre>...
alias aup="pamac upgrade --aur"  
alias aup="pamac upgrade --aur"
 
...</pre>}}
 
=== For editing commonly used files ===
=== For editing commonly used files ===
To edit '''.bashrc''' itself and automatically reload bash configuration file (so that changes made to .bashrc can be implemented in current terminal session)
To edit '''.bashrc''' itself and automatically reload bash configuration file (so that changes made to .bashrc can be implemented in current terminal session)
 
{{File|file=~/.bashrc|
alias bashrc="nano ~/.bashrc && source ~/.bashrc"  
content=<pre>...
 
alias bashrc="nano ~/.bashrc && source ~/.bashrc"
 
...</pre>}}
To edit '''/etc/fstab'''
To edit '''/etc/fstab'''
 
{{File|file=~/.bashrc|
alias fstab="sudo nano /etc/fstab"
content=<pre>...
 
alias fstab="sudo nano /etc/fstab"
 
...</pre>}}
To edit '''/etc/default/grub'''
To edit '''/etc/default/grub'''
 
{{File|file=~/.bashrc|
alias grub="sudo nano /etc/default/grub"
content=<pre>...
 
alias grub="sudo nano /etc/default/grub"
...</pre>}}
=== To update GRUB ===
=== To update GRUB ===
To update your grub bootloader using the '''sudo update-grub'''
To update your grub bootloader using the '''sudo update-grub'''
 
{{File|file=~/.bashrc|
alias grubup="sudo update-grub"
content=<pre>...
 
alias grubup="sudo update-grub"
== Conclusion ==
...</pre>}}
 
==Conclusion==
This list is not comprehensive. Almost anything that is commonly used can be shortened with an alias
This list is not comprehensive. Almost anything that is commonly used can be shortened with an alias
 
==See Also==
 
== See Also ==
[https://www.gnu.org/software/bash/manual/html_node/index.html Bash documentation]
[https://www.gnu.org/software/bash/manual/html_node/index.html Bash documentation]


[[Category:Contents Page]]
[[Category:Contents Page]]
Moderators, translator
424

edits