Re-recognize common commands under Linux

1. Document viewing : cat, tac, more, less, head, tail, cut, od, nl
2. File permissions : ls -l, chmod, umask
3. File search : find, whereis, locate, which
4. Program management : jobs, bg, fg, kill, killall, ps, pstree, top, free, nice, renice
5. Switch machine : sync, shutdown, halef, poweroff, reboot, init
grep, awk, sed

Document view

cat: view all documents at one time, cannot turn pages, cannot modify
tac: similar to cat, but display forward from the last line
nl: output with line number
more: can page down
less: can page up
head: Display the first few lines of the document, default 10 lines head -n
tail: display the last few lines of the document, default 10 lines tail -n
od: read the file in binary mode

Document permissions

View documentation permissions ls -l

[lala@localhost day01]$ ls -l a.out
-rwxr-xr-x. 1 root root 5314 Jan 28 06:40 a.out
//依次为 文件类型(-:普通文件) 3组文件权限 硬连接数(1) 文件拥有者 文件所属群组 文件的最后修改时间 文件名

Modifying
file permissions generally include read, write, and execute

The access permissions of the above a.out file are: rwxr-xr-x is divided into 3 groups, which are the file owner, the group to which the file belongs, and the permission
rwx of other users to the file can be regarded as 111 binary, with 8 The hexadecimal representation is 7, so the file permissions can be modified in the following ways

[root@localhost day01]# chmod 777 a.out
[root@localhost day01]# ls -l a.out
-rwxrwxrwx. 1 root root 5314 Jan 28 06:40 a.out
[root@localhost day01]# 

Of course, it can also be displayed to specify that
u represents the owner of the file,
g represents the group to which the file belongs ,
o other
a all

[root@localhost day01]# chmod g-w a.out  //chmod u+(或者-或者=)权限 
[root@localhost day01]# ls -l a.out
-rwxr-xrwx. 1 root root 5314 Jan 28 06:40 a.out

Permission mask word umask When the permission bit is 1, the permission is blocked by default

[root@localhost day01]# umask
0022  //默认屏蔽 g和o的 w权限
[root@localhost day01]# umask -S
u=rwx,g=rx,o=rx

Find and locate files

find: find the specified path
whereis: find the default location of
the system locate: find the file database of the system
which: find the specified file only in the environment variable

Program management

A brief understanding of programs and processes
Program: generally stored in the media (disk, CD-ROM) in the form of physical documents,
process: the program being executed, occupying memory
Each process has a process ID (process ID) assigned by the system, and Associated with the user (user ID) that started the process.
Users can query the status of all processes, but can only control their own processes, such as sending signals to processes, restarting or terminating processes, and superusers can control all processes.

A simple understanding of the calling process of commands in bash:
first fork a child process, then call exec to let the child process execute its command, call exit after the task is completed, and then continue to execute the parent process.

Linux multi-user, multi-task environment
Multi-user: There can be multiple users under Linux, and each user has different permissions. The process ID of the shell obtained by each user after logging in to Linux is different, so different login environments can be set for different users.
Multitasking: All competing processes can reasonably share resources. When multiple users log in to Linux, the system seems to serve you alone.

Process management
ps: View process status information
pstree: Display the calling relationship between processes in the form of tree indentation
top: Monitor process status information in real time
nice, renice: Adjust process priority information
free: View system resources

Common parameters after ps:
-l display detailed status information of the
process -a display active processes
-e display all processes
-f display important status information of the process
generally use ps -l and ps -ef

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  5224  2362  0  80   0 -  2096 -      pts/0    00:00:00 su
4 S     0  5230  5224  0  80   0 -  1315 -      pts/0    00:00:00 bash
4 S     0  5325  5230  0  80   0 -  1315 -      pts/0    00:00:00 bash
4 R     0  5418  5325  0  80   0 -  1219 -      pts/0    00:00:00 ps

F: Represents the flag of this program, indicating the summary permissions of this program. Common numbers are
4: root
1: Indicates that this child process only performs replication (fork) but does not execute (exec)
S: Represents the status of this program
R: The program is running Running (Running)
S: Sleep state, can be woken up (signal)
D: Can't be woken up
T: Stop state
Z: Zombie state
C: Represents CPU usage
PRI /NI: Program execution priority
ADDR/SZ/WCHAN: All are related to memory, ADDR represents the part of the program in the memory, - represents running, SZ represents the memory where the program is running, WCHAN represents whether the program is running, if - represents running
TTY: the terminal location of the login person
TIME this program Actual CPU time spent

top:
The difference from the ps command is that top dynamically observes the operating status of the program.

free
observes memory usage.

Guess you like

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