The alias built-in in shells, used to define shortcuts for frequently used commands.
87
votes
9answers
5k views
In Bash, when to alias, when to script, and when to write a function?
It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing.
But people shouldn't need 10 years for this. If I were just ...
60
votes
6answers
2k views
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 ...
55
votes
12answers
12k views
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 ...
49
votes
21answers
4k views
Quick directory navigation in the terminal
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 ...
22
votes
3answers
1k views
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 ...
18
votes
6answers
474 views
Why is aliasing over standard commands not recommended?
For example, a common alias I've seen in the ~/.bashrc file (or equivalents) is
alias rm='rm -i'
However, I've seen people recommend against this because
the alias might not exist on another ...
16
votes
3answers
4k views
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?
15
votes
5answers
9k views
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 ...
13
votes
2answers
1k views
aliasing cd to pushd - is it a good idea?
Is it a good idea to use the following alias:
cd() {
pushd $1;
}
in bash?
I think this would be very useful, since I can then use a series of popds instead of just a cd - once.
Is there any ...
12
votes
4answers
758 views
How can I create an alias for a command that includes a space?
Most of my my aliases are of this form: alias p='pwd'
I want to alias git commit so that it does git commit -v
But trying to create an alias with a space gives an error:
$ alias 'git commit'='git ...
12
votes
3answers
1k views
Share aliases and PATH setting between zsh and bash
The shell that I normally use is zsh. I have several aliases to enable color in some programs such as ls and grep. I've also set my custom path so that I can execute programs in non-standard place ...
10
votes
1answer
908 views
bash functions vs scripts
This site says, "Shell functions are faster [than aliases]. Aliases are looked up after functions and thus resolving is slower. While aliases are easier to understand, shell functions are preferred ...
10
votes
1answer
2k views
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 ...
9
votes
5answers
288 views
How to test for possible conflicts while using alias in bashrc?
Is there a simple way to list all the command conflicts that have occurred in the system due to the bashrc update involving alias commands?
For example, someone writes alias ...
9
votes
2answers
332 views
How to use - as alias?
When I was using openSUSE 11.3, it came with several aliases already set up. Two that I used a lot were + for pushd . and - for popd. Now on Debian, I can't figure out how to create the second one. ...
9
votes
1answer
252 views
Grep alias - line numbers unless it's in a pipeline
I want to create a bash alias for grep that adds line numbers:
alias grep='grep -n'
But that, of course, adds line numbers to pipelines as well. Most of the time (and no exceptions come to mind) I ...
8
votes
5answers
2k views
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 ...
8
votes
3answers
883 views
Is there a 'rc' configuration file for grep/egrep? (~/.egreprc?)
I usually do some grep when developing, and there are some extensions that I always don't want to look for (like *.pyc).
Is it possible to create a ~/.egreprc or something like that, and put some ...
8
votes
2answers
311 views
Change directory without typing cd?
Is it possible to make bash change directory in command line simply by typing that directory without any commands like cd?
For example is it possible instead of writing this:
$ cd /tmp
I just want ...
7
votes
3answers
274 views
How can I find a rogue alias declaration?
I'm trying to find where a specific alias has been declared. I've searched all the usual places I know to look for aliases:
~/.bashrc
~/.bash_profile
/etc/bashrc
/etc/profile
With no luck.
I know ...
7
votes
3answers
229 views
Do you prefer bash scripts or aliases for shortcuts?
I have a ~/bin directory (which is on my PATH) where I store a lot of little 1 or 2 line scripts. Some of them just cd into a directory and run a command on a file, like vim or something. But I also ...
6
votes
2answers
408 views
Difference between alias in zsh and alias in bash
I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases ...
6
votes
2answers
715 views
Is a symbolic/soft link similar to a shortcut/alias on a desktop?
It sounds to me like the basic idea of soft/symbolic links compared to shortcuts (on a PC) or aliases (on a Mac) are the same thing. Am I way off? Are they similar?
6
votes
1answer
2k views
How to reset a shell environment?
This issue has been bugging me for a while, and although I've taught I've found my answer through EnvWatcher, unfortunately it only works on Bash. And I use zsh.
I would like to replicate the things ...
5
votes
3answers
288 views
Aliases for 'sudo /etc/init.d/'
Are there any standards for aliasing sudo /etc/init.d/? I'm sure many people have considered cutting down these 17 characters to just 2 or so.
5
votes
4answers
126 views
Change command-line “environment” to programs command
In a console, is it possible to change into a commands "environment"? To explain, I take "git" as an example. While programming and using a git repository, I change to the repos path and then do many ...
5
votes
1answer
994 views
Alias a command to run in the background
I'd like a keyboard shortcut to work as so:
> e foo.txt
to expand as
> emacs foo.txt &
It's simple to use alias e=emacs, but how do I insert the & after the filename? I realize it ...
5
votes
2answers
109 views
Aliases interpretation
I have a few aliases in .bash_aliases.
I defined c alias as follows, but it does not work as it should
...
alias cd='cd; ls -r --time=atime'
alias c='cd'
...
in .bashrc there is a line
alias ...
5
votes
3answers
910 views
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 ...
5
votes
1answer
318 views
What commands have -h human readable option, and how can I enable it by default w/env variable?
I'm tired of using aliases or typing -h. I want human readable output 24/7. Is there a way to enable it all the time for all commands that offer it?
Thanks.
5
votes
1answer
191 views
Does one alias affect another alias?
I don't have many aliases set up in my .bash_aliases file just yet. Only recently have I discovered how useful they can be.
I can see myself getting quite hooked on aliases so before the file gets ...
5
votes
2answers
4k views
Can I make scripts use aliases instead of commands?
I have an alias for a command (I'm setting up a Python development environment)
alias python=~/virtualenv/bin/python
so that I can run ~/virtualenv/bin/python by just typing python. Now in my ...
5
votes
3answers
230 views
For a same unix or linux user, different sets of environment variables
I'm using tcsh, and for a specific project every member of my team connects to a server with the same user. (This is something we cannot change).
The situation arises because I want to have some ...
5
votes
1answer
99 views
ask for comfirmation when file is replaced using a redirection
I'm a careless terminal driver scared of accidentally deleting files, hence using some aliases like alias rm='rm -i' for rm, mv, cp. How can I get a similar confirmation behavior for file redirections ...
5
votes
2answers
142 views
Mailman / Postfix Configuration Assistance
I am writing for some help regarding Postfix configuration.
I cannot seem to get Postfix configured properly to transfer mail to the mailing list installed on the same server. I followed many steps ...
4
votes
5answers
122 views
How to use ' in alias?
I have one-line that I want to call using alias.
while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done
I tried to escape ' like \' but it didn't work.
What is the ...
4
votes
2answers
198 views
Combine two commands in .bash_profile
In my .bash_profile file, I'd like to setup a single command alias that is two commands that execute one after another. The first command takes an argument from the command line and the second is ...
4
votes
2answers
311 views
cp -f cannot overwrite cp -i alias
In my /home/user/.bashrc file, I have those aliases to prevent mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
If I'm really sure of what I'm doing, I can overwrite rm and mv aliases ...
4
votes
1answer
236 views
Preventing use of `cd ..` in bash?
I have set up an alias in my .bashrc as follows:
alias u='cd ..'
All is well in my world... until I type cd .. and cringe that I did not use my incredible new alias. In fact, with this particular ...
4
votes
2answers
1k views
How do I temporarily bypass an alias in tcsh?
I am using tcsh. bash and zsh and other suggestions won't help here.
I have several aliases that are named the same thing as another command, so if I did unalias it, typing the same thing would now ...
4
votes
2answers
1k views
Refresh aliases after defining new command
When I define new alias in .bash_aliases file or new function in .bashrc file is there some refresh command to be able immediately use the new aliases or functions without closing terminal (in my case ...
4
votes
1answer
1k views
How do I get which to show aliases? [duplicate]
Possible Duplicate:
How to use which on an aliased command?
I'm used to working on systems where which would list aliases, so e.g. if I have an alias like this:
alias ...
4
votes
3answers
254 views
Forcing an 'added' alias to every command
Is it possible to forcibly add a timing alias (for lack of a better way to phrase it) to every command in bash?
For example, I would like to have a specific user who whenever a command is run, it is ...
4
votes
1answer
74 views
Remove alias from current session
How to remove a alias from current session without closing that session?
3
votes
2answers
3k views
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?
3
votes
2answers
148 views
place the aliased version of an existing command in /usr/bin/
I use Vim a lot, and I know how I can start vim in insert mode. So I have an alias named vii in my .bash_aliases file.
On other hand I use Git a lot too, and I have this line in my .gitconfig:
...
3
votes
2answers
219 views
Are there any utilities to quickly add, list and remove command aliases?
I'd like to be able to quickly, on-the-fly add (and list/remove) command aliases so that they persist between shell restarts (as if they were added to .bashrc). Are there any ready ...
3
votes
1answer
430 views
How can I alias to `!!` (last command)?
!! in bash runs last command. I find it too difficult to type given how much I use it. alias to the rescue, I presumed.
Or not. I tried:
$ alias dl='!!' # Aliasing
$ echo Testing123 ...
3
votes
2answers
165 views
How to set an alias on a per-directory basis?
Suppose you have an alias go, but want it to do different things in different directories?
In one directory it should run cmd1, but in another directory it should run cmd2
By the way, I have an ...
3
votes
2answers
220 views
List only temporary aliases in bash
I know that to list all aliases in a given bash session with alias -p. Is there a way to get a list of all the temporary aliases in a given bash session, i.e. all aliases that aren't in my bash ...