43

How to list available shells for use by command-line?

Pandya
  • 23,898
  • 29
  • 92
  • 144

4 Answers4

62

To list available valid login shells for use at time, type following command:

cat /etc/shells

Example:

pandya@pandya-desktop:~$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/ksh93

For information about shell visit wikipedia.

Pandya
  • 23,898
  • 29
  • 92
  • 144
  • Note that this will not work for all systems. E.g. Solaris and HP-UX do not have an /etc/shells file by default. – Warwick Jul 02 '14 at 05:25
  • Why do I have `/bin/true` and `/bin/false` in this list? – Bernhard Jul 02 '14 at 05:33
  • 2
    @bernhard - There is a good explanation of /bin/true and /bin/false here [link](http://serverfault.com/questions/519215/what-is-the-difference-between-sbin-nologin-and-bin-false) – Warwick Jul 02 '14 at 05:47
9

You can also use chsh -l This will print the list of shells.

Example :-

[anurag@focused ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
Anurag Anand
  • 191
  • 1
  • 3
  • 4
    For me, `chsh: invalid option -- 'l'` – Pandya Jun 08 '16 at 15:46
  • @Pandya can you provide the complete command you are using. You might be using it with combination of other shell methods or constructs like ((...)) or [...] or [[...]] – Anurag Anand Jun 09 '16 at 10:59
  • http://pastebin.com/rGipgDg4 – Pandya Jun 09 '16 at 11:58
  • Probably I've http://man7.org/linux/man-pages/man1/chsh.1@@shadow-utils.html – Pandya Jun 09 '16 at 12:00
  • @Pandya http://man7.org/linux/man-pages/man1/chsh.1.html This provides -l option. Just click on the link on the top of the page, to go to linux-util man page – Anurag Anand Jun 09 '16 at 13:01
  • @Pandya You can run your the command here and verify. http://www.tutorialspoint.com/execute_bash_online.php – Anurag Anand Jun 09 '16 at 13:03
  • `shadow-utils 4.1.5.1` provides `chsh` in my case that's why I am getting [that](http://unix.stackexchange.com/questions/140286/how-to-find-list-of-available-shells-by-command-line/288394?noredirect=1#comment504359_288394) error. +1 for correct answer – Pandya Jun 09 '16 at 13:51
  • @Pandya Thnx :) – Anurag Anand Jun 10 '16 at 07:00
  • `chsh: invalid option -- 'l'`, `which chsh` gives `/usr/bin/chsh`, `dpkg -S /usr/bin/chsh` gives `passwd: /usr/bin/chsh`, `dpkg-query -l passwd` gives: passwd version 1:4.1.5.1-1. – Progrock Jul 26 '16 at 03:07
2

On at least OpenBSD and NetBSD:

$ getent shells

On (Ubuntu) Linux and many other Unices (including BSDs):

$ grep '^[^#]' /etc/shells

On Solaris, the file /etc/shells may not exist. The list of valid shells is contained in the shells(4) manual. On my vanilla Solaris 11.3 system, this lists the following shells:

/bin/bash         /usr/bin/bash     /bin/pfbash   /usr/bin/pfbash
/bin/csh          /usr/bin/csh      /bin/pfcsh    /usr/bin/pfcsh
/bin/jsh          /usr/bin/jsh      /sbin/jsh     /usr/sbin/jsh
/bin/ksh          /usr/bin/ksh      /bin/pfksh    /usr/bin/pfksh
/bin/ksh93        /usr/bin/ksh93    /bin/pfksh93  /usr/bin/pfksh93
/bin/sh           /usr/bin/sh       /bin/pfsh     /usr/bin/pfsh
/bin/tcsh         /usr/bin/tcsh     /bin/pftcsh   /usr/bin/pftcsh
/sbin/sh          /usr/xpg4/bin/sh  /sbin/pfsh    /usr/xp4/bin/pfsh
/bin/zsh          /usr/bin/zsh      /bin/pfzsh    /usr/bin/pfzsh
/usr/sfw/bin/zsh

It's worth noting that on my installation, neither /usr/sfw/bin/zsh nor /usr/xp4/bin/pfsh exists...

A shorter list of valid Solaris shells (duplicates of each shell removed):

/bin/bash       /bin/ksh        /bin/pfcsh      /bin/pfsh       /bin/sh
/bin/csh        /bin/ksh93      /bin/pfksh      /bin/pftcsh     /bin/tcsh
/bin/jsh        /bin/pfbash     /bin/pfksh93    /bin/pfzsh      /bin/zsh
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
0

If you want to dig into /etc/passwd, you could do:

cut -d ':' -f 7 /etc/passwd | sort -u

H/T @schrodigerscatcuriosity in https://unix.stackexchange.com/a/631346/40454

Brian Peterson
  • 619
  • 1
  • 7
  • 12