Questions tagged [alias]

An alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence. This can save a great deal of typing at the command-line and avoid having to remember complex combinations of commands and options.

An alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence.

If, for example, we include alias lm="ls -l | more" in the ~/.bashrc file, then each lm typed at the command-line will automatically be replaced by a ls -l | more. This can save a great deal of typing at the command-line and avoid having to remember complex combinations of commands and options.

Setting alias rm="rm -i" (interactive mode delete) may save a good deal of grief, since it can prevent inadvertently deleting important files.

Further reading

In Bash, when to alias, when to script, and when to write a function?

How do I get bash completion for command aliases?

External references

890 questions
427
votes
16 answers

In Bash, when to alias, when to script and when to write a function?

Noone should need 10 years for asking this question, like I did. If I were just starting out with Linux, I'd want to know: When to alias, when to script and when to write a function? Where aliases are concerned, I use aliases for very simple…
ixtmixilix
  • 13,040
  • 27
  • 82
  • 118
330
votes
5 answers

Why doesn't my Bash script recognize aliases?

In my ~/.bashrc file reside two definitions: commandA, which is an alias to a longer path commandB, which is an alias to a Bash script I want to process the same file with these two commands, so I wrote the following Bash script: #!/bin/bash for…
Zaid
  • 10,442
  • 13
  • 38
  • 36
319
votes
23 answers

How to have tail -f show colored output

I'd like to be able to tail the output of a server log file that has messages like: INFO SEVERE etc, and if it's SEVERE, show the line in red; if it's INFO, in green. What kind of alias can I setup for a tail command that would help me do this?
Amir Afghani
  • 7,083
  • 11
  • 26
  • 23
210
votes
8 answers

Run a command that is shadowed by an alias

Let's say I have the following alias in bash - alias ls='ls --color=auto' - and I want to call ordinary ls without options. Is the only way to do that is to unalias, do the command and then alias again? Or there is some nifty trick or workaround?
Mirzhan Irkegulov
  • 8,248
  • 11
  • 45
  • 54
140
votes
6 answers

How to pass parameters to an alias?

For bash script, I can use "$@" to access arguments. What's the equivalent when I use an alias?
prosseek
  • 8,418
  • 16
  • 47
  • 43
133
votes
9 answers

How do I get bash completion for command aliases?

I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided by aptitude when I hit the tab key? i.e. when I…
levesque
  • 3,775
  • 5
  • 20
  • 15
133
votes
36 answers

Quick directory navigation in the bash shell

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd /[full-path]/ all the time. Are there any shortcut commands to…
saiy2k
  • 1,593
  • 3
  • 11
  • 10
128
votes
6 answers

watch command alias expansion

If a run the watch command containing an alias, it will not expand the alias. I have tried both with single quote and double quotes, in fact given the following alias: # alias ll alias ll='ls -l --color=tty' The following command will fail # watch…
ztank1013
  • 2,161
  • 2
  • 13
  • 14
124
votes
11 answers

How can I install the `ll` command on Mac OS X?

I'm using Mac OS X. When I SSH into servers I find the ll command useful, but it's not available on my local machine. How can I install it?
Eonil
  • 4,607
  • 11
  • 30
  • 30
97
votes
7 answers

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is that if I want to use which to see where my…
Adrian Petrescu
  • 1,077
  • 1
  • 9
  • 10
77
votes
3 answers

Refresh aliases and functions after defining new aliases and functions?

When I define a new alias in .bash_aliases file or a new function in .bashrc file, is there some refresh command to be able immediately use the new aliases or functions without closing the terminal (in my case xfce4-terminal with a few tabs open,…
xralf
  • 16,149
  • 29
  • 101
  • 149
72
votes
13 answers

Show only hidden files (dot files) in ls alias

I'm using the command ls -a | grep '^\.' for showing only the hidden files. I added the line alias hidden='ls -a | grep '^\.'' # show only hidden files to .bash_aliases file but this does not work. It's probably the problem with ' character. Could…
xralf
  • 16,149
  • 29
  • 101
  • 149
70
votes
5 answers

What is the difference between ls and l?

I accidentally typed l instead of ls today and found that the command still printed a list of the files in my current directory. Trying l --help brings up the help file for ls suggesting that l is just an alias of ls. Howver, each file was suffixed…
Rupert Madden-Abbott
  • 1,044
  • 1
  • 9
  • 10
63
votes
6 answers

How can I `alias sudo !!`?

I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal !! and prints sudo: !!: command not found If I use double quotes, it substitutes the double bang in the string itself, so that…
Manishearth
  • 1,007
  • 2
  • 10
  • 12
47
votes
5 answers

Is there a 'rc' configuration file for grep/egrep? (~/.egreprc?)

I usually use grep when developing, and there are some extensions that I always want to exclude (like *.pyc). Is it possible to create a ~/.egreprc or something like that, and add filtering to exclude pyc files from all results? Is this possible, or…
1
2 3
59 60