Linux commands commonly used to learn

1.ls command

 The ls command can not only view the files contained in the linux folder, but also view file permissions (including directories, folders, file permissions), view directory information, and so on.

Common parameters

ls- a lists all files in the directory, including hidden files starting with. 
ls - A lists other files except. and .. 
ls - r sorts in reverse order 
ls - t sorts by file modification time 
ls - S sorts by file size 
ls - h displays 
ls -l in easy - to-read size In addition to the file name, it also lists the file permissions, owner, file size and other information in detail

2.mkdir command

The mkdir command is used to create folders.

Common parameters

- m: New directory is provided for access, may be provided with the chmod command;
 -p: may be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create those directories that are not there, that is, multiple directories can be created at one time.
mkdir t creates a folder named t in the current working directory
mkdir - p / tmp / test / t1 / t Create a directory with the path test / t1 / t in the tmp directory, if it does not exist, create it

3.cp command

Copy the source file to the target file, or copy multiple source files to the target directory.

- i Tip
 - r copy all the items in the catalog and directory
 -a copy of the original file with the same file time

Copy a.txt to the test directory, keep the original file time, if the original file exists prompt whether to overwrite.

cp -ai a.txt test

4.cat command

1. Display the entire file at once: cat fileName

2. Create a file from the keyboard: cat> fileName can only create new files, not edit existing files.

3. Combine several files into one file: cat fileName1 fileName2> newFile

parameter

- b line number of non-null outcome
 -n output all line numbers

Add log1.log file content to the log.log file after adding the line number

cat -n log1.log log.log

 Append the content of log1.log and log2.log to the newlog.log after adding the line number (the blank line is not added)

cat -b log1.log log2.log newlog.log

5.less command

less is similar to more, but you can use less to browse files at will, and more can only move forward, but not backwards, and less will not load the entire file before viewing.

Common command parameters:

- case ignore search when i
 - N line number of each row
 -o <filename> content less output saved in the specified file
 - S continuously displayed empty behavior line
 / string: Search down "string Function of "? Character string: function of
 upward search for" string " 
n: repeat previous search (related to / or? ) 
N: repeat previous search in reverse (related to / or? )
 -X <number> will" The tab key is displayed as a specified number of spaces 
b Turn one page 
backward d Turn half a page backward 
h Display the help interface 
Q Quit the less command 
u Scroll half a page 
forward y Scroll a line forward 
Scroll a line with the 
Enter key Scroll a page 
[pagedown]: turn down one page

ps View process information and display it through the less tab: ps - aux | less - N

View multiple files: less 1.log 2.log

You can use n to view the next one, and p to view the previous one.

5.head command

head is used to display the beginning of the file to standard output. The default head command prints the first 10 lines of the corresponding file.

Common parameters:
-n <number of lines> display the number of lines (the number of lines is a complex number from the last forward)

Display the first 20 lines in the 1.log file: head 1.log - n 20

Display the first 20 bytes of the 1.log file: head-c20 log2014 . Log

Display the last 10 lines of t.log: head-n-10 t . Log

6.tail command

Used to display the content at the end of the specified file. When the file is not specified, it is processed as input information. Commonly used to view log files.

Common parameters:

- F read cycle (commonly used in view of increasing log file)
 -n <line number> shows the number of rows (from back to front)

7.wc command

wc (word count) function is to count the number of bytes, words and lines in the specified file, and output the statistical results

wc [ option ] file ..
parameter type
- C the number of bytes
 - L counts the number of lines
 - m counts the number of characters
 Number -w statistics word, a word is defined as spaces, tabs, or newline character string delimited

Count the number of output lines

cat test.txt | wc -l

8.ps command

ps (process status), used to view the current running process status, one-time view, if you need dynamic continuous results, use top

The ps tool identifies five status codes for a process:

D uninterruptible sleep (usually IO) 
R runnable (on run queue) 
S interrupt sleeping 
T stop traced or stopped 
Z zombies a defunct (“zombie”) process

Command parameters

- A show all processes 
a show all processes
 - a display terminal all the same processes 
c show real name Process 
e display environment variables 
f shows the relationship between the process 
r the current terminal display processes running
 -aux show all the other processes use comprising

Examples: (1) Display all current process environment variables and inter-process relationships ps -ef

(2) Display all current processes ps -A

(3) Combine with grep to find a process    ps - aux | grep apache

(4) Find out the PID numbers related to the two services cron and syslog   ps aux|grep '(cron | syslog)'

9.top command

Display information about processes currently being executed by the system, including process ID, memory usage, CPU usage, etc.

10.kill command

Send the specified signal to the corresponding process. Unspecified model will send SIGTERM (15) to terminate the specified process. If you can't terminate the program, you can use the "-KILL" parameter, and the signal it sends is SIGKILL (9), which will force the process to end. Use the ps command or jobs command to view the process number. The root user will affect the user's process, non-root users can only affect their own processes.

Common parameters:

-l signal, if the signal number parameter is not added, the " -l" parameter will list all signal names
 - a When processing the current process, the correspondence between the command name and the process number is not limited
 - p specifies the kill command only Print the process number of the relevant process without sending any signal
 - s specifies sending signals
 -u specifies users

First use ps to find the process pro1, then kill it with kill

   kill - 9 $ ( ps - ef | grep pro1 )

11.free command

Display system memory usage, including physical memory, interactive area memory (swap), and kernel buffer memory.

Common parameters

- B shown in Byte memory usage
 - K kb in units of display memory usage
 - m in the display unit of mb memory usage
 - G gb Displays in memory usage
 -s <interval in seconds> Length display memory
 -t Show total memory usage

Display memory usage

free , free -k,  free -m

Display memory usage information as a sum

free -t

Query memory usage periodically

free -s 10

 

Guess you like

Origin www.cnblogs.com/seedss/p/12752568.html