Understand the different classifications of _Linux_ under _Shell_ commands and their usage

Summary: When you're going to really manipulate your Linux system, there's nothing like a command-line interface that lets you do it. In order to become a Linux pro, you must be able to understand the different types of shell commands and use them correctly in the terminal. Under Linux, there are several types of commands. For a Linux novice, only knowing the meaning of different commands can use them efficiently and accurately.

When you're going to really take control of your Linux system, there's nothing like a command-line interface that lets you do that. In order to become a Linux pro, you must be able to understand the different types of shell commands and use them correctly in the terminal.

Under Linux, there are several types of commands. For a Linux novice, only knowing the meaning of different commands can use them efficiently and accurately. Therefore, in this article, we will go over various different categories of Linux shell commands.

One very important thing to note: the command line interface is not the same as the shell, the command line interface just gives you a way to access the shell. The Shell, which is programmable, allows it to communicate with the kernel through commands.

The different types of commands under Linux are listed below:

1. Program executables (commands in the file system)
When you execute a command, Linux finds it by searching the directories stored in the $PATH environment variable from left to right The executable for this command.

You can view the directories stored in $PATH like this:

$ 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 command, the directory /home/aaronkilik/bin will be searched first, followed by /usr/local/sbin, and so on. During the search process, the search order is critical.

For example a command in a filesystem in the /usr/bin directory:

$ ll /bin/
Example 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 created with the shell builtin alias, which contain other shell commands with options and arguments. The intent is primarily to replace verbose commands with novel, short names.

The syntax for creating an alias is as follows:

$ alias newcommand='command -options'
All aliases in the system can be listed with the following command:

$ 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='

alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
To create a new alias in Linux, read the following example carefully .

$ alias update='sudo apt update'
$ alias upgrade='sudo apt dist-upgrade'
$ alias -p | grep 'up'

However, the aliases we created above only work temporarily, after the next system boot They no longer work. You can set permanent aliases in the '.bashrc' file as shown below.


After adding, run the following command to activate:

$ source ~/.bashrc
3.
Linux Shell Reserved Words In shell programming, if, then, fi, for, while, case, esac, else, until, and many more words are shell reserved words. As the description implies, they have a special meaning in the shell.

You can list all shell keywords by using the type command shown below:

$ type if then fi for while case esac else until
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 set of commands that are executed together within the current shell. Functions are useful for implementing special tasks in shell scripts. The traditional form of writing shell functions in shell scripts is like this:

function_name() {
command1
command2
......
}
or like this: function

function_name {
command1
command2
......
}
Shell functions are written in a script called 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 two commands from the command line: sudo apt update and sudo apt dist-upgrade, we wrote a shell in the script that executes two commands as if they were a single command Function upgrade_system.

Save the file, then make the script executable. Finally run the shell function like this:

$ chmod +x shell_functions.sh
$ ./shell_functions.sh

5. Linux Shell Builtin Commands
These are Linux commands built into the shell, so you can't find them in the filesystem. These commands include pwd, cd, bg, alias, history, type, source, read, exit, etc.

You can list or check Linux built-in commands with the type command shown below:

$ 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 the usage of some Linux built-in commands:

15 pwd command examples under
Linux 15 cd command examples under Linux
Understand the power of the history command under Linux "Linux China"


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326196277&siteId=291194637