Hot answers tagged

85 votes

How to pass parameters to an alias?

Alias solution If you're really against using a function per se, you can use: $ alias wrap_args='f(){ echo before "$@" after; unset -f f; }; f' $ wrap_args x y z before x y z after You can replace ...
user avatar
  • 25.4k
81 votes

How do I get bash completion for command aliases?

Try complete-alias, which solves this problem exactly. (Disclaimer: I am the author of complete_alias) After install it you can use one generic function to complete many aliases like this: complete -...
user avatar
  • 3,862
57 votes

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

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 ...
user avatar
  • 671
54 votes
Accepted

Why does sudo ignore aliases?

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 ...
user avatar
  • 36.9k
53 votes

How can I `alias sudo !!`?

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 ...
user avatar
  • 631
52 votes
Accepted

Would globally aliasing the fork bomb prevent its execution?

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 ...
user avatar
  • 119k
46 votes

How to have tail -f show colored output

Have a look at lnav, the advanced log file viewer. It can also pretty print various formats. Before: After:
user avatar
  • 561
38 votes

Alias to CD in a directory and call a command

To execute a command with a specific working directory, one usually does ( cd directory && utility ) The parentheses around the cd ... means that the command(s) therein runs in a subshell. ...
user avatar
  • 275k
38 votes
Accepted

Are there any single character bash aliases to be avoided?

Things to avoid: standard or common commands with single character names: w (show logged in users' activity), X (X Window System server), R (R programming language interpreter), [ (similar to test) ...
user avatar
36 votes
Accepted

Alias and functions

Aliases are expanded when a function definition is read, not when the function is executed … $ echo "The quick brown fox jumps over the lazy dog." > myfile   $ alias myalias=cat   $ myfunc() { >...
user avatar
34 votes

Only if in "/" : alias ls='ls -I test'?

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 ...
user avatar
  • 275k
30 votes
Accepted

how to find file defining an alias

zsh -x 2>zsh.trace exit grep 'alias.*subl' zsh.trace The -x option causes zsh to print out every command that it executes on stderr. Any command that was executed from reading a file has a prefix ...
user avatar
26 votes

Fish-Shell Will Not Save my Aliases

A fish alias is actually implemented as a function. To save a function, you need funcsave. So this is the sequence alias foo=bar funcsave foo That creates ~/.config/fish/functions/foo.fish which will ...
user avatar
24 votes

Making alias of rm command

An alias can not take arguments and use $@ to access them like that. Alias expansion in bash is a simple text replacement. If you have alias rm ='something something', then using rm file1 file2 would ...
user avatar
  • 275k
23 votes

Have xargs use alias instead of binary

Use alias xargs='xargs ' alias: alias [-p] [name[=value] ... ] (snip) A trailing space in VALUE causes the next word to be checked for alias substitution when the alias is expanded.
user avatar
  • 1,091
23 votes
Accepted

How to escape single quotes correctly creating an alias

To make this an alias, which is possible, you need to use double quotes around the entire value for the alias. You'll also need to escape a few things within the alias as a result, and you need to ...
user avatar
  • 348k
23 votes
Accepted

How to stop .bashrc from running sub-command in alias at startup?

Use pkill instead: alias killguake='pkill guake' This is a whole lot safer than trying to parse the process table outputted by ps. Having said that, I will now explain why your alias doesn't do ...
user avatar
  • 275k
23 votes
Accepted

-bash: /bin/cd: No such file or directory - automatically execute ls after cd

Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An ...
user avatar
  • 275k
22 votes

Only if in "/" : alias ls='ls -I test'?

Use a function that tests if you're in / for ls: ls () { if [[ "$PWD" == / ]] then command ls -I test "$@" else command ls "$@" fi } This way, any arguments you pass ...
user avatar
  • 64.8k
22 votes
Accepted

How to make a multiline alias in Bash?

It's not impossible at all. alias thing='( cd "${program_to_update_dir}" wget "https://raw.githubusercontent.com/USER/PROJECT/BRANCH/update.sh" source update.sh rm update.sh )' or,...
user avatar
  • 275k
21 votes

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

To source a file if it exists in one line: [ -f .aliases ] && source .aliases
user avatar
21 votes
Accepted

How do you make an alias or function that retains tab completion?

First find out which complete-function is used for the systemctl command: complete | grep " systemctl$" The output looks like this: complete -F _functionname systemctl Then use: complete -F ...
user avatar
  • 45.7k
21 votes
Accepted

Trying to use `pwd` inside an alias giving unexpected results

Use single quotes to avoid shell expansion at time of definition alias search='find `pwd` -name '
user avatar
  • 2,819
20 votes

How to reset a shell environment?

To undo exported environment variables, you can use the env command env -i zsh. env runs the command given as an argument, and -i gives it a clean environment. Depending on your configuration, you ...
user avatar
  • 1,467
20 votes
Accepted

why strace ignores my alias for rm?

strace doesn't run rm -i for the same reason as: echo rm doesn't output rm -i. Aliases are a feature of a few shells to allow some strings to automatically be replaced by another when found in ...
user avatar
20 votes
Accepted

why doesn't gdb like aliases

Aliases are a feature of the shell. Defining an alias creates a new shell command name. It's recognized only by the shell, and only when it appears as a command name. For example, if you type > ...
user avatar
20 votes

Are there any single character bash aliases to be avoided?

The simplest way is probably to check whether something with that name already exists. On my system: $ for char in {A..z}; do type "$char" 2>/dev/null; done R is /usr/bin/R X is /usr/bin/...
user avatar
  • 47.3k
19 votes

in Bash, how to not include extra arguments in an alias?

When you define an alias, the command you set is run instead of the one you wrote. This means that when you run ftp abc.com, what is actually executed is echo do not use ftp. Use sftp instead abc.com ...
user avatar
  • 219k
19 votes
Accepted

nohup: failed to run command `.': Permission denied

nohup runs an executable. You need to pass it an external command, i.e. an executable file. You can't call nohup on a shell construct such as an alias, function or builtin. nohup runs a new process, ...
user avatar

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