7

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.

7

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.

  • Witch one of the 'important files' is the best one to add a function instead of an alias? If there is one. – glc78 Aug 12 '17 at 13:36
  • 1
    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. – Ravexina Aug 12 '17 at 13:58
  • Before your answer I just created the file .bash_profile and added to .bashrc. I'm going to rename the file as suggested. – glc78 Aug 12 '17 at 15:18
  • 1
    Remember if you use a file named .bash_profile then your .profile will not going to be sourced any more... ;) – Ravexina Aug 12 '17 at 19:42
  • I didn't know. I'm using ~/.bash_functions now. – glc78 Aug 13 '17 at 9:45
3

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.