AI Hints
Home›Linux Tutorial›The Environment
Linux · Lesson 87 of 120

Aliases and .bashrc

Your own shortcuts.

⏱ 2 min read▶ Video at 1:56:16🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Do you type the same long command again and again? Give it a short nickname. That's an alias. And put your aliases in a special file, so they're ready every time you open a terminal.

Aliases and .bashrc
From the video: Aliases and .bashrc
  • The same long command?
  • Give it a nickname
  • Save it for every terminal

Making an alias

Alias, a name, equals, and the command in quotes. Here, LL becomes LS dash LAH. Now typing LL runs the whole thing. And alias on its own lists all your aliases.

Terminal
alias ll='ls -lah'
ll Pictures
total 64K
drwxr-xr-x 2 sam sam 4.0K Jan  5 09:00 .
drwxr-x--- 1 sam sam 4.0K Jan  5 09:00 ..
-rw-r--r-- 1 sam sam  24K Jan  5 09:00 beach.jpg
-rw-r--r-- 1 sam sam  31K Jan  5 09:00 party.jpg
alias
alias ll='ls -lah'

The .bashrc file

Aliases disappear when you close the terminal. To keep them, add them to dot bash RC, in your home folder. Bash reads it every time a new terminal opens. Here we append an alias with echo, and tail shows it was added. Source runs the file straight away, so we don't need a new terminal.

Terminal
echo "alias update='sudo apt update && sudo apt upgrade'" >> ~/.bashrc
tail -n 1 ~/.bashrc
alias update='sudo apt update && sudo apt upgrade'
source ~/.bashrc && alias update
alias update='sudo apt update && sudo apt upgrade'

People love sharing their aliases. A few classics. LL for a detailed listing. Dot dot, for CD dot dot. RM dash I instead of plain RM, so deletes always ask first. And a short name for updating the system. Just don't name an alias after a command you'll need in its normal form.

keyvalue
llls -lah
..cd ..
rmrm -i, safer
updatesudo apt update && upgrade

Summary

Aliases are nicknames for commands, and dot bash RC makes them permanent. Source reloads it. Next, packing files into archives.

Key takeaways
  • alias ll='ls -lah'
  • ~/.bashrc
  • source ~/.bashrc
Next up: Archives with tar — packing many files into one