Shell Programming - DEV Community
Shell Programming - DEV Community
Oluchi John
Posted on Apr 26
18 2 1 4 3
Shell Programming
#shell #linux #bash #gitbash
In today's rapidly evolving tech landscape, mastering the command line streamlines the
development process for developers. The command line can be accessed through
various shell environments like Bash and PowerShell. This article explores the shell
environment, showing its role in executing complex operations, navigating files,
processing data, and text manipulation.
Definition of shell
A shell is a user interface that allows users to interact with a computer's operating
system using text-based commands. Think of it as a translator between the user and the
operating system
The shell takes the human-readable commands entered by the user and translates them
into instructions that the operating system understands and executes, it also displays
the results or output of these commands back to the user. This type of interaction,
called a command-line interface (CLI), gives you more direct control over the system
https://dev.to/ollie20/shell-programming-4k65?context=digest 1/11
4/27/24, 2:16 AM Shell Programming - DEV Community
Importance of Shell
Shell allows users to interact with the operating system. This makes it easier to
execute complex tasks by typing specific commands.
It allows users to automate repetitive tasks using written shell scripts.
It helps administrators and users access remote systems through protocols like SSH
It can be used to access and manage files and directories.
It diagnoses issues and checks system status.
Shell Environments
There are several shells available, each with its own unique features and syntax. Some of
the most widely used shells include:
Bash (Bourne-Again Shell): This is one of the shells on Linux distributions and macOS.
Its syntax is compatible with the original Unix shell, making it a popular choice.
Zsh (Z Shell): Zsh is known for its extensive customization options and advanced
features. It offers improved tab completion, history management, and plugin support.
This article uses the bash shell for code examples and commands. If you're unfamiliar
with Bash, consider using Git Bash for Windows or the built-in Terminal app on macOS.
Both offer a Bash-like experience that you can follow along with in this article.
Commands Function
pwd(Print
This command shows the path of the current directory you're
Working
working with.
Directory)
Command syntax
Some commands have components that modify their function. These components are
called options and arguments.
Options are used to adjust the operation of the command while arguments are what the
command operates on. Eg:
ls -l myfile
-l is the option while myfile is the argument.
Commands Function
ls -t List all file contents by the time they were last modified
cd ~username This will take you to the directory of the specified username
https://dev.to/ollie20/shell-programming-4k65?context=digest 3/11
4/27/24, 2:16 AM Shell Programming - DEV Community
Commands Function
Nano
Vim
Emacs
https://dev.to/ollie20/shell-programming-4k65?context=digest 4/11
4/27/24, 2:16 AM Shell Programming - DEV Community
sed: The sed command performs text transformations on an input stream. It's
particularly useful for finding and replacing text within files.
awk: The awk command processes and analyzes text line by line. It's often used for
data extraction and reporting.
ssh your_username@remote-machine-address
Don't worry if you don't see characters appearing as you type; it's a security feature.
Once it is done, this allows administrators to execute commands, manage files, and
perform various administrative tasks on the remote machine.
https://dev.to/ollie20/shell-programming-4k65?context=digest 5/11
4/27/24, 2:16 AM Shell Programming - DEV Community
This means the owner, group, and others can read, write, and execute the file. The -
indicates it is a file, d indicates a directory.
rw-rw-rw- means the owner, group, and others can only read and write the file.
Changing Permissions
The chmod command is used to modify file permissions. You can change permissions
either numerically or symbolically.
Numerical example: chmod 774 myfile
Symbolic example: chmod u+rwx myfile
https://dev.to/ollie20/shell-programming-4k65?context=digest 6/11
4/27/24, 2:16 AM Shell Programming - DEV Community
The chown command is used to change the owner and group of a file or directory.
Output redirection: The > symbol is used to redirect the output of a command to a
file. If the command doesn't exist, If the file doesn't exist, it's created; if it exists, it's
overwritten.
Append redirection: The >> symbol is similar to the output redirection but instead
of overwriting the file, it adds the output to the end of an existing file.
Input redirection
Pipes (|)
A pipe | is used to send the output of one command as the input to another. This is
used to connect commands.
Eg: ls -l | grep "file"
In this example, the ls -l command lists files in detailed format, and the output is then
filtered by grep to display only lines containing the word "file."
https://dev.to/ollie20/shell-programming-4k65?context=digest 7/11
4/27/24, 2:16 AM Shell Programming - DEV Community
In the next article, we will look at advanced shell techniques and shell scripting.
👋 Before you go
Do your career a favor. Join DEV. (The website you're on right now)
Get started
GrimKillingbeck • Apr 26
This was a great overview of Shell commands. You refreshed a few things for
me, especially since I've just creating my own scripts!
Ini • Apr 26
Pieces.app PROMOTED
https://dev.to/ollie20/shell-programming-4k65?context=digest 8/11
4/27/24, 2:16 AM Shell Programming - DEV Community
Our desktop app, with its intelligent copilot, streamlines coding by generating
snippets, extracting code from screenshots, and accelerating problem-solving.
Oluchi John
JOINED
May 31, 2023
Javascript factorial
https://dev.to/ollie20/shell-programming-4k65?context=digest 9/11
4/27/24, 2:16 AM Shell Programming - DEV Community
AWS PROMOTED
https://dev.to/ollie20/shell-programming-4k65?context=digest 10/11
4/27/24, 2:16 AM Shell Programming - DEV Community
Get expert advice around all things security as AWS and AWS Partners go in depth and discuss a new
security topic each episode—streaming live every other Wednesday at 8AM PT.
Learn More
https://dev.to/ollie20/shell-programming-4k65?context=digest 11/11