Linux common commands Linux is simple and basic to use commands for beginners!

Sort out common Linux commands

1. User management

add user useradd username

set password passwd username

Modify user usermod -l new username old username

delete user userdel username

2. User group management

add group groupadd group name

Modify group groupmod -n new group name old group name

Query the group the user is in groups username

delete group groupdel user group

Add user to group gpasswd -a username groupname

View all users under the group grep 'group name' /etc/group

3. System management

Date management​

date -s "2019-12-11 16:15:00" (set time) ​

date (display time) ​

show users

​logname (display login account information) ​

su switch user

su username

​id command

id (display user's current information) ​

sudo execute

sudo command (increase the privileges of the current user)

top

top -c (display process information)

​ps command

ps -ef (display all process information) ​

kill command

kill -9 thread name (completely kill the process) ​

shutdown command

shutdown -h now (shutdown immediately)

shutdown +1 (1 minute shutdown) ​

shutdown –r +1 (shutdown and restart after 1 minute) ​

who command

who (displays the user currently logged in to the system) ​

timedatectl command

timedatectl is used to control system time and date. Can be used to query and change the system clock and settings, and can set and modify time zone information

clear command

clear (command to clear the screen) ​

exit command

exit is often used in the shell

4. Directory management

ls list directories  

ls -l          

ls -al

cd change directory    

cd [relative or absolute path]

show current directory   

pwd

Create a new directory  

mkdir directory name

mkdir -p aaa/bbb (-p ensures that the directory name exists, create one if it does not exist)

delete an empty directory   

rmdir directory name

remove file or directory   

rm -r ccc (force not to ask)

rm -rf ccc (force not to ask for recursive delete)

Copy a file or directory       

cp [options] source dest

cp –r aaa/* ccc (copy object and subfiles)

Move files and directories or change the names of files and directories 

mv [options] source dest

mv aaa bbb

 

========================================================================

If there is a file with the same name in the specified directory, first ask whether to overwrite the old file

No indication is given when the mv operation is to overwrite an existing object file; file properties example file:

drwxr-xr-x. 2 root root 70 5月 23 19:59 tuned

The first character in Linux indicates whether the file is a directory, file or link file, etc.

  • When it is [ d ], it is a directory

  • When it is [ - ], it is a file;

  • If it is [ l ], it is represented as a link file;

  • If it is [ b ], it means the interface device (random access device) that can be stored in the device file;

  • If it is [ c ], it means the serial port device in the device file, such as keyboard, mouse (one-time read device).

The following characters are grouped by three, and they are all combinations of the three parameters of "rwx". in,

[ r ] stands for readable (read), [ w ] stands for writable (write), [ x ] stands for executable (execute)

It should be noted that the position of these three permissions will not change. If there is no permission, there will be a minus sign [-] only. File owner and group For a file, it has a specific owner, that is, the user who owns the file. That is, the so-called owner, which means which user it belongs to. In addition to the owner, there is also a group, that is, which group the file belongs to (the group to which the user belongs).

The [owner] of the file has a set of [read, write and execute permission rwx], the [group] of the file has a set of [read, write and execute permission rwx], and the [other user] of the file has a set of [read, write and execute permission rwx]

 

========================================================================

The chgrp command is used to change the group to which a file or directory belongs.            chgrp -v The modified group name file name

chown changes the owner and group                                           chown -R root:root abc modified group name file name

chmod command to change access permissions If you want to set all permissions of the abc file to enable the command as follows:

chmod -R 777 abc

chmod -R u=rwx,g=rx,o=r abc 

chmod -R a=rwx abc

chmod -R a=rwx abc

Five, touch command

The touch command is used to create files, modify the time attributes of files or directories, including access time and change time. If the file does not exist, the system will create a new file

touch aaa.txt [create an empty file] ​   

touch czbk-{1..10}.txt [create batch of empty files]

Six, vi and vim commands

VI: ​ Only edit text content, not typesetting font paragraphs​

VIM: ​ is a text editor developed from vi. The programming-friendly functions such as code completion, compilation, and error jumping are particularly rich​

VI/VIM mode: ​

Command mode : ​ Enter "vim file name" in the Linux terminal to enter the command mode, but you cannot enter text.

Edit mode: ​Press i in command mode to enter edit mode, you can write programs at this time, press Esc to return to command mode.

Last line mode: ​In the command mode, press: to enter the last line mode, a colon will appear in the lower left corner, and you can type in the command and execute it.

Edit file:​ vim txtfile.txt

  • If the file already exists, the file will be opened directly

  • If the file does not exist, a new file will be created when saving and exiting. Exception handling: - If vim exits abnormally, a swap file may be saved on disk

  • The next time you use vim to edit the file, you will see the following screen information,

7. File View

cat command

cat txtfile.txt [view all file contents directly]​

grep command   

grep eeee txtfile.txt [search files with lines with the keyword "eeee"] ​

grep -n eeee txtfile.txt [search for the line with the keyword "eeee" and display the line number] ​

grep -i eeee txtfile.txt [ignore case search for lines with keywords] ​

grep -v Chinese txtfile.txt [search for lines without keywords] ​

ps -ef | grep sshd (content) [find the specified process information] ​

ps -ef|grep -c sshd [find the number of processes] ​

tail command The tail command can be used to view the content of the file. There is a common parameter -f that is often used to view the log file that is changing.

tail -f txtfile.txt [dynamically display the last content of the document, generally used to view the log]​

The less command The     less command is also used to view files, but it is suitable for viewing text files with more content. It can also be used to display file content on a split screen. Only one page of content is displayed at a time, which is similar to our paging query.

less txtfile.txt [View large file]​

1. Full screen navigation

ctrl + F - move forward one screen

ctrl + B - move backward one screen

ctrl + D - move forward half screen

ctrl + U - move back half a screen

2. One-line navigation

j - move forward one line

k - move backward one line

Eight, text processing

echo​ The function of the echo command is to display a piece of text on the display, which generally acts as a prompt. The general format of this command is:

echo [ -n ] string

echo string将字符串输出到控制台 ,

echo redirection

       Command: 1.echo "what you want" > filename

                     Overwrite the desired content to the corresponding file, the previous content in the file no longer exists, and the content of the original file is actually modified.


                   2.echo "what you want" >> filename

                     After appending the desired content to the file, the previous content of the file is not modified, but only added, which is also called append redirection.

 

Pipes        Pipes are an important concept in Linux commands, their role is to use the output of one command as the input of another command

ls --help | less paginated query help information 

ps –ef | grep java Query processes that contain java in their names

awk         AWK is a language for processing text files and is a powerful text analysis tool

cat czbk-txt.txt | awk '/zhang|li/' [search for student grades with zhang and li]

soft connection

ln -s target file absolute path shortcut path

find find      find command is similar to global find in Windows

find <specified directory> <specified condition> <specified content> 

find / -name 'czbk' [/ represents a full search, you can also specify a directory search ]

read command      The read command is used to read values ​​from standard input like a java keyboard entry Scanner object.

#!/bin/bash

echo "Please enter the website name: "

#read input from keyboard

read website

echo "The website name you entered is $website"

exit 0 #exit

Nine, backup compression

gzip Command    The gzip command is used to compress files. gzip is a widely used compression program. After the file is compressed, the extension of ".gz" will be added after its name.

Syntax: gzip [parameter] [file or directory] 

gzip * [compress all files]

gunzip command    The gunzip command is used to decompress files.

Syntax: gunzip[parameter][file or directory]

gunzip 001.gz [unzip file]

tar Command    The main function of tar is to pack, compress and decompress files. tar itself has no compression capabilities. He is achieved by calling the compression function.

Syntax: tar [required parameter][optional parameter][file]

tar -cvf txt.tar txtfile.txt [pack the txtfile.txt file (pack only, not compress)]

tar -zcvf txt.tar.gz txtfile.txt [pack and compress the txtfile.txt file (pack compression (gzip))]

tar -ztvf txt.tar.gz [see what files are in tar]

tar -zxvf /home/itcast/ysFiles/txt.tar.gz [unzip]

zip command    The zip command is completely equivalent to right-clicking the file under Windows to compress it

unzip command   The unzip command is completely equivalent to right-clicking the file under Windows to decompress it

The bzip2     bz2" format is another Linux compression format. In theory, the ".bz2" format has a more advanced algorithm and a better compression ratio; while the ".gz" format we learned above is relatively faster.

bunzip2      The Linux bunzip2 command is an unzip program for .bz2 files.

Summarize:

gz: A file compressed by the gzip compression tool.

.bz2: A file compressed by the bzip2 compression tool.

.tar: The file packaged by the tar packager (tar has no compression function, it just merges a directory into one file)

.tar.gz: It can be understood as being packaged by tar first and then compressed by gz.

.zip: can be understood as directly compressed by the zip compression tool

10. Network and Disk

ifconfig command​ ifconfig [used to display or set network devices]

Ping command​ ping www.baidu.com [check whether it is connected to the host]

netstat command netstat -a [show detailed connection status] netstat -i [show network card list]

lsblk command​ Use the lsblk command to display information about all devices in the form of a tree

df command The df command is used to display the disk usage statistics of the file system currently on the Linux system.

mount command The mount command is used to mount files outside the Linux system.

firewall

systemctl status firewalld View current firewall status

systemctl stop firewalld shuts down the current firewall.

systemctl disable firewalld The firewall does not start at boot.

NIC restart

1. ifdown/ifup
ifdown eth0 unload the network card
ifup eth0 load the network card

2. ifconfig
ifconfig eth0 down to uninstall the network card
ifconfig eth0 up to load the network card

3. The command network
/etc/init.d/network restart is to restart the entire network . After restarting, you need to log in to the server again, which is troublesome. You can use nohup /etc/init.d/network restart &


4.service network restart 或者  systemctl restart network

 

 

Eleven, software installation

Installation category :

  1.  The binary release package software has been compiled, packaged and released for the specific platform, just decompress and modify the configuration.
  2. The RPM package software has been packaged and released according to redhat's package management tool specification RPM. It is necessary to obtain the corresponding software RPM release package, and then use the RPM command to install it.
  3. The Yum online installation software has been packaged in the RPM specification, but it has been released on some servers on the network. You can use yum to install the rpm software on the server online, and it will automatically solve the library dependency problem during the software installation process.
  4. The source code compilation and installation software is released in the form of a source code project. After obtaining the source code project, it needs to be compiled, packaged and deployed with the corresponding development tools.

yum online installation

yum install software name

rpm package installation

  1.     rpm can only install rpm packages that have been downloaded to the local machine
  2.     rpm -ivh software full package name [install rpm package]
  3.     rpm -e software full package name [uninstall rpm package]
  4.     rpm -qa [list all installed rpm packages]
  5.     rpm -qi software full package name [query package information]
  6.     rpm -ql software full package name [View package installation location]

Source code installation
    Compile the source code before installation. For example: nginx software
binary package installation
and     decompression can be used. For example, tomcat software

Open publicly accessible ports 

See here  https://blog.csdn.net/weixin_49328005/article/details/108284170

Set development port

firewall-cmd --zone=public --add-port=8080/tcp --permanent

Resetting the settings will not fail

firewall-cmd --reload

Take a look at all open ports in the public area

firewall-cmd --zone=public --list-ports

 

Guess you like

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