Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged


The other answers provide some soft general guidelines based on personal taste, but ignore many pertinent facts that one should consider when deciding between scripts, functions, or aliases. Aliases and Functions ¹ The entire contents of aliases and functions are stored in the shell's memory. A natural consequence of this is aliases and functions can ...


An alias should effectively not (in general) do more than change the default options of a command. It is nothing more than simple text replacement on the command name. It can't do anything with arguments but pass them to the command it actually runs. So if you simply need to add an argument at the front of a single command, an alias will work. Common ...


You can also prefix a back slash to disable the alias: \ls Edit: Other ways of doing the same include: Use "command": command ls as per Mikel. Use the full path: /bin/ls as per uther. Quote the command: "ls" or 'ls' as per Mikel comment. You can remove the alias temporarily for that terminal session with unalias command_name.


If you're just switching between two directories, you can use cd - to go back and forth.


MacOS: alias ll='ls -lG' Linux: alias ll='ls -l --color=auto' Stick that in ~/.bashrc.


grc, the generic colourizer is pretty cool. apt-get install grc Just do grc tail -f /var/log/apache2/error.log and enjoy! You’ll also find it on GitHub.


which is actually a bad way to do things like this, as it makes guesses about your environment based on $SHELL and the startup files (it thinks) that shell uses; not only does it sometimes guess wrong, but you can't generally tell it to behave differently. (which on my Ubuntu 10.10 doesn't understand --skip-alias as mentioned by @SiegeX, for example.) type ...


Have the shell list the dot files, and tell ls not to see through directories: ls -d .*


Aliases are only expanded as the first argument, or after another alias with a trailing space on the end of the command. From bash's help alias: A trailing space in VALUE causes the next word to be checked for alias substitution when the alias is expanded. To do this, try the following: alias watch='watch ' alias ll='ls -l --color=tty' watch ll Bear ...


That's what the command command is for. Try command ls This tells the shell to bypass aliases and functions. This way is supported by bash, zsh, and ash/dash.


There is a shell variable CDPATH in bash and ksh and cdpath in zsh: CDPATH The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. So you can set in your ~/.bashrc: export CDPATH=/Project/Warnest:~/Dropbox/Projects/ds Then cd ...


Sourcing the changed file will provide access to the newly written alias or function in the current terminal, for example: source ~/.bashrc An alternative syntax: . ~/.bashrc Note that if you have many instances of bash running in your terminal (you mentionned multiple tabs), you will have to run this in every instance.


!! is expanded by bash when you type it. It's not expanded by alias substitution. You can use the history built-in to do the expansion: alias sbb='sudo $(history -p !!)' If the command is more than a simple command (e.g. it contains redirections or pipes), you need to invoke a shell under sudo: alias sbb='sudo "$BASH" -c "$(history -p !!)"'


The two, no, three, ... Amongst the main obstacles to that are: It's not a valid name for an alias. Bash's online manual: The characters ... and any of the shell metacharacters or quoting characters listed above may not appear in an alias name. (, ), &, | and whitespace are out in Bash 4.4. That particular string is not the only way to write a ...


Something else you might try is a tool called autojump. It keeps a database of calls to it's alias (j by default) and attempts to make intelligent decisions about where you want to go. For example if you frequently type: j ~/Pictures You can use the following to get there in a pinch: j Pic It is available of Debian and Ubuntu, and included on a per-...


If it's a small number of directories, you can use pushd to rotate between them: # starting point $ pwd /Project/Warnest/docs # add second dir and change to it $ pushd ~/Dropbox/Projects/ds/test ~/Dropbox/Projects/ds/test /Project/Warnest/docs # prove we're in the right place $ pwd ~/Dropbox/Projects/ds/test # swap directories $ pushd /Project/Warnest/docs ~...


With the assumption that you call vi with the directory as the last argument: vi() { if [[ -d ${!#} ]]; then cd "$@" else command vi "$@" fi }


In OS X 10.9.5 since Mavericks (and at least up to El Capitan) you have to add an alias command to your .bash_profile file in your home folder: ~/.bash_profile which is equivalent to your user path at /Users/YOUR_USER_NAME/.bash_profile To see that file in finder you have to activate the display of hidden files (e.g. using the app InVisible). Otherwise ...


Alias in bash can't have arguments, but you can use functions. e() { emacs "$@" & } then e foo.txt will do what you want.


I think it's up to each person's taste. For me the logic goes like this: First I try to make an alias, because it's the simplest. If the thing is too complicated to fit in one line, I try to make it a function. When the function starts to grow beyond a dozen of lines I put it in a script. There is really nothing to restrict you from doing something that ...


Try: alias sbb='sudo $(fc -ln -1)' I like actually prefer to name it 'please': alias please='sudo $(fc -ln -1)' Info: fc is a in-built command in the bash shell. that lists, edits and reexecutes commands previously entered to an interactive shell.


ls () { case "$PWD" in /) command ls -I test "$@" ;; *) command ls "$@" ;; esac } The above shell function will test the current directory against / and executes the GNU ls command differently according to the outcome of the test. "$@" will be replaced by the command line options and operands on the original command line. We need to use ...


I see the below information from here. When using sudo, use alias expansion (otherwise sudo ignores your aliases) alias sudo='sudo ' The reason why it doesn't work is explained here. Bash only checks the first word of a command for an alias, any words after that are not checked. That means in a command like sudo ll, only the first word (sudo) is ...


Have a look at lnav, the advanced log file viewer. It can also pretty print various formats. Before: After:


You can use a backslash: % alias ls ls -a % ls # ls -a output here % \ls # plain ls output here For shell builtins, there turns out to be a gotcha: a leading backslash prevents both aliases and builtins from being used, but an internal backslash suppresses aliasing only. % alias cd pushd % cd /tmp /tmp /tmp % c\d % dirs ~ /tmp (I'm tempted to call that ...


Not a direct answer to your question (since aliases can only be one word), but you should be using git-config instead: git config --global alias.civ commit -v This creates a git alias so that git civ runs git commit -v. Unfortunately, AFAIK there is no way to override existing git commands with aliases. However, you can always pick a suitable alias name ...


You could just exec zsh, which will give you a fresh zsh and re-run the init functions. Note that you'd need to exec zsh -l for a login zsh to keep its "login shell" status. I don't know how well it preserves command history (it seems to work for me, but if you use multiple shells in different terminals you might get 'crosstalk' between the two shells' ...


I would look in /etc/profile.d/ for the offending alias. You could also do the following to find it: grep -r '^alias COMMAND' /etc This will recursively grep through files looking for a line beginning with alias COMMAND. If all else fails, put this at the end of your ~/.bashrc unalias COMMAND


One difference between the two is that aliases are only a shell feature. Environment variables are inherited by all subprocesses (unless deliberately cleared). The environment variable would be more likely to work even if less is launched indirectly, such as via another shell (e.g. tcsh), man, vim, psql, etc.

Only top voted, non community-wiki answers of a minimum length are eligible