Where is the alias for "ll" defined?

10,881

Solution 1

In Ubuntu, this alias is defined by default in the ~/.bashrc file, in mine like this:

$ grep "alias ll" ~/.bashrc
alias ll='ls -alF'

Another file read by default is the ~/.bash_aliases. It may not exist until you create it, but it's the recommended way of storing aliases as keeping them in a separate file provides clarity. Your ~/.bashrc contains the following section, the if expression in which loads this aliases file if it exists:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

As for zsh I suppose the alias is defined in the same manner in your ~/.zshrc file or any file sourced by it. If you use oh-my-zsh it may be contained in lib/directories.zsh or plugins/common-aliases/common-aliases.plugin.zsh.

sh (= dash in Ubuntu) reads only ~/.profile, which normally doesn't contain any aliases as they are defined shell-specific. In the case of an alias as simple as alias ll='ls -lh' however you could go for a definition in ~/.profile. Further reading: Is there a “.bashrc” equivalent file read by all shells?

Solution 2

For zsh, aliases can be added in .zshrc. ll must have been defined in that file.

You can add an alias in .zshrc by editing it with any file editor such as nano. For example:

alias ll="ls -lh"
Share:
10,881
Eliah Kagan
Author by

Eliah Kagan

Updated on September 18, 2022

Comments

  • Eliah Kagan
    Eliah Kagan over 1 year

    I often find myself using ll which is an alias.

    $ type ll
    ll is an alias for ls -lh
    

    I always wondered where this was defined as it works both on bash, zsh but not on sh:

    # THIS IS SH
    $ ll
    sh: 1: ll: not found
    
  • Eliah Kagan
    Eliah Kagan over 4 years
    Most people don't use dash much as an interactive shell. But if one does, and wishes to define aliases in dash, their definitions should not go in ~/.profile. Like bash and other POSIX-compatible shells, dash sources ~/.profile only when run as a login shell--and aliases are not inherited. When an ENV environment variable is set, all interactive dash shells source the file named in it. Such a file is a good place for aliases. (Setting and exporting ENV can be done in ~/.profile.) See man dash for details.
  • dessert
    dessert over 4 years
    @EliahKagan Please feel free to edit and correct me there!
  • Aindriú
    Aindriú over 3 years
    If you use the above you can run the following after to make changes take effect : source ~/.zshrc