Are you ready to boost your productivity and streamline your workflow? Look no further than the powerful tools of the shell terminal.
In this guide, you will learn about the differences between shell and terminal and how to use them efficiently to navigate the command line. You will also learn how to make the most of the shell prompt and how to use the history to streamline your workflow.
Whether you are new to command line interfaces or a seasoned pro, this guide will provide you with the knowledge and skills needed to master the shell terminal and take your productivity to new heights.
So, let’s dive in and discover the exciting world of shell terminal!
What is the shell?
A shell is a command line interface that allows users to interact with the operating system. It is a program that takes commands from the keyboard and gives them to the operating system to perform.
The shell is responsible for interpreting commands entered by the user, and it also provides additional features such as command history, tab completion, and command line editing.
For more information on how to execute a command with a shell script in Linux, please visit: How to Execute a command with a Shell script.
There are many different shells available for Linux and Unix-based operating systems, but the most commonly used ones are the Bourne shell (sh), the C shell (csh), and the Bourne Again shell (bash).
Here is an example of how to use the bash shell to display the current working directory:
To list the contents of a directory:
To navigate to a different directory:
$ cd /path/to/directory
Here’s an example of how to use the bash shell to execute a script:
These are just a few examples of the many commands that can be executed in a shell. The specific commands and syntax will depend on the shell being used.
Difference between a terminal and a shell
A terminal is a program that allows a user to interact with their computer’s operating system using text commands. It provides a command line interface (CLI) for entering and executing these commands.
Examples of terminal programs include xterm, gnome-terminal, and terminal.app on MacOS.
A shell, on the other hand, is a command line interpreter that provides a way for a user to interact with the operating system through the terminal. It interprets the commands entered by the user and then executes them.
Examples of shells include Bash, Zsh, Csh, etc.
In summary, the shell is a program that runs inside the terminal. The terminal provides the interface for the user to enter commands, and the shell interprets and executes those commands.
When you open a terminal window, the terminal program starts a shell process. You can interact with the shell by entering commands into the terminal. The shell then interprets and executes those commands, and displays the output back in the terminal window.
It is also worth mentioning that you can have multiple shells running in the same terminal window, each in a different tab and you can switch between them.
Here is an example of how to open the terminal on Linux, macOS, and Windows
- Ctrl + Alt + T (Linux)
- Cmd + Space (macOS)
- Windows R, then type
cmdand enter to open (Window)
When you open a terminal, it starts a shell. The default shell on Linux is usually Bash (Bourne-Again shell) but it can be changed to other shells like Zsh, Fish, etc.
Here is an example of how to check the default shell of your terminal
$ echo $SHELL
Inside a terminal, you are presented with a prompt (e.g., $) that is generated by the shell. You can then enter commands at this prompt, and the shell will execute them.
Here is an example of how a terminal and a shell work together:
- A user opens a terminal program (e.g. gnome-terminal)
- The terminal program starts a shell (e.g. Bash)
- The user enters a command (e.g.
ls) into the terminal
- The shell interprets the command and executes it (e.g. it lists the files and directories in the current directory)
- The output of the command is displayed in the terminal
Here is an example:
# This is an example of a command entered into a terminal ls -al # This is an example of a shell script #!/bin/bash echo "Hello, World!"
- The first line is a command that can be entered directly into the terminal and run.
- The second line is a shell script that can be executed by a shell.
What is the shell prompt?
The shell prompt is the text displayed on the command line that indicates that the system is ready to receive input. It typically includes information such as the current user, hostname, and current working directory.
Here are some examples of common shell prompts:
- In a BASH shell, the default prompt is typically in the format
- In a ZSH shell, the default prompt is typically in the format
username@hostname ~ %
How to navigate the filesystem in a Shell Terminal
There are several ways to navigate the filesystem in a shell.
Here are some basic commands and concepts you can use to move around the filesystem:
- pwd: this command displays the current working directory, which is the directory you are currently located in.
- cd: This command allows you to change the current working directory. You can use it to move to a different directory by specifying the path to the directory you want to move to.
- .. : this is a special directory that refers to the parent directory of the current working directory. You can use it to move up one level in the directory hierarchy.
- / : This is the root directory of the filesystem. You can use it to move to the top level of the filesystem.
- ~ : this is a special directory that refers to the home directory of the current user. You can use it to move to the home directory.
You can also use relative and absolute paths to navigate the filesystem.
A relative path is a path that is relative to the current working directory, while an absolute path is a path that starts with the root directory (
For example, if your current working directory is
/home/user/ and you want to move to the
/home/user/documents directory, you can use a relative path:
You can also use an absolute path:
These are some basic commands and concepts that can help you navigate the filesystem in a shell.
Keep in mind that the specifics of how these commands work may vary depending on the shell and operating system you are using.
How do you change directory on Linux?
Leave your answers to the quiz in the comments section below and we will give a shoutout to the first 3 readers who got the answer right.
Navigating the filesystem efficiently with the shell terminal is a key skill for any Unix-based systems user. The shell provides a set of commands that allows you to easily move around the filesystem, list and manage files and directories, and create links between files.
Some of the key concepts and commands to master when navigating the filesystem with the shell terminal include:
- Understanding the current working directory and how to change it with the
- Knowing how to move up and down the directory hierarchy with
- Being able to use relative and absolute paths to specify the location of files and directories.
- Being familiar with the
lscommand and its options to list the files and directories in a directory.
Mastering these concepts and commands will allow you to navigate the filesystem quickly and efficiently with the shell terminal, and will serve as a solid foundation for learning more advanced shell commands and concepts.
Ready to take your shell skills to the next level? Check out our forum for a variety of tasks and projects that will put your knowledge to the test.
Leave a Reply