aliasCreate shortcuts for commands you type all the time
alias defines a short name that the shell replaces with longer text before running a command, like k for kubectl or ll for ls -alF. Aliases only exist in interactive shells, are expanded as text, and are easy to bypass when you need the real command.
alias [NAME[='VALUE']]... | unalias [-a] NAME...You type kubectl and ls -lah hundreds of times a day. Make shortcuts.
aliasA shell builtin. With no arguments it lists every alias.
Aliases are pure text substitution done by the shell's parser. When bash reads a command line in an interactive shell, it checks whether the first word of each simple command is an alias. If so, it replaces the word with the alias text and checks the new first word again, so aliases can chain (ll -> ls -alF -> ls --color=auto -alF) but a word isn't expanded twice in a row. If the alias value ends in a space, the next word is checked too, which is why alias sudo='sudo ' lets aliases work after sudo. Expansion happens when a line is read, before any execution, so an alias defined on a line can't be used later on that same line. In non-interactive shells (scripts, cron, sh -c) the expand_aliases option is off, so aliases don't exist there. A backslash or quotes on the word (\ls, 'ls'), or command ls, skip the alias. Aliases can't take arguments in the middle; use a function for that.
aliasList all aliasesalias NAMEShow one aliasalias NAME='VALUE'Define or overwriteunalias NAME / unalias -aRemove one / remove all\NAME or command NAMERun the real command, skipping the aliastype NAMEShow whether NAME is an alias and what it expands to~/.bash_aliasesWhere Ubuntu's .bashrc loads personal aliases fromUsing aliases (k, ll, tf) inside scripts or cron jobsNon-interactive shells don't expand aliases, so the script fails with 'command not found'.
Write kubectl / ls -lah / terraform in full in scriptsalias rm='rm -rf'Every rm becomes recursive and forced; one typo deletes a tree without asking.
alias rm='rm -I' (prompt once for many files), or no rm alias at allalias gp="git push origin $(git branch --show-current)"Double quotes run the $(...) once, when the alias is defined, so it always pushes the branch you were on then.
alias gp='git push origin "$(git branch --show-current)"' # single quotes: evaluated at useExpecting 'sudo ll' to workOnly the first word is checked for aliases; ll after sudo isn't expanded.
alias sudo='sudo ' # trailing space makes the next word alias-expanded tooTry these on a Linux machine of your own. Each task has a hint and a solution.
List your current aliases. The sandbox shell is zsh; then start bash and compare.
In bash, create an alias logs that shows the last 20 lines of ~/logs/app.log, use it, then check it with type.
Make the alias permanent for bash and verify it in a new bash shell.
ll is an alias in the sandbox. Run the real ls without the alias's options.
aliasCreate shortcuts for commands you type all the time
alias defines a short name that the shell replaces with longer text before running a command, like k for kubectl or ll for ls -alF. Aliases only exist in interactive shells, are expanded as text, and are easy to bypass when you need the real command.
alias [NAME[='VALUE']]... | unalias [-a] NAME...You type kubectl and ls -lah hundreds of times a day. Make shortcuts.
aliasA shell builtin. With no arguments it lists every alias.
Aliases are pure text substitution done by the shell's parser. When bash reads a command line in an interactive shell, it checks whether the first word of each simple command is an alias. If so, it replaces the word with the alias text and checks the new first word again, so aliases can chain (ll -> ls -alF -> ls --color=auto -alF) but a word isn't expanded twice in a row. If the alias value ends in a space, the next word is checked too, which is why alias sudo='sudo ' lets aliases work after sudo. Expansion happens when a line is read, before any execution, so an alias defined on a line can't be used later on that same line. In non-interactive shells (scripts, cron, sh -c) the expand_aliases option is off, so aliases don't exist there. A backslash or quotes on the word (\ls, 'ls'), or command ls, skip the alias. Aliases can't take arguments in the middle; use a function for that.
aliasList all aliasesalias NAMEShow one aliasalias NAME='VALUE'Define or overwriteunalias NAME / unalias -aRemove one / remove all\NAME or command NAMERun the real command, skipping the aliastype NAMEShow whether NAME is an alias and what it expands to~/.bash_aliasesWhere Ubuntu's .bashrc loads personal aliases fromUsing aliases (k, ll, tf) inside scripts or cron jobsNon-interactive shells don't expand aliases, so the script fails with 'command not found'.
Write kubectl / ls -lah / terraform in full in scriptsalias rm='rm -rf'Every rm becomes recursive and forced; one typo deletes a tree without asking.
alias rm='rm -I' (prompt once for many files), or no rm alias at allalias gp="git push origin $(git branch --show-current)"Double quotes run the $(...) once, when the alias is defined, so it always pushes the branch you were on then.
alias gp='git push origin "$(git branch --show-current)"' # single quotes: evaluated at useExpecting 'sudo ll' to workOnly the first word is checked for aliases; ll after sudo isn't expanded.
alias sudo='sudo ' # trailing space makes the next word alias-expanded tooTry these on a Linux machine of your own. Each task has a hint and a solution.
List your current aliases. The sandbox shell is zsh; then start bash and compare.
In bash, create an alias logs that shows the last 20 lines of ~/logs/app.log, use it, then check it with type.
Make the alias permanent for bash and verify it in a new bash shell.
ll is an alias in the sandbox. Run the real ls without the alias's options.