How to find aliases?

43,539

Solution 1

List of defined aliases

Type alias, you'll get a list of all defined ones in your environment.

$ alias
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

List along the file they've been set in

To find the files that your aliases have been defined in, use this solution, with a little bit altering it:

$ PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7> /tmp/mylog
$ grep "alias " /tmp/mylog | grep -e /home -e /etc

Which gives you a list of files, stating what alias defined there, the output is similar to:

++/home/ravexina/.bashrc> alias 'la=ls -A'

Which states 'la=ls -A' has been set in my .bashrc.


Important files

There are many places that we can define our aliases, the most important ones might be:

  • Standard ones:
    • ~/.bashrc
    • ~/.bash_aliases
  • One of them in order:
    • ~/.bash_profile
    • ~/.bash_login
    • ~/.profile
  • Works but not a good place, unless you want it system wide:
    • /etc/bash.bashrc
    • /etc/profile

And any other place which get sourced while running a shell.

Solution 2

Aliases are defined on a per-user, per-shell basis. You can see what aliases are defined for your current shells via

alias

Read more about aliases in man bash.

Solution 3

I might also throw in that the .bashrc for new users (not existing) is populated from /etc/skel/.bashrc, inside which you'll find aliases for things like ll, la, l, etc. So if you want every new user to have more/less/different aliases that's the place to modify them

Share:
43,539

Related videos on Youtube

glc78
Author by

glc78

New in informatic things. Interested in networking. Out of time, not so clever.

Updated on September 18, 2022

Comments

  • glc78
    glc78 over 1 year

    Where can I find a list/file of all aliases created in Ubuntu 17.04? I mean shortcuts for commands most frequently used and more.

  • glc78
    glc78 almost 7 years
    Witch one of the 'important files' is the best one to add a function instead of an alias? If there is one.
  • Ravexina
    Ravexina almost 7 years
    That would be ~/.bashrc, However what I suggest is to create a new file: ~/.bash_functions and put all functions there, then source that file in your .bashrc like: . ~/.bash_functions.
  • glc78
    glc78 almost 7 years
    Before your answer I just created the file .bash_profile and added to .bashrc. I'm going to rename the file as suggested.
  • Ravexina
    Ravexina almost 7 years
    Remember if you use a file named .bash_profile then your .profile will not going to be sourced any more... ;)
  • glc78
    glc78 almost 7 years
    I didn't know. I'm using ~/.bash_functions now.
  • Ravexina
    Ravexina almost 7 years
    You're fine... ;)