Tag Info

Hot answers tagged

68

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.


63

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


52

There are lot of ways to create alias . The most used ways are : 1) . 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 when you type rm the rm -i command will be executed. 2). The second method lets you make a separate aliases file, so you won't have to put them ...


51

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


37

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


31

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


26

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.


26

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


23

The command to remove an alias is unalias so.... unalias -a 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 ...


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


17

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


16

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


16

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


16

Alias are deprecated in favor of shell functions. From 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 your ...


15

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


15

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


14

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


11

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 }


11

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

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


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.


10

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


9

Here are some that I like: #Opens current directory in a file explorer alias explore='nautilus .' #Opens current directory in a file explorer with super user privileges alias suexplore='sudo nautilus .' #Opens current directory in Ubuntu's Disk Usage Analyzer GUI with super user privileges in the background alias analyze='gksudo baobab . &' #Opens a ...


9

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.


8

aliases do not support the positional parameters so you need to create a function (in ~/.profile) and alias that function. function grepMe(){ grep "$1" ~/myfile } and then alias it.. alias grepAlias="grepMe"


8

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


8

With the first method you are not creating an alias, you are creating a symlink. Symlinks are short for symbolic links: Symbolic links are files that act as pointers to other files. [...] A symbolic link is a special type of file whose contents are a string that is the pathname another file, the file to which the link refers. In other ...


8

You can set this option in one f the mplayer option files, this will then be the default behaviour. For system wide change /etc/mplayer/mpplayer.conf of just for that user create ~/.mplayer/mplayer.conf and put it in there. Adding this to ~/.mplayer/mplayer.conf works: msglevel=all=0


8

Actually both ls and l are equal raja@badfox:~/Pictures$ l des.png Screenshot from 2012-09-22 19:37:03.png Screenshot from 2012-09-22 19:37:11.png Screenshot from 2012-09-22 19:37:12.png Untitled.png raja@badfox:~/Pictures$ ls des.png Screenshot from 2012-09-22 19:37:03.png Screenshot from 2012-09-22 19:37:11.png Screenshot from 2012-09-22 19:37:12.png ...


7

Create a file called something like runthisstuff In this file, stick a bunch of commands: alias doc='cd ~/Documents/' alias ps='ps aux' date Now run the file like so: $ source runthisstuff It will print the date, and you can now use the aliases. The date command is just to show you that you can pretty much stick anything you want in there, and it will ...



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