The alias built-in in shells, used to define shortcuts for frequently used commands.

learn more… | top users | synonyms

146
votes
10answers
15k 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 ...
86
votes
13answers
32k 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 ...
69
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 ...
58
votes
24answers
8k 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 ...
36
votes
4answers
4k 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 ...
33
votes
6answers
23k 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 ...
25
votes
3answers
6k 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?
20
votes
4answers
2k views

Automatically detect when I typed “vi” but meant “cd”?

Title says it all. About 5 times a day, I type "vi" when I meant "cd", and end up opening a directory in vi. It's making me NUTS. It seems like there should be a way to detect when I type in "vi + ...
19
votes
2answers
3k 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 ...
19
votes
6answers
608 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 ...
18
votes
1answer
2k views

Aliases vs 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 ...
18
votes
1answer
3k 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 ...
16
votes
4answers
4k views

How can I create an alias for a git [action] command (which includes spaces)?

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 ...
16
votes
2answers
461 views

How to retrieve lost aliases?

Let me start by saying I know this was dumb. Time and Linux make fools of us all. I made an echo command to my .bash_aliases file and erased all of my aliases, except the test alias. However, I ...
15
votes
1answer
765 views

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 ...
14
votes
5answers
6k 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 ...
13
votes
3answers
2k 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 ...
13
votes
1answer
495 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 ...
11
votes
5answers
545 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 ...
11
votes
4answers
2k 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 ...
10
votes
2answers
387 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. ...
10
votes
2answers
293 views

How to document my custom bash functions and aliases?

Problem: I have multiple bash functions and aliases. I can't remember all of them off the top of my head, so I usually end up opening my .bash_functions and .bash_aliases files to find what I need. ...
10
votes
1answer
558 views

How many different ways can you create an “alias” in Bash?

I only know of two ways: alias foo=bar and function foo() { bar }. The reason I'm asking is that - all of a sudden in one of my bash sessions - I cannot run the ln command because bash is erroring ...
9
votes
3answers
2k 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 ...
9
votes
2answers
10k 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?
9
votes
2answers
726 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 ...
8
votes
6answers
6k views

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 ...
8
votes
5answers
183 views

How can I “stack” shell aliases?

In my .profile (sourced in sh emulation mode from my .zshrc) I have the following snippet: if [ -f /usr/bin/pacmatic ]; then alias pacman=pacmatic fi # Colorized Pacman output alias ...
8
votes
4answers
303 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 ...
8
votes
1answer
979 views

Can rm recursively remove empty directories?

In an old version of Unix, the rm command would delete directories if they were empty. From the Research Unix Eighth Edition man page for rm: "If an entry is a directory it is removed only if empty." ...
7
votes
2answers
2k views

Is it possible to include file in config file of zsh? How?

I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc. Is it possible? If ...
7
votes
2answers
6k 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 ...
7
votes
2answers
1k 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?
7
votes
1answer
310 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 ...
7
votes
2answers
852 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 ...
7
votes
2answers
2k 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 ...
7
votes
1answer
6k 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 ...
7
votes
3answers
550 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 ...
7
votes
2answers
418 views

alias vs export for simple commands

For simple commands like less, is it better to make an alias or to export the options? Is there any benefit of one over the other? For example, if I want less to always use the -R option to show raw ...
7
votes
3answers
91 views

Resolve all aliases in a zsh command line

I have nested aliases and I want to resolve all of them before executing the command. How do I do that? If there is a function that is not bound to any keys then M-x foobar is fine for me too. I ...
6
votes
1answer
2k 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 ...
6
votes
2answers
635 views

l, ls & la — what are the differences, and are there more of these commands?

So, through typing several commands I've found that there's not only ls, but l and la too. There doesn't appear to be any man entries on Ubuntu 12.14. They all appear to do similar things with minor ...
6
votes
2answers
180 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 ...
6
votes
1answer
1k 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 ...
6
votes
1answer
92 views

What are the side effects of having several UNIX users share one UID?

The sys-apps/shadow package on my GNU / Linux system comes with a useradd command that supports an option that I have previously overlooked: --non-unique. For the sake of convenience when shellig home ...
6
votes
2answers
498 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?
6
votes
2answers
6k 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 ...
6
votes
1answer
295 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 ...
5
votes
3answers
566 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
2answers
2k 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 ...