Basic command explanation



  • 1. Preface
  • 2. Command operation syntax format of Linux system
    • 2.1 create a directory / Oldboy
    • 2.2 view directory / Oldboy
    • 2.3 change current directory / location
    • 2.4 print current working directory
    • 2.5 create file or modify file timestamp (file attribute)
  • 3.stat command
  • 4.vim
    • 4.1 view document content
    • 4.2more command
    • 4.3 Linux shortcut key
    • 4.4 echo command
    • 4.5 special symbols
    • 4.6 copy command
    • 4.7 move command
    • 4.8 delete command
    • 4.9 find command
    • 4.10 pipeline command
    • 4.11 alias command
    • 4.12 setting alias for RM
    • 1.13 which order
    • 4.14scp command
    • 4.15du command
    • 4.16top command
    • 4.17chattr command
    • 4.18lsattr command
    • 4.19 common problems for children’s shoes:
  • 5. Linux time synchronization
  • 6. Calendar command
  • 7. NTP time server
    • 7.1wget command
  • 8. On off command

1. Preface

The structure of Linux command line

[[email protected]_python ~]# 
			[[email protected]_python ~]# 
			[[email protected]_python ~]# 
			[[email protected]_python ~]# 
[[email protected]_python ~]#

Basic command explanation

2. Command operation syntax format of Linux system

