11

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
  • 116,445
  • 54
  • 318
  • 493

3 Answers3

12

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?

dessert
  • 39,392
  • 12
  • 115
  • 163
  • 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`](http://manpages.ubuntu.com/manpages/disco/en/man1/dash.1.html) for details. – Eliah Kagan Nov 23 '19 at 11:05
  • @EliahKagan Please feel free to edit and correct me there! – dessert Nov 24 '19 at 10:14
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"
Kulfy
  • 17,416
  • 26
  • 64
  • 103
n4t5ru
  • 31
  • 1
-1

I ran into the same question on Manjaro Linux, which uses Zsh by default, but I couldn't find any alias defined in the usual spots (e.g. /etc/profile, /etc/zsh/zprofile, grep -rin alias /etc/*, ~/.zshrc, etc.... )

It turns out that Manjaro had installed oh-my-zsh under a system-level location: /usr/share/oh-my-zsh/

Thanks to this answer, I was able to track it down:

zsh -ixc : 2>&1 | grep 'll='

First line shown in the trace output found it:

+/usr/share/oh-my-zsh//lib/directories.zsh:37> alias 'll=ls -lh'
TrinitronX
  • 3,204
  • 3
  • 22
  • 23
  • It seems [this file is not packaged for Ubuntu](https://packages.ubuntu.com/search?suite=jammy&arch=any&mode=exactfilename&searchon=contents&keywords=directories.zsh), so this answer doesn't apply to Ubuntu. – muru Jun 23 '23 at 15:43
  • Yeah, that's fair. Yet this is among the first search engine results for the general question, so I figured I would leave an answer here anyway for others (and myself when I forget in the future) – TrinitronX Aug 03 '23 at 21:38
  • You can ask and answer on [unix.se] instead. – muru Aug 04 '23 at 00:19