Hot answers tagged

171

The type builtin is useful for this. It will not only tell you about aliases, but also functions, builtins, keywords and external commands. $ type ls ls is aliased to `ls --color=auto' $ type rm rm is /bin/rm $ type cd cd is a shell builtin $ type psgrep psgrep is a function psgrep () { ps -ef | { read -r; echo "$REPLY"; grep -...


161

To create an alias permanently add the alias to your .bashrc file gedit ~/.bashrc And then add your alias at the bottom. Now execute . ~/.bashrc in your terminal (there should be a gap between the . and ~/.bashrc. Now you can check your alias.


121

Add the following line to your ~/.bashrc: alias sudo='sudo ' From the bash manual: Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands. The first word of each simple command, if ...


100

There are lot of ways to create alias. The most used ways are : Add aliases directly in your ~/.bashrc file For example : append these line to ~/.bashrc file alias ll='ls -l' alias rm='rm -i' Next time (after you have logged out/in, or done . ~/.bashrc) when you type rm the rm -i command will be executed. The second method lets you make a separate ...


72

The command to remove an alias is unalias so.... unalias gs Manual: NAME unalias - remove alias definitions SYNOPSIS unalias alias-name... unalias -a DESCRIPTION The unalias utility shall remove the definition for each alias name specified. See Alias Substitution . The aliases shall be removed from the current ...


58

Just type alias while at the Shell prompt. It should output a list of all currently-active aliases. Or, you can type alias [command] to see what a specific alias is aliased to, as an example, if you wanted to find out what the ls alias was aliased to, you could do alias ls.


44

You can bypass aliases by the following methods: the full pathname of the command: /bin/ls command substitution: $(which ls) the command builtin: command ls double quotation marks: "ls" single quotation marks: 'ls' a backslash character: \ls


37

In Ubuntu, the default .bashrc skeleton file looks for a .bash_aliases file in your home directory when you log in and sources it. So if you just create a .bash_aliases file and put any aliases you want in it, it should be sourced automatically when you open a new bash shell (no need to log out of desktop and back in, just open a new terminal). Here's the ...


36

Sure, although I have never tried it as an alias but it should work: sudo apt-get update && sudo apt-get -y upgrade


33

From Bash Tips and Tricks: 'cd' with style: Finally, I want to show you how to write your own custom replacement for the 'cd' command. Do you find yourself always typing the same thing upon changing into a directory? You probably at least list the files there every time, perhaps so much that your hands automatically type 'ls' after every 'cd'. ...


31

In your shell script use the full path rather then an alias. In your shell script, set a variable, different syntax petsc='/home/your_user/petsc-3.2-p6/petsc-arch/bin/mpiexec` $petsc myexecutable Use a function in your script. Probably better if petsc is complex function petsc () { command 1 command 2 } petsc myexecutable Source your aliases ...


27

I really like Ctrl+Alt+E as I learned from this answer. It "expands" the currently typed command line, meaning it performs alias expansion (amongst other things). What does that mean? It turns any alias, that might be currently written on the command line, into what the alias stands for. For example, if I type: $ ls and then press Ctrl+Alt+E, it is ...


25