command Blank space parameter Blank space [file or path] content to be processed
rm -rf /tmp/*
ls -la /home
marry -No car, no room Women will do.
marry -Car and room White, rich and beautiful girl

1. In general, parameter is optional, and in some cases, file or path is also optional

2. Parameters > the same command, keep up with different parameters to perform different functions

The purpose of executing linux commands and adding parameters is to make the commands more suitable for actual work!

Linux commands, parameters between the general should be separated with one or more spaces!

2.1 create a directory / Oldboy

Under Windows:

Right click > new folder


make directory > mk dir > mkdir-------------------------------
			mkdir /oldboy-------------------------------
			cd /
MKDIR Oldboy ා recursively create a / B C / dmkdir - P A / B C / D ා recursively create test / A, B, C, D four directories MKDIR - P test / {a, B, C, D} ා recursively create folder a / B / C / D / emkdir - P A / B / C / D / E

2.2 view directory / Oldboy

#Display content under / Oldboy
ls /oldboy

2.3 change current directory / location

cd /home
			cd ~
cd -

2.4 print current working directory

#Print current working directory

2.5 create file or modify file timestamp (file attribute)

Create text

Modification time of modified file

#To modify the file change time, many hackers will modify the file to the previous time LS - L echo 'sb' > > XXX. Pytouch - t'07101530 '1.txt

3.stat command

Displays the status of a file or file system.
			#Usage stat [parameter] file parameter list:
			-50. -- Reference follows the link - F, - file system displays the file system status instead of the file status - C -- format = format uses the specified output format instead of the default value, and each time a new line is changed with the specified format -- printf = format is similar to -- format, but the backslash escape character will be interpreted instead of using the new line as the output end. If you still want to use newline, you can add "\ n" - t, -- terse to the format to output -- help to display this help information and exit -- version to display version information and exit
			Format output parameters:
			%A octal permission% a output permission in a readable way
			#Instance 1 [root @ master TMP] ා stat 1.txt
			File: '1.txt'
			Size: 0             Blocks: 0          IO Block: 4096   regular empty file
			Device: fd00h/64768d    Inode: 17348002    Links: 1
			(permission) access: (0644 / - rw-r -- R --) uid: (0 / root) GID: (0 / root)
			(recent visit) access: 2018-07-10 15:30:00.000000000 + 0800
			(latest change) modify: 2018-07-10 15:30:00.000000000 + 0800
			(latest change) change: 2018-11-07 15:38:36.400989868 + 0800
Birth: - instance 2, display file permission

[[email protected] tmp]# stat -c %a 1.txt
[[email protected] tmp]# stat -c %A 1.txt


All UNIX like systems will have built-in VI document editors, while other document editors may not exist.

But now we use VIM editor more often.

VIM has the ability of program editing. It can distinguish the correctness of syntax by font color, which is convenient for program design.

#Method, command
			Use VI to open The default is command mode. Enter a / I to enter editing mode, and then enter the text "life is short, I use Python"
			Press ESC to return to command mode
			Input: W q! Force save exit w write write Q quit! Force
Or: X save exit ------: Q don't save exit: q! Don't save force exit

4.1 view document content

The cat command is used to view plain text files (often used for less content)

#View the file, display the line number cat - n, and view the file
Cat ා add the $sign at the end of each line [root @ master TMP] ා cat - e 1.txt ා append the text to the file cat > > / TMP / oldboy.txt < < EOF pump / Mulan what aircraft Boeing 747 EOF

4.2more command

1. The more command is used to view more content text. For example, to see a long configuration file, the cat view content screen will quickly scroll to the end.

2. The more command will tell you in percentage how much you have seen. Use the Enter key to read down the content

More / etc / passwd press space, turn page, press B, and press enter on the previous page to read down

4.3 Linux shortcut key

1. The tab key is used to automatically complete the command / filename / directory Name2. Ctrl + L cleaning terminal display3. Clear / CLS cleaning terminal display4. Ctrl + C terminating the current operation

4.4 echo command

The echo command is used to output the value after string or variable extraction at the terminal. The format is “echo [string | $variable]”

#Display the content on the terminal by default    
			Echo "super brother 666"
			#超哥平时比较低调,不想让别人知道他666,怎么办?要么把“超哥666”写入到文件里!Echo "super brother 666" > /tmp/chaoge.txtecho $PATH 
#Take out the value of print path

4.5 special symbols

Input / output redirection symbol 1. > > append redirection, append text to the end of the file
			2. > redirection symbol, clear all contents of the original file, and then overwrite the text to the end of the file. 3. < input redirection 4. < input redirection echo "oldboy-python666" > / TMP / Oldboy. Txtecho "chaoge666" > / TMP / Oldboy. Txtcat > > / TMP / Oldboy. Txt < < EOF
------------------------------------I want to write the result information of command execution into the file IP addr > / TMP / network.txt ා standard output redirection put the result information of command execution into the file 3. Wildcard LS - L / etc / us*

4.6 copy command

Windows replication

It's pretty simple
			CTRL + C copy
CTRL + V paste

Basic command explanation

Copy > CP ා move to / tmp directory
CP / TMP / ා move and change its name to chaoge.pycp There are many commands below. Generally, there is no way to directly process folders. Therefore, it is necessary to add (parameter) cp-r recursion to copy directories and their descendants cp-p to copy files. At the same time, keeping the file properties unchanged, you can use statcp-a to copy the test folder recursively, which is test2 CP - R test test2cp is a good command. Before operating files, back up CP

4.7 move command

What? Move command?

Basic command explanation

Move command > move > MV

			CD / home move the old boy from the shabby place of Shahe to Chaoyang
MV / home / Shahe / Oldboy / TMP / Chaoyang file / folder renamed MV x.log xx.log

4.8 delete command

Delete > remove > RM parameter - I need to delete confirmation - f force delete - R recursively delete directory and content     
			cd /tmp
			#There is a prompt to delete by default. You need to enter y
RM - F - no prompt is needed. Forced deletion is not allowed by default. You need to keep up with the parameter - RRM - RF / TMP / Oldboy / - -------- friendly reminder: beginners use RM command to snapshot virtual machines at any time

4.9 find command

#How to find the required file in Linux, such as
			Where to find (directory), what type (file type), what name (file name) parameter
			-Name find files by file name
			-Type to find a type of file, such as: B - block device file. D - directory. C - character device file. P - Pipeline file. L - symbolic link file. F - general documents. S - socket file
Find / TMP / - type F - name "Oldboy. Py" ා find out / tmp all files ending in. TXT find / TMP / - type F - name "*. TXT" ? find all files starting with host under / etc find / etc - name 'host *' ා find / opt the previous one named settings.pyfind / opt - name 'settings. Py'

4.10 pipeline command

The pipe character "|" provided by Linux means that two commands are separated. The output of the command on the left side of the pipe character will be the input of the command on the right side of the pipe character.
			Common usage:
			#Check whether Python program starts
PS - ef| grep "Python" ා find all the txt files in the / tmp directory LS / tmp| grep '. TXT' ා check whether the ports of nginx survive netstat - tunlp| grep nginx

Command format: command a | command B

Basic command explanation


Global search regular expression (RE) and print out the line is a powerful text search tool, which can use regular expression to search text and print out matching lines.

Syntax: grep [parameter] [-- color = auto] [string] filename parameter details: - I: ignore case - N: output line number - V: reverse selection -- color = Auto: add color to keyword section grep "what I'm looking for" / TMP / oldboy.txt
			#Rule out - V, rule out what I'm looking for
Grep - V "what am I looking for / TMP / oldboy.txt

For example, find out the line of root user under / etc / passwd, as well as the line number and display color

cat /etc/passwd |grep '^root' --color=auto -n

Find out all users of / etc / passwd who are not allowed to log in

grep /sbin/nologin /etc/passwd

Find all MySQL related lines and line numbers of / etc / passwd

cat /etc/passwd |grep 'mysql' -n

Head and tail commands

Head displays the first few lines of the file, the first 10 lines by default, tail displays the last few lines of the file, and the last 10 lines by default
			#View the first two lines
			head -2 /tmp/oldboy.txt
			#View the last two lines
			tail -2 /tmp/oldboy.txt
#Continuously refresh the display tail - f XX. Log ා display file 10-30 lines head - 30 / TMP / Oldboy. TXT | tail - 21

4.11 alias command

Linux must be very careful when using RM (delete), CP (overwrite), MV (move) and other commands, because these commands are “bombs”, presumably everyone has heard “delete library to run”, which is not “RM RF /”, if you do, then… God bless you

Basic command explanation

How does Linux prompt you to be careful when using these commands?
			#View system aliases
Alias default alias

alias cp=’cp -i’
alias egrep=’egrep –color=auto’
alias fgrep=’fgrep –color=auto’
alias grep=’grep –color=auto’
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mv=’mv -i’
alias rm=’rm -i’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’

Aliases are used to:

When we use CP in Linux, we execute cp-i
-i: Ask users before deleting existing files or directories;

#Alias is a dangerous operation to prevent you from making mistakes

4.12 setting alias for RM

#Let the system display do not use RM
			echo do not use rm
			#Set RM alias
Alias RM ='echo do not use RM 'ා set the alias to take effect permanently, write it to / etc / profile (set the environment variable for the contract of the login user) VIM / etc / profile ා edit the file g quickly to the last line o the next line of the current line, create a new line, enter the editing mode source / etc / profile ? read the file (the contract takes effect) ---------- cancel the alias unalias RM

1.13 which order

Which command is used to find and display the absolute path of a given command. The path environment variable holds the directory to traverse when finding the command. The which instruction looks for the eligible files in the directory set by the environment variable $path. That is to say, with which command, you can see whether a system command exists and where the command is executed. which pwdwhich python


which python       
			#Where is the python command
#Command file absolute path

4.14scp command

The Linux SCP command is used to copy files and directories between Linux.

SCP is the abbreviation of secure copy. SCP is a remote file copy command based on SSH login in Linux system.

SCP [optional parameters] local source file remote file flag


-R: recursively copy the entire directory
			-v: Detailed mode output
			-q: Do not show transfer progress bar
-C: Allow compression


#Transfer local file to remote address
			SCP local file remote user name @ remote IP: remote folder/
			SCP local file remote user name @ remote IP: remote folder/远程文件名

			scp /tmp/ [email protected]:/home/
			scp /tmp/ [email protected]:/home/

			SCP - R local folder remote user name @ remote IP: remote folder/
			scp -r /tmp/oldboy [email protected]:/home/oldboy

			#Copy remote files to local
			scp [email protected]:/home/oldboy.txt /tmp/oldboy.txt
scp -r [email protected]:/home/oldboy /home/

4.15du command

The Linux Du command displays the size of the directory or file.

Du displays the disk space occupied by the specified directory or file.

Du [parameter] [file or directory] - s display total - H display in K, m and G, with strong readability


Display space occupied by directory or file
			#Nothing to follow, indicating that all file sizes of the current directory are displayed

			#Display the total size of / home
du -sh /home

4.16top command

The top command is used to dynamically monitor information such as process activity and system load

Basic command explanation

Let’s analyze the picture information

Statistics area

First line (uptime)
			System time host running time user connections (who) average load of system 1, 5, 15 minutes
			Line 2: process information
			Total processes running processes sleeping processes stopping processes zombie processes
			Line 3: CPU Information
			1.5 us: percentage of user space in CPU
			0.9 sy: percentage of CPU occupied by kernel space
			0.0 Ni: the percentage of CPU occupied by the process with priority changed in the user's process space
			97.5 ID: idle CPU percentage
			0.2 Wa: percentage of CPU time waiting for input and output
			0.0 hi: Hardware CPU interrupt percentage
			0.0 Si: soft interrupt percentage
0.0 ST: percentage occupied by virtual machine

Line 4: memory information (similar to the information in line 5 and the free command)

  • 8053444 total: total physical memory
  • 7779224 used: total memory used
  • 274220 free: total free memory (free + used = total)
  • 359212 buffers: amount of memory used as kernel cache
Line 5: swap information
			8265724 total: total number of swap partitions
			33840 used: total used swap partitions
			8231884 free: total free swap area
4358088 cached MEM: the total number of buffered swap areas. The contents of the memory are swapped out to the swap area, and then swapped in to the memory. However, the used swap area is not covered. These contents of the swap area already exist in the size of the swap area in the memory. When the corresponding memory is swapped out again, it is unnecessary to write to the swap area.

4.17chattr command

Lock the file. Only data can be written, and the file cannot be deleted

chattr +a test.pychattr -a

4.18lsattr command

View file hidden properties


4.19 common problems for children’s shoes:

Question 1: yudanl: ~ Yuchao $CD~
-bash: cd~: command not found

Basic command explanation

Q2: yudanl: ~ Yuchao $CD / Oldboy
-bash: cd: /oldboy: No such file or directory

Basic command explanation

5. Linux time synchronization

Linux date command can display current time or set system time

View current time

Basic command explanation

Format output

-D -- date = string displays the specified time instead of the current time. The current time is displayed as year month day. Date + ""% Y -% m -% d ""
			"Display current time date +" "% Y -% m -% d% T" "in mm / DD / yyyy"
Under Linux, the system time and hardware time will not be automatically synchronized. During the running process of Linux, the system time and hardware time run asynchronously without mutual interference. Hardware time is run by BIOS battery, while system time is maintained by CPU tick. When the system is powered on, the hardware time will be obtained from the BIOS and set as the system time

Hardware always view

[[email protected]_python ~ 10:19:04]#hwclock
Monday, August 27, 2018 10:23:03-0.528004

To synchronize system time and hardware time, you can use the hwlock command

//Modify hardware time based on system time
			[[email protected]_python ~ 10:29:07]#hwclock -w

			//Modify system time based on hardware time
[[email protected]y_python ~ 10:29:21]#hwclock -s

6. Calendar command

Cal command

Calendar – y view the calendar of the year

yugoMBP:~ yuchao$ cal
			March 2019
			Su Mo Tu We Th Fr Sa
			1  2
			3  4  5  6  7  8  9
			10 11 12 13 14 15 16
			17 18 19 20 21 22 23
			24 25 26 27 28 29 30

7. NTP time server

Time is essential to human beings. Time is money. Therefore, it is very important to control the server time. If the system time is not right, the operation of each file is wrong.

The configuration files of time server are as follows

/Bin / date is the instruction for modifying and displaying Linux time (software clock). / SBIN / hwlock is the instruction for modifying and displaying BIOS clock (hardware clock). This is an instruction that can only be executed by root. Because the BIOS time on the Linux system is separate from the Linux system time, after adjusting the time with the date instruction, you need to use hwlock to write the modified time into the BIOS! /Usr / SBIN / ntpd: it mainly provides NTP services! The configuration file is / etc / ntp.conf/usr/sbin/ntpdate: used for client-side time correction. If you don't want to enable NTP but only want to use NTP client function, you will only use this command!

Because we only need to use as client update time

ntpdate -u

7.1wget command

WGet command is used to download network files at terminal
			The parameter is WGet [parameter] download address
WGet - R - P ා Download all resources of Luffy recursively and save them in the file

8. On off command

The reboot command is used to restart the machine
Poweroff is used to shut down the system