5 Different Types of Shell Commands in Linux

When it comes to gaining absolute control over your Linux system, then nothing comes close to the command line interface (CLI). In order to become a Linux power user, one must understand the different types of shell commands and the appropriate ways of using them from the terminal.

In Linux, there are several types of commands, and for a new Linux user, knowing the meaning of different commands enables efficient and precise usage. Therefore, in this article, we shall walk through the various classifications of shell commands in Linux.

One important thing to note is that the command line interface is different from the shell, it only provides a means for you to access the shell. The shell, which is also programmable then makes it possible to communicate with the kernel using commands.

Different classifications of Linux commands fall under the following classifications:

1. Program Executables (File System Commands)

When you run a command, Linux searches through the directories stored in the $PATH environmental variable from left to right for the executable of that specific command.

You can view the directories in the $PATH as follows:

echo $PATH

/home/aaronkilik/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

In the above order, the directory /home/aaronkilik/bin will be searched first followed by /usr/local/sbin and so on, the order is significant in the search process.

Examples of file system commands in /usr/bin directory:

ll /bin/

Sample Output:

total 16284
drwxr-xr-x  2 root root    4096 Jul 31 16:30 ./
drwxr-xr-x 23 root root    4096 Jul 31 16:29 ../
-rwxr-xr-x  1 root root    6456 Apr 14 18:53 archdetect*
-rwxr-xr-x  1 root root 1037440 May 17 16:15 bash*
-rwxr-xr-x  1 root root  520992 Jan 20  2016 btrfs*
-rwxr-xr-x  1 root root  249464 Jan 20  2016 btrfs-calc-size*
lrwxrwxrwx  1 root root       5 Jul 31 16:19 btrfsck -> btrfs*
-rwxr-xr-x  1 root root  278376 Jan 20  2016 btrfs-convert*
-rwxr-xr-x  1 root root  249464 Jan 20  2016 btrfs-debug-tree*
-rwxr-xr-x  1 root root  245368 Jan 20  2016 btrfs-find-root*
-rwxr-xr-x  1 root root  270136 Jan 20  2016 btrfs-image*
-rwxr-xr-x  1 root root  249464 Jan 20  2016 btrfs-map-logical*
-rwxr-xr-x  1 root root  245368 Jan 20  2016 btrfs-select-super*
-rwxr-xr-x  1 root root  253816 Jan 20  2016 btrfs-show-super*
-rwxr-xr-x  1 root root  249464 Jan 20  2016 btrfstune*
-rwxr-xr-x  1 root root  245368 Jan 20  2016 btrfs-zero-log*
-rwxr-xr-x  1 root root   31288 May 20  2015 bunzip2*
-rwxr-xr-x  1 root root 1964536 Aug 19  2015 busybox*
-rwxr-xr-x  1 root root   31288 May 20  2015 bzcat*
lrwxrwxrwx  1 root root       6 Jul 31 16:19 bzcmp -> bzdiff*
-rwxr-xr-x  1 root root    2140 May 20  2015 bzdiff*
lrwxrwxrwx  1 root root       6 Jul 31 16:19 bzegrep -> bzgrep*
-rwxr-xr-x  1 root root    4877 May 20  2015 bzexe*
lrwxrwxrwx  1 root root       6 Jul 31 16:19 bzfgrep -> bzgrep*
-rwxr-xr-x  1 root root    3642 May 20  2015 bzgrep*

2. Linux Aliases

These are user-defined commands, they are created using the alias shell built-in command and contain other shell commands with some options and arguments. The idea is to basically use new and short names for lengthy commands.

The syntax for creating an alias is as follows:

alias newcommand='command -options'

To list all aliases on your system, issue the command below:

alias -p

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '''s/^s*[0-9]+s*//;s/[;&|]s*alert$//''')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

To create a new alias in Linux, go through some below examples.

alias update='sudo apt update'
alias upgrade='sudo apt dist-upgrade'
alias -p | grep 'up'
Create Aliases in Linux
Create Aliases in Linux

However, the aliases we have created above only work temporarily when the system is restarted, they will not work after the next boot. You can set permanent aliases in your .bashrc file as shown below.

Set Aliases Permanent in Linux
Set Aliases Permanent in Linux

After adding them, run the command below to activate.

