Skip to main content
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 ...
ilkkachu's user avatar
  • 148k
40 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) ...
Stéphane Chazelas's user avatar
38 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,...
Kusalananda's user avatar
  • 356k
29 votes
Accepted

How to create an environment variable that is the output of a command

In general the sequence foo="$(bar)" will run the command bar and assign the output to the variable. e.g. % echo $PWD /home/sweh % BWD="$(basename "$PWD")" % echo $BWD sweh This creates a shell ...
Stephen Harris's user avatar
28 votes
Accepted

How to make `python` an alias of `python3` systemwide on Debian

It looks like Debian is now shipping python-is-python3 themselves (in Debian 11 and later), so the premise of the question no longer holds and you can just: sudo apt update && sudo apt install ...
a3nm's user avatar
  • 9,587
27 votes
Accepted

How can I alias `...` to `../..` in Bash?

If switching to zsh is an option, you could use global aliases there for that: alias -g ...=../.. But in any case that's only expanded when ... is recognised as a full delimited token on its own. It ...
Stéphane Chazelas's 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 ...
Kusalananda's user avatar
  • 356k
23 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, ...
Gilles 'SO- stop being evil''s user avatar
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 ...
Kusalananda's user avatar
  • 356k
22 votes

How do I get bash completion for command aliases?

By googling this issue, I ended up here, so I tried the approaches in the other answers. For various reasons I don't actually understand, they never behaved properly in my Ubuntu 16.04. What in the ...
M.Ermatinger's user avatar
22 votes
Accepted

bash aliases do not expand even with shopt expand_aliases

It doesn't seem work if you set the alias on the same line as it's used. Probably something to do with how aliases are expanded really early in the command line processing, before the actual parsing ...
ilkkachu's user avatar
  • 148k
22 votes
Accepted

Multi-word aliases in bash

Well, I get: $ alias 'apt update'='sudo apt update -y' bash: alias: 'apt update': invalid alias name which seems clear enough. Similarly, you can't have functions or commands with whitespace in their ...
ilkkachu's user avatar
  • 148k
21 votes

Why doesn't my Bash script recognize aliases?

You can also use . before your script. Run it as: . /path/to/your/script.sh You can check for this condition on your bash script as follows: if [[ $- == *i* ]] then echo "running on ...
Tono Nam's user avatar
  • 338
21 votes
Accepted

Multiples aliases for one command

You could use brace expansion. alias {name1,name2}="echo hello" or for your example alias lw{p,b}c="$(npm bin)/webpack" https://www.gnu.org/software/bash/manual/html_node/Brace-...
gnarlyninja's user avatar
21 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/...
l0b0's user avatar
  • 53.6k
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 > ...
Keith Thompson's user avatar
20 votes
Accepted

Bash shadow a command - function with same name as command

Any character in front of an alias will prevent the alias from triggering: alias ls='ls -la' ls foo.txt #will run ls -la foo.txt \ls foo.txt #will run ls foo.txt 'ls' foo.txt #will run ls foo....
jeremysprofile's user avatar
20 votes
Accepted

How to overwrite aliases in my shell (Oh My Zsh)?

The alias command overrides a previous alias by the same name. So generally, if you want your aliases to override the ones defined by a zsh framework, put them at the end of your .zshrc. The same goes ...
Gilles 'SO- stop being evil''s user avatar
19 votes

How to create alias for ssh command?

I usually use the .ssh/config file found in my home directory to run my OpenSSH client in the format ssh ubserver. In that file found here /home/$USER/.ssh I have the follow configurations: Host ...
George Udosen's user avatar
18 votes

How to create alias with a command contains ' and "

Saying that the syntax of an alias is alias aliasname='command' is a bit misleading, as it seems to imply that the single quotes are part of the syntax. They are not. The part after the equal sign is ...
ilkkachu's user avatar
  • 148k
18 votes

How to create an environment variable that is the output of a command

In Bourne-like shells, you create environment variables by marking a shell variable with the export attribute (so it's exported to the environment of the commands that the shell will execute) by using ...
Stéphane Chazelas's user avatar
18 votes

bash aliases do not expand even with shopt expand_aliases

Turning my comment into an answer, as suggested by ilkkachu. The Bash manual (linked to in the question) does provide an explanation of how the aliases are handled when there is an alias definition ...
Haxiel's user avatar
  • 8,719
18 votes
Accepted

How to use aliases with `watch` command?

aliases are enabled in interactive shells, so try this: watch -x bash -ic "my-alias" # .............^
glenn jackman's user avatar
17 votes

watch command alias expansion

Maybe we could manually expand the alias before watch sees it? watch $(alias ll | cut -d\' -f2) Explanation The output of alias ll looks like: $ alias ll alias ll='ls -lAGh' So we set cut's ...
Jonathan Hartley's user avatar
17 votes

How to turn globbing on and off?

If you want globs to be disabled only while the shell is interpreting code in any.sh, with bash4.4+ or ash-based shells, you can do: x() { local - set -o noglob . any.sh } Or in zsh: x() { ...
Stéphane Chazelas's user avatar
17 votes
Accepted

Where is the script for alias command in Linux?

alias is a builtin command, so it doesn't show up as script in any file, or as a function. The type command will show this: $ type alias alias is a shell builtin But you can still override it. A ...
ilkkachu's user avatar
  • 148k
17 votes

Would globally aliasing the fork bomb prevent its execution?

No. There are just too many ways to write a fork-bomb. The evil fork-bomb writer will just try again with a different function name. Or other alterations until his fork-bomb succeeds. The ...
cmaster - reinstate monica's user avatar
17 votes

Are there any single character bash aliases to be avoided?

Addressing: "I'm curious if this should be avoided." As described in the other answers, there should be no technical problem as long as the command you are overriding with the alias it isn't ...
WaterMolecule's user avatar
16 votes

How can I test if a particular alias is defined?

I’m gonna make @jimmij’s comment from 5 years ago into an answer: type -t is designed for exactly that purpose. It will output alias if the given command is an alias. If the command does not exist, it ...
scy won't contribute anymore's user avatar

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