Shell Basic Operations

Table of contents

1. What is Shell

2. What is the relationship between Shell and Bash? What's the difference?

3. Shell command format

4. Auto-completion function

5. Commonly used Shell commands

1. Directory information viewing command ls 

2. Directory switching command cd

3. The current path display command pwd 

4. System information viewing command uname 

5. Clear screen command clear 

6. Switch the user to execute the identity command sudo 

7. Add user command adduser 

8. Delete user command deluser 

9. Switch user command su 

10. Display file content command cat 

11. Display and configure network attribute command ifconfig 

12. System help command man 

13. System restart command reboot 

14. The system shutdown command poweroff 

15. Software installation command install 


1. What is Shell

The shell is a command interpreter that interacts between the user and the operating system.

Simply put, Shell is to type commands. In China, inputting commands through the command line under Linux is called "knocking commands". Foreigners play it in a more western style, and they call it "Shell". Therefore, the first reaction when seeing the word Shell in the future is to type commands in the terminal, and put multiple Shell commands into a text according to a certain format, then this text is called a Shell script.

-- punctual atom

2. What is the relationship between Shell and Bash? What's the difference?

/bin/bash is the most commonly used shell and is the default shell for most current Linux distributions.

Other shells include: sh, ksh, rsh, csh, etc.

3. Shell command format

command    -options     [argument] 
command: Shell 命令名称。 
options:选项,同一种命令可能有不同的选项,不同的选项其实现的功能不同。 
argument:Shell 命令是可以带参数的,也可以不带参数运行。 

4. Auto-completion function

After using the auto-completion function, we only need to enter the first part of the letters of the command, and then press the TAB key. If only one command matches, it will automatically complete the remaining letters of the command. If there are multiple commands matching, the system will sound an alarm, and at this time, pressing the TAB key once will list all matching commands.

5. Commonly used Shell commands

1. Directory information viewing command ls 

ls [options] [path] 

  -a Displays all files and subdirectories, including hidden files starting with ".". 
  -l Display the detailed information of the file, such as the shape, permission, owner, size and other information of the file. 
  -t List files sorted by creation time. 
  -A Same as -a, but do not list "." (current directory) and ".." (parent directory). 
  -R List all files recursively, including files in subdirectories. 

2. Directory switching command cd

cd [path] 

The path is the directory path we want to enter, such as the following operations: 

cd / //Enter the root directory "/", the root directory of the Linux system is "/", 
cd /usr //Enter the directory "/usr". 
cd .. //Enter the upper directory.     
cd ~ //Switch to the current user's home directory 

3. The current path display command pwd 

Display the absolute path of the current working directory, no parameters are required.

4. System information viewing command uname 

uname [options] 

Optional option parameters are as follows: 

    -r lists the specific kernel version number of the current system. 
   -s List system kernel names. 
   -o List system information. 

5. Clear screen command clear 

6. Switch the user to execute the identity command sudo 

Ubuntu (Linux) is an operating system that allows multiple users. The super user root has the most authority. Sometimes we need to use the root user identity to perform some operations, such as installing software. The sudo command allows us to temporarily switch our identity to the root user. The command format is as follows:  

sudo [options] [commands] 

-h Display help information. 

-l lists the commands that the current user can and cannot execute 

-p Changes the prompt asking for the password. 

7. Add user command adduser 

adduser [parameters] [username] 

  -system Add a system user 
  -home DIR DIR represents the user's home directory path 
  -uid ID ID represents the user's uid. 
  -ingroup GRP Indicates the group name to which the user belongs. 

User and User Group-UID and GID_uid gid_lucky Duoduo's Blog-CSDN Blog

Users and user groups in Linux (1): concepts and the meaning of setting users and user groups_What is the role of user groups?

8. Delete user command deluser 

eluser [parameters] [username] 

-system Can only be deleted when the user is a system user. 

-remove-home remove the user's home directory 

-remove-all-files Remove all files associated with the user. 

-backup backup user information 

9. Switch user command su 

su [options] [username] 

  -c –command Execute the specified command, and restore the original user identity after execution. 
  -login changes the user identity, and changes the working directory and PATH environment variable at the same time. 
  -m does not change the environment variable when changing the user identity 
  -h displays help information 

10. Display file content command cat 

cat [options] [file] 

  -n Number all output lines starting with 1. 
  -b Like -n, but does not number blank lines. 
  -s Merge into one blank line when two or more consecutive blank lines are encountered. 

11. Display and configure network attribute command ifconfig 

Through this command, we can view the current network properties, and also configure network properties through this command, such as setting the network IP address and so on.

ifconfig  interface  options | address 

interface Network interface name, such as eth0 and so on. 

up Turn on the network device. 

down Turn off the network device. 

add IP address, set the network IP address. 

netmask add subnet mask. 

12. System help command man 

Through the "man" command, you can view the syntax format, main functions, and main parameter descriptions of other commands:

man [command name] 

13. System restart command reboot 

reboot.

14. The system shutdown command poweroff 

shutdown.

15. Software installation command install 

Many software under Ubuntu need to download the source code first, compile it by yourself after downloading the source code, and use the command "intsall" to install after the compilation is completed.

The command "install" is usually used in combination with the command "apt-get", for example:

sudo apt-get install package-name 

Among them, "package-name" is the name of the software to be installed, "apt-get" is responsible for downloading the software, and "install" is responsible for installing the software.

Guess you like

Origin blog.csdn.net/qq_41709234/article/details/131354165