- 4 Ways to Check Which Shell You are Using on Linux
- 1) Using echo command
- 2) Using ps command
- 3) By viewing /etc/passwd file
- 4) Using lsof command
- How to check the valid login shells
- Conclusion
- How do I find out what shell I am using on Linux/Unix?
- How can I find out what shell I am using?
- How do I check which shell am I using?
- How do I check how many shells are installed on my Linux box?
- Okay, so when I open the Terminal app, which shell is opened by default?
- How to check which shell am I using:
- Conclusion
- Linux Shell Commands
- The Shell
- Shell Commands
- Logging out
- Files and Directories
- File Editors
- Manipulating data
- Compressed files
- Information
- Status
- Printing
- Messages between Users
- Networking
- Programming
- Text Processing
- Word Processing
- Database Management
4 Ways to Check Which Shell You are Using on Linux
Out of the box, Linux provides a wide variety of shells. There is bash (Bourne Again shell) shell which ships by default in many Linux distributions. We also have sh (Bourne Shell), tcsh (TC shell), csh (C shell), Zsh (Z shell) and ksh (Korn Shell).
Curious to know which shell you are using on your Linux system? In this guide, we explore different ways that you can use to check which shell you are currently using in Linux.
1) Using echo command
The Linux echo command is a built-in command that is used to print the output of a string which is passed as an argument. Additionally, you can use the echo command to check the shell that you are running commands in. To accomplish this, execute:
The output shows that I am using the bash shell. Additionally, you can simply run the command:
To get the PID of the shell that you are currently in, run:
2) Using ps command
Commonly used for listing running processes, the ps command in its basic format sheds light on the shell that you are using. Simply execute the command:
From the first line of the output, we can clearly see the PID of the shell and the last column prints out the type of shell, in this case — bash.
Alternatively, you can run the command:
You can also use ps -p $$ -o args= which output just the shell name.
3) By viewing /etc/passwd file
The grep command can be used to probe the /etc/passwd file that contains attributes of the users such as username, user ID and group ID.
To display the shell used, invoke the command:
At the very last segment, we get to see the bash used, in this case /bin/bash This also gives you a glimpse of which shell is opened first when you first log in to your system.
4) Using lsof command
Ordinarily, the lsof command, short for list of open files, is used to provide a list of open files on your system. However, when used with the -p $$ flag, it gives a pointer to the shell you are in when you look at the first column of the output.
For example, we can clearly see that we are on the bash shell.
How to check the valid login shells
We have seen various ways that you can employ to check the shell that you are currently in. If you want to know the valid shells on your system, check the /etc/shells file, This file will provide you with the full pathnames of valid login shells in your system. Using the cat command, view the file as shown:
Conclusion
In this guide, we have shared simple but nifty ways that you can use to know which shell you are working on. This is important when writing scripts so that you can know how to start off writing the shebang header. We do hope that this tutorial was beneficial. Send us a shout and don’t forget to share this guide on your social platforms.
Источник
How do I find out what shell I am using on Linux/Unix?
B oth Linux and Unix provides various shell out of the box. One can find bash (Bourne Again shell), ksh (Korn shell), csh (C shell)/tcsh (TC shell), sh (Bourne shell) and more installed by default. However, how do you check which shell am I using? What is the best way to find out what shell I am using on Linux? The echo $SHELL is not so reliable. This page explains how to find out which shell I am using at a Linux, MacOS, FreeBSD, or Unix-like systems.
How can I find out what shell I am using?
The following echo command or printf command should work:
echo «$SHELL»
OR
printf «My current shell — %s\n» «$SHELL»
Please note that $SHELL is the shell for the current user but not necessarily the shell that is running at the moment. Try the following examples
How do I check which shell am I using?
Here is another old good Unix trick. Use the ps command with -p
ps -p $$
Sample outputs:
So what is a $ argument passed to the -p option? Remember $ returns the PID (process identification number) of the current process, and the current process is your shell. So running a ps on that number displays a process status listing of your shell. In that listing, you will find the name of your shell (look for CMD column).
ps -p $$
Sample outputs:
From my Linux box:
ps -p $$
Sample outputs:
You can store your shell name in a variable as follows :
MYSHELL=`ps -hp $$|awk ‘
Please note those are backquotes, not apostrophes. Or better try out the following if you have a bash shell:
MYSHELL=$(ps -hp $$|awk ‘
Another option is as follows:
echo $0
OR
printf «%s\n» $0
Sample outputs from the above commands:
Fig.01: Linux check which shell am I using
How do I check how many shells are installed on my Linux box?
The /etc/shells is a text file which contains the full pathnames of valid login shells. Type the following [nixmd name=”cat”] to see list how many shells are installed on your Linux or Unix box:
cat /etc/shells
Use /etc/shells file to check how many shells are installed on your system
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Okay, so when I open the Terminal app, which shell is opened by default?
Your default shell is defined in /etc/passwd file. So try the following grep command:
How to check which shell am I using:
Use the following Linux or Unix commands:
- ps -p $$ – Display your current shell name reliably.
- echo «$SHELL» – Print the shell for the current user but not necessarily the shell that is running at the movement.
- echo $0 – Another reliable and simple method to get the current shell interpreter name on Linux or Unix-like systems.
- readlink /proc/$$/exe – Another option to get the current shell name reliably on Linux operating systems.
- cat /etc/shells – List pathnames of valid login shells currently installed
- grep «^$USER» /etc/passwd – Print the default shell name. The default shell runs when you open a terminal window.
- chsh -s /bin/ksh – Change the shell used from /bin/bash (default) to /bin/ksh for your account
Conclusion
Sometimes things are not easy as they seem, and this page is the perfect example of it. I hope you found the suggestion useful when it comes to checking your current running shell. Bash users can display shell version by typing the following command:
$ bash —version
Here is what I got from my Ubuntu Linux 20.04 LTS desktop:
Источник
Linux Shell Commands
The Shell is the command interpreter on Linux systems. This document intoduces some of the basic features of the Shell and lists many of the commands or programs available on the Linux computers in Cardiff School of Computer Science & Informatics.
The Shell
The Linux command interpreter or shell is the program users interact with in a terminal emulation window. The terminal emulation window can be one in the workstation’s Graphical User Interface mate-terminal on Linux. Alternatively, it can be an application such as SSH secure shell client or PuTTY on a Windows PC that’s logged into Linux over the network.
The shell used in the School of Computer Science & Informatics is bash Bourne Again Shell. There are other shells available such as the Bourne Shell, the C-Shell and the TC-Shell, and you can choose to use a different shell if you prefer. They all have similar characteristics but each has its own particular features. This document assumes you are using bash .
Bash has the following features:
A command prompt which may be configured by the user. The default prompt is a dollar symbol preceded by «bash» and the bash program’s version number.
/bin containing the following.
/bin/countc
bash-2.05$ countc
45
516 ls -lrt
517 ps -ef
518 pdflatex myfile.tex
See the manual page on bash for more details (type man bash ).
Bash has an additional mechanism which allows you to recall and edit previous commands using the keyboard up-arrow key. If you press up-arrow, the last command re-appears on the terminal. Press up-arrow again to get earlier commands. To rerun the command, press RETURN . To amend the command before rerunning it, use the delete key to remove characters from the end or use the back-arrow key to reposition the cursor to delete or insert characters within the command.
Shell Commands
Here is a summary of some of the commands available. For more details refer to the manual page of each command. You can see these on-line by using the man command. Just type man followed by the name of the command you want to see.
Logging out
Command | Description |
logout | log out of a Linux terminal |
Note, on a Linux workstation you will need to exit the Desktop Environment instead.
Files and Directories
These commands allow you to create directories and handle files.
Command | Description |
---|---|
cat | concatenate and print data |
lpr | spool file for line printing |
cd | change current directory |
lprm, cancel | remove jobs from line printer queue |
chgrp | change file group |
ls | list and generate statistics for files |
chmod | change file mode |
mkdir | make a new directory |
cp | copy file data |
more, page | display file data at your terminal |
Command | Description |
---|---|
file | determine file type |
mv | move or rename files |
find | find files |
pwd | print working directory |
grep | search file for regular expression |
rm, rmdir | remove (unlink) files or directories |
head | give first few lines |
tail | print last lines from file |
just | text justification program |
touch | update access and modification times of a file |
lpq | spool queue examination program |
File Editors
Editors are used to create and amend files.
Command | Description |
---|---|
emacs | GNU project Emacs |
xemacs | emacs with mouse action |
ex, edit | line editor |
Command | Description |
---|---|
pico | easy text editor for vdus |
pluma | Mate GUI text editor |
gedit | GNOME text editor |
vi, vim | standard text editor |
Vi , pico and emacs are screen-based editors which run on a vdu or in a workstations terminal emulation window; pluma , gedit and xemacs are graphical user interface (GUI) based editors with cut and paste and mouse-controlled cursor positioning.
Manipulating data
The contents of files can be compared and altered with the following commands.
Command | Description |
awk | pattern scanning and processing language |
perl | data manipulation language |
cmp | compare the contents of two files |
paste | merge file data |
comm | compare sorted data |
sed | stream text editor |
cut | cut out selected fields of each line of a file |
sort | sort file data |
diff | differential file comparator |
Command | Description | split | split file into smaller files |
---|---|
expand, unexpand | expand tabs to spaces, and vice versa |
tr | translate characters |
gawk | pattern scanning and processing language |
uniq | report repeated lines in a file |
join | join files on some common field |
look | find lines in sorted data |
wc | count words, lines, and characters |
Compressed files
Files may be compressed to save space. Compressed files can be created and examined.
Command | Description |
---|---|
gzip | compress files |
zmore | file perusal filter for crt viewing of compressed text |
uncompress | uncompress files |
Command | Description |
---|---|
zcat | cat a compressed file |
gunzip | uncompress gzipped files |
zcmp, zdiff | compare compressed files |
Information
Manuals and documentation are available on-line. Go to our web site www.cs.cf.ac.uk/systems for web-based documentation. The following Shell commands give information.
Command | Description |
apropos | locate commands by keyword lookup |
man | displays manual pages online |
Command | Description |
---|---|
info | displays command information pages online |
yelp | GNOME help viewer |
Status
These commands list or alter information about the system.
Command | Description |
ps | print process status statistics |
date | print the date |
quota -v | display disk usage and limits |
reset | reset terminal mode |
du | print amount of disk usage |
script | keep script of terminal session |
stty | set terminal options |
groups | show group memberships |
time | time a command |
homequota | show quota and file usage |
iostat | report I/O statistics |
tty | print current terminal name |
Command | Description |
---|---|
kill | send a signal to a process |
uptime | display system status |
last | show last logins of users |
users | print names of logged in users |
lun | list user names or login ID |
vmstat | report virtual memory statistics |
netstat | show network status |
w | show what logged in users are doing |
who | list logged in users |
printenv | display value of a shell variable |
Printing
Files can be printed using shell commands, using the GUI print manager, or direct from some applications.
You must specify a printer by name. Printers are called
Printer Name | Location |
---|---|
tl1_lw | Teaching Lab 1 (C/2.04) laser printer |
tl3_lw | Teaching Lab 3 (C/2.08) laser printer |
Printer Name | Location |
---|---|
tl2_lw | Teaching Lab 2 (C/2.05) laser printer |
tl4_lw | Teaching Lab 4 (C/2.10) laser printer |
Most commands which can be used to print files, expect the printer name to be given following a -P argument.
Files may be sent to the printers as simple text files or they may be processed in various ways for the laser printers.
Command | Description |
---|---|
lpr -P printer | send a file to a printer |
dvips -P printer | postprocess TeX file into Postscript and print on laser printer |
a2ps -P printer | format text file in PostScript and print on laser printer |
Messages between Users
The Linux systems support on-screen messages to other users and world-wide electronic mail.
Command | Description |
---|---|
write | send a message to another local user |
wall | send a message to all local users |
Command | Description |
---|---|
pine | vdu-based mail utility |
simple send or read mail program | |
thunderbird | GUI mail handling tool on Linux |
Networking
The School of Computer Science & Informatics is connected to the JANET Internet Protocol Service (JIPS), the UK Universities’ network.
These commands are used to send and receive files from Campus Linux hosts and from other hosts on JIPS and the Internet, that permit such connections, around the world.
Command | Description |
---|---|
ftp | file transfer program |
tftp | trivial file transfer program |
sftp | secure shell file transfer program |
rcp | remote file copy |
scp | secure shell remote file copy |
wget | non-interactive network downloader |
Command | Description |
---|---|
telnet | make terminal connection to another host |
ssh | secure shell terminal or command connection |
rlogin | remote login to a Linux host |
rsh | remote shell |
curl | transfer data from a url |
firefox | web browser |
google-chrome | web browser |
These commands work only where the remote host permits such connections.
Programming
The following programming tools and languages are available.
General
Command | Description |
---|---|
make | maintain groups of programs |
size | print program’s sizes |
Command | Description |
---|---|
nm | print program’s name list |
strip | remove symbol table and relocation bits |
Command | Description |
---|---|
cb | C program beautifier |
gcc | GNU ANSI C Compiler |
Command | Description |
---|---|
ctrace | C program debugger |
indent | indent and format C program source |
cxref | generate C program cross reference |
Command | Description |
---|---|
g++ | GNU C++ Compiler |
Command | Description |
---|---|
appletviewer | JAVA applet viewer |
javac | JAVA compiler |
eclipse | Java integrated development environment on Linux |
FORTRAN
Command | Description |
f95 | GNU Fortran 95 compiler |
Other Languages
(Not available on all systems).
Command | Description |
bc | interactive arithmetic language processor |
matlab | maths package |
gcl | GNU Common Lisp |
perl | general purpose language |
Command | Description |
---|---|
python | object-oriented programming language |
squeak | smalltalk |
php | web page embedded language |
mathematica | symbolic maths package |
asp | web page embedded language |
Text Processing
TeX is a typesetting language used extensively in Linux and other operating systems for producing high-quality printed documents. Another set of programs based on Troff is the standard Linux text formatting family used, for example to format manual pages.
General Commands
Command | Description |
---|---|
fmt | simple text formatter |
evince | GNOME PostScript previewer |
Command | Description |
---|---|
acroread | PDF viewer |
spell | check text for spelling error |
aspell | interactive spelling checker |
Troff
Command | Description |
---|---|
eqn | mathematical preprocessor for troff |
tbl | prepare tables for nroff or troff |
grap | pic preprocessor for drawing graphs |
troff | text formatting and typesetting language |
Command | Description |
---|---|
nroff | text formatting language |
groff | GNU troff interface for laserprinting |
pic | troff preprocessor for drawing pictures |
Command | Description |
---|---|
tex | text formatting and typesetting |
latex | latex formatter |
Command | Description |
---|---|
pdflatex | latex formatter with PDF output |
xdvi | dvi previewer |
dvips | convert a DVI file to POSTSCRIPT |
Word Processing
LibreOffice is available on the School’s Linux systems and attempts compatibilty with Microsoft Office.
Command | Description |
---|---|
libreoffice | start LibreOffice applications |
Database Management
MySQL and Oracle are available.
Command | Description |
---|---|
sqlplus | run the Oracle SQL interpreter |
mysql | run the mysql SQL interpreter |
sqldeveloper | Oracle SQL Developer GUI interface |
mysql-workbench | GUI interface for MySQL |
Cardiff University is a member of the Russell Group of Universities
Cardiff University is a registered charity No. 1136855
Copyright © Cardiff University
Источник