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 ...


Try out multitail. This is an ├╝bergeneralization of tail -f. You can watch multiple files in separate windows, highlight lines based on their content, and more. multitail -c /path/to/log The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log ...


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.


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 ...


First of all, as ddeimeke said, aliases by default are not expanded in non-interactive shells. Second, .bashrc is not read by non-interactive shells unless you set the BASH_ENV environment variable. But most importantly: don't do that! Please? One day you will move that script somewhere where the necessary aliases are not set and it will break again. ...


grc, the generic colouriser is pretty cool Just do grc tail -f /var/log/apache2/error.log and enjoy


If you look into the bash manpage you find: Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below). So put a shopt -s expand_aliases in your script. Make sure to source your aliases file after setting this ...


A good way to inspect what a command is: type l If it's a program or a script, it will give you its location, if it is an alias, it will tell you what it's aliased to, if it's a function, it will print the funciton; otherwise, it will tell you if it is a built-in or a keyword. Examples: $ type l l is aliased to `ls -CF' $ type find find is /usr/bin/find ...


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 ...


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


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.


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


!! 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 !!)"'


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


The main difference between aliases and functions is that aliases don't take arguments┬╣, but functions do. When you write something like alias l='ls --color', l foo is expanded to ls --color foo; you can't grab foo into the alias expansion and do something different with it the way you can do with a function. See also How to pass parameter to alias?. ...


There's no rc file for grep, but you can set the environment variable GREP_OPTIONS to a whitespace-separated list of options that will apply to all grep commands. This requires GNU grep (the implementation on non-embedded Linux, Cygwin and some other systems) 2.4; the --exclude option is new to GNU grep 2.5. Put something like this in your ~/.profile: ...


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 ~...


Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c or directly in your configuration file. If your screen is clearing after colorizing you must use option -A. Edit: If you really would like to have the complete line colored in red, you could also have a try at the following: $ tail -...


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's installed system-wide, but included on a per-user basis ...


Personally, I have these in my bashrc and use them all the time: pushd() { if [ $# -eq 0 ]; then DIR="${HOME}" else DIR="$1" fi builtin pushd "${DIR}" > /dev/null echo -n "DIRSTACK: " dirs } pushd_builtin() { builtin pushd > /dev/null echo -n "DIRSTACK: " dirs } popd() { builtin popd > /dev/null echo -n "DIRSTACK: " ...


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 ...


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 ...


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


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.


In bash there is also autocd option. You can enable it by using shopt -s autocd: pbm@tauri ~ $ shopt -s autocd pbm@tauri ~ $ django # Now just type this cd ./django <- it's done automatically pbm@tauri ~/django $


Aliases are like commands in that all arguments to them are passed as arguments to the program they alias. For instance, if you were to alias ls to ls -la, then typing ls foo bar would really execute ls -la foo bar on the command line. If you want to have actual control over how the arguments are interpreted, then you could write a function like so: ...


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 ...


You can use the alias command. $ alias ll ll='ls --color=auto -Flh'

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