Aliases are deprecated in favor of shell functions. From the bash manual page: For almost every purpose, aliases are superseded by shell functions. To create a function, and export it to subshells, put the following in your ~/.bashrc: petsc() { ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@" } export -f petsc Then you can freely call your command from ...


23

There is no way you can prevent a user from defining whatever aliases they prefer. Consider: You disable aliases in /etc/bash.bashrc. They enable it wherever they chose to. You delete all mentions of aliases in /etc/bash.bashrc, and all ~/.bashrc and ~/.bash_aliases via a script. They put their aliases in another file and source it. You run a command in ...


20

If you want to check something in bash, use type and man. In your case you want to know what is . $ type . . is a shell builtin shell builtin means that . is inside bash shell. You can find information about shell builtins in bash manual page. There is a big section SHELL BUILTIN COMMANDS $ man bash SHELL BUILTIN COMMANDS Unless otherwise noted,...


19

You can use the builtin command in bash : function cd() { new_directory="$*"; if [ $# -eq 0 ]; then new_directory=${HOME}; fi; builtin cd "${new_directory}" && ls }


19

You have a space between the = and the opening '. Remove it. $ alias foo= 'bar baz' bash: alias: bar baz: not found


18

With most commands, you can pass -- as an argument, and all subsequent arguments are treated as operands and not options, even if they begin with a dash. The alias builtin in bash recognizes --. alias -- -='cd -'


17

While the other answers offer a good workaround for your problem, to answer your question, the right way to use an alias inside a .desktop file is, in your case: Exec=bash -ic "midos" That's because aliases from ~/.bashrc file will work only in a bash interactive shell (-i option is used in this case to start bash interactive). If another user wants to ...


16

Use a function instead of an alias: cs() { cd "$1" && ls; }


16

alias new_name='old command' For creating a permanent alias you've to edit the .bashrc file in youre home dir. More info here More .bashrc files here


16

Instead of using grep, you can just type alias aliasname to see what an alias is set to. For example, alias ls will return ls='ls --color=auto'. Also take a look at the type and whence commands, which return more detailed information about utilities, including executable files in your path, shell built-ins, aliases, and shell functions.


13

l is an alias for ls -CF, which behaves differently from plain ls. -C -C makes ls print output in column form. When stdout is a terminal (rather than being redirected to a file or non-terminal device, or piped to another command), -C is implied. So running ls -C is the same as running ls. But they are not equivalent when ls is redirected or piped. For ...


13

Run the command with a leading \, an answer in examples: ;) % ls bar foo % alias ls="ls -laog" % ls total 4292 drwxrwxr-x 4 4329472 Nov 5 15:06 . drwx------ 95 28672 Nov 5 15:15 .. -rw-rw-r-- 1 0 Nov 5 15:06 bar drwxrwxr-x 2 4096 Nov 5 15:06 foo drwxrwxr-x 2 4096 Okt 2 14:29 .foo -rw-rw-r-- 1 191 Feb 25 2015 .htaccess % \ls ...


12

You can't use slashes in an alias name. Bash allows them in function names, however, so you can make that a function: cd../.. () { cd ../..; } You can't use backslashes in an alias or function name. The backslash character quotes the next character, so cd..\.. is parsed as cd...., well before that string is looked up as a command name. If you want to call ...


11

The problem is that you are trying to execute a non executable file: You can check this with: ls -la ~/.bashrc -rw-r--r-- 1 username username 3596 2010-08-05 17:17 /home/pt001424/.bashrc Note there is no "x - executable" letter on the first column (file permissions). Profile files are not executable files, instead of executing them you load them with: ...


11

Use single quotes ' around the argument. (This works for any command, not just cd). cd 'My path with spaces (and parentheses)' You can't make bash pass the parentheses to cd. Getting the spaces to work at all is a very specialized hack. Single quotes work around every character except ' itself. Replace single quotes by the 4-character sequence '\''. cd '...


11

DON'T CD, just run it using its absolute path This version: cd /home/path_to_x && ./x changes directory to an absolute path (you see how /home/... starts at the root directory) and then runs the executable at the relative path ./x (that is, relative to the new working directory). This version: ./home/path_to_x/x tries to run the executable at ...


11

You can create a script in /etc/profile.d/ to make aliases for all users: Create a file called 00-aliases.sh (or any other fancy name) in /etc/profile.d: gksu gedit /etc/profile.d/00-aliases.sh Put you aliases in this file. Example: alias foo='bar --baz' alias baz='foo --bar' Save the file Restart any open terminals to apply the changes. Enjoy! ...


10

You can do it, but only if your directory names don't contain several consecutive spaces, and only if they contain no shell special character other than spaces. cd () { builtin cd "$*"; } In practice, use completion: type cd My then press Tab. Bash will insert backslashes before special characters.



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