source ~/.bashrc

  • BEST Webhosting

    Explore a comprehensive array of web hosting services designed to cater to various needs. Whether you’re an individual looking for reliable personal hosting or a business requiring high-performance solutions, BEST Webhosting offers tailored options to ensure optimal website performance, robust security, and 24/7 support.

  • Unveiling the Pillars of Web Hosting

    Web hosting is the backbone of a digital presence, providing the infrastructure necessary to publish and maintain websites online. This article delves deep into the essentials of web hosting, guiding individuals and businesses to make informed decisions. Learn about hosting types, server performance, and scalability options to choose the perfect fit for your online goals.

  • Digital Experience and Coding a New Website

    Building a website today involves more than creating an online presence; it’s about delivering an exceptional digital experience. This piece explores modern website design principles, user experience strategies, and advanced coding techniques. It highlights how a well-crafted website can effectively convey your brand message, captivate audiences, and drive business success.

  • How to Buy a .com.au Domain: A Buyer’s Guide to .com.au Domains

    This guide is a must-read for startups and established businesses aiming to enhance their Australian online presence. Learn the steps to secure a .com.au domain that aligns perfectly with your brand identity. The article provides insights into domain registration requirements, tips for choosing a memorable domain name, and the benefits of a local domain for SEO.

  • Incredible Ideas deserve Incredible DomainsWith Rapid Registration, your domain is registered almost instantly, meaning you don’t have to wait to get your business or name online!
  • Edge of Technology, Digital Transformation, and Cloud Computing

    Staying competitive in today’s fast-paced digital landscape requires leveraging cutting-edge technologies. This article explores the vital roles of Digital Transformation (DT) and Cloud Computing in modern business strategies. Understand how these technologies drive efficiency, foster innovation, and enable organisations to scale operations seamlessly.

  • The Best WordPress Plugins for Email Marketing to Grow and Engage Your Subscriber List

    Email marketing remains a powerful tool for audience engagement and lead conversion. Discover top WordPress plugins like Mailchimp, Constant Contact, OptinMonster, and Thrive Leads. This article provides detailed guidance on creating effective opt-in forms, segmenting email lists, automating campaigns, and tracking metrics for successful email marketing strategies.

  • The Best WordPress Caching Plugins to Optimize Site Speed and Performance

    Website speed and performance are crucial for user experience and SEO rankings. This detailed review covers the most effective WordPress caching plugins, including W3 Total Cache, WP Super Cache, WP Rocket, WP Fastest Cache, and LiteSpeed Cache. Learn how these plugins enhance site performance by minimising load times and optimising server resources.


3. Linux Shell Reserved Words

In shell programming, words such as if, then, fi, for, while, case, esac, else, until, and many others are shell-reserved words. As the description implies, they have specialized meaning to the shell.

You can list out all Linux shell keywords using type command as shown:

type if then fi for while case esac else until

Sample Output:

if is a shell keyword
then is a shell keyword
fi is a shell keyword
for is a shell keyword
while is a shell keyword
case is a shell keyword
esac is a shell keyword
else is a shell keyword
until is a shell keyword

4. Linux Shell Functions

A shell function is a group of commands that are executed collectively within the current shell. Functions help to carry out a specific task in a shell script. The conventional form of writing shell functions in a script is:

function_name() {
command1
command2
…….
}

Alternatively,

function function_name {
command1
command2
…….
}

Let’s take a look at how to write shell functions in a script named shell_functions.sh.

#!/bin/bash 

#write a shell function to update and upgrade installed packages 
upgrade_system(){
        sudo apt update;
        sudo apt dist-upgrade;
}

#execute function
upgrade_system

Instead of executing the following two commands from the command line.

sudo apt update
sudo apt dist-upgrade

We have written a simple shell function to execute the two commands as a single command, upgrade_system within a script.

Save the file and thereafter, make the script executable. Finally, run it as below:

chmod +x shell_functions.sh
./shell_functions.sh
Linux Shell Functions Script
Linux Shell Functions Script

5. Linux Shell Built-in Commands

There are Linux commands built into the shell, so you won’t find them within the file system. They include pwd, cd, bg, alias, history, type, source, read, exit, and many others.

You can list or check Linux built-in commands using type command as shown:

type pwd
pwd is a shell builtin
type cd
cd is a shell builtin
type bg
bg is a shell builtin
type alias
alias is a shell builtin
type history
history is a shell builtin

Learn about some Linux built-in Commands usage:

Conclusion

As a Linux user, it is always important to know the type of command you are running. I believe, with the precise and simple-to-understand explanation above including a few relevant illustrations, you probably have a good understanding of the various categories of Linux commands.

You can also get in touch through the comment section below for any questions or supplementary ideas that you would like to offer us.

Similar Posts