In Linux, how does one view, kill, and start processes? (Common commands), common linux commands
Keywords: linux Process query, killing process, Starting Process
1. Check the process
Ps command to find the process-related PID:
Ps a shows all programs under the current terminal, including those of other users.
Ps-A shows all programs.
When listing programs in ps c, the real command name of each program is displayed without the path, parameter, or resident service identifier.
The effect of this parameter is the same as that of the specified "A" parameter.
When listing programs, ps e displays the environment variables used by each program.
Ps f uses ASCII characters to display the tree structure and express the relationship between programs.
The ps-H tree structure is displayed, indicating the relationship between programs.
Ps-N displays all programs except the programs under the ps command terminal.
Ps uses the program signal format to display the program status.
When listing programs in ps, it includes interrupted subroutines.
Ps-t <terminal number> specifies the terminal number and lists the program status of the terminal.
Ps u displays the program status in user-based format.
Ps x shows all programs, not distinguished by terminals.
The most common method is ps aux. Then, use the grep command in the pipeline to filter out specific processes, and then perform operations on specific processes.
Ps aux | grep program_filter_word, ps-ef | grep tomcat
Ps-ef | grep java | grep-v grep shows all java processes and removes the current grep process.
2. Kill processes
Run the kill command to end the process: kill xxx
Commonly used: kill-9 324
In Linux, A killall command is also provided to directly use the process NAME rather than the process ID number, for example: # killall-9 NAME
3. Enter the path where the execution file of the process is located, and the execution file./file name
Appendix:
It took me two days to sort it out, and some of the most common commands that people on earth know would be skipped! Pdf manual download
Change archive owner
Command: chown [-cfhvR] [-help] [-version] user [: group] file...
Function: Change the owner of a file or folder.
Parameter format:
User: user IDgroup of the new owner: user group of the new owner)
-C: If the archive owner has changed, the change action is displayed.
-F: If the archive owner cannot be changed, do not display an error message.
-H: only the link is changed, not the file actually pointed to by the link.
-V: displays the details of the owner's changes.
-R: Change the owner of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)
For example: chown-R oracle: oinstall/oracle/u01/app/oracle
Change the directory owner to oracle
Modify permissions
Command: chmod (change mode)
Function: Change the read/write and execution permissions of a file. The signed method and the octal digit method.
Option: (1) Symbolic method:
Command Format: chmod {u | g | o | a} {+ |-| =}{ r | w | x} filename
U (user) indicates the user himself.
G (group) indicates the same group of users.
O (oher) indicates other users.
A (all) indicates all users.
+ Permission granted to a specified user.
-Cancels the permission granted to a specified user.
= Grant the permitted permissions to the file.
R (read) indicates that the content of the file or directory can be copied.
W (write) write Permission indicates that the content of the file or directory can be modified.
X (execute) indicates that you can execute the file or enter the directory.
(2) octal digit method:
Command Format: chmod abc file
A, B, and c each have an octal number, indicating the permissions of the User, Group, and Other respectively.
4 (100) indicates readable.
2 (010) indicates writable.
1 (001) indicates executable.
If you want the rwx attribute, 4 + 2 + 1 = 7;
If the rw-attribute is required, 4 + 2 = 6;
If you want the r-x attribute, 4 + 1 = 5.
Example: # chmod a + rx filename
Allows all users to read and execute file filename.
# Chmod go-rx filename
Cancel the read and execute file filename permissions of the same group and other users.
# Chmod 741 filename
Enable read/write execution by myself, readable by users in the same group, and executable file filename by other users.
Chmod-R 755/home/oracle
Recursively Change directory permissions. users in the same group can read and write, and other users can read and write.
File modification date
Command: touch
Format: touch filenae
Function: changes the date of a file. The file content is not modified. If the file does not exist, a new file is created.
Example: % touch file
Link file
Command: ln (link)
Format: ln [option] filename linkname
Ln [option] directory pathname
Function: Creates a chain for a file or directory. Here, filename and directory are the source file names and
Source directory name; linkname and pathname indicate
File or directory.
Option:-s creates a symbolic link for a file or directory. If-s is not added, a hard link is created for the file or directory.
Note: The purpose of the link is to assign more than two names to a file or directory so that it can output
In different directories, files or directories can be shared and disk space can be saved.
Example: % ln-s filename linkname
Display date
Command: date
Example: % date
Show Calendar
Command: cal (calendar)
Format: cal [month] year
Function: displays the specified calendar for a year.
Example: % cal 1998
Show File Header
Command: head
Format: head [option] filename
Function: displays the file header.
Option: the first 10 lines of the file are displayed by default.
-I: displays the start line of the file.
Example: % head filename
Show file tail
Command: tail
Format: tail [option] filename
Function: displays the end of a file.
Option: the last 10 lines of the file are displayed by default.
-I: displays the last line of the file.
+ I is displayed from row I of the file.
Example: % tail filename
Show user ID
Command: id
Format: id [option] [user]
Function: displays the user ID and all groups to which the user belongs.
Option:-a displays the user name, user ID, and all groups to which the user belongs.
Note:
Example: % id username
View currently logged-on users
Command: users
Shows who logged on to the machine
Command: who
Format: who
Function: displays all usernames in the system. Use the terminal device number and the registration time.
Example: % who
Display the user name on the current terminal
Command: whoami
Format: whoami
Function: displays the users used on the current terminal.
Example: % whoami
Search for files
Command: find
Format: find pathname [option] expression
Function: search for a file that matches the expression under the given path.
Option:-name indicates the file name.
-User Username: select the file to which the user belongs.
-Size: search by size. The unit is block. A block is B.
-Mtime n: search by the last modification time and select the file to be modified within n days
-Perm search by permission
-Type: search by file type
-Atime: search by the last access time
Example: % find./-name 'abc'-print
Search for matching characters in a file
Command: grep
Format: grep [option] pattern filenames
Function: searches the specified file or standard input row by row, and displays each row in the matching mode.
Option: case-insensitive for-I matching
-V: Find out the line with Mode Mismatch
Example: % grep-I 'java * './test/run. sh
Count the number of words in a file
Command: wc [option] filename
Function: counts the number of lines, characters, and characters in a file.
Option:-l number of statistics files
-W: number of words in the statistics File
-C: number of characters in the statistics File
Note: If the default file name is used, standard input is used.
Example: % wc-c./test/run. sh
Display disk space
Command: df (disk free)
Format: df [option]
Function: displays the disk space usage, including the directory name, block device name, and total
The number of bytes, the number of bytes in use, and the percentage of remaining bytes.
Option:
-A: displays the disk usage of all file systems and partitions.
-I: displays the I-nodes usage.
-K: The size is represented by k (default)
-T: displays the disk usage of all partitions in a file system.
-X: displays the disk usage of all partitions of a file system.
-T: displays the file system name of each partition.
-H: indicates the use of "Human-readable" output, that is, the size of the file system is in a readable format such as GB and MB.
Note:
Example: % df-hi
Query the disk space used by an archive or directory
Command: du (disk usage)
Format: du [option] [filename]
Function: displays the disk space occupied by all files in each directory in the unit of subdirectories in the specified directory.
Option:
-A: displays the disk space occupied by all directories and each file in the second directory.
-B: The size is represented by bytes (the default value is k bytes)
-C: add the total value (default value)
-S: Only displays the total size of each file
-X: only calculate the files of the same file system.
-L: calculates the size of all files.
-H: indicates that the file system is in a readable format such as GB and MB.
Example: % du-
% Du-sh/etc only displays the sum of the directories
% Du/etc | sort-nr | sort the more statistical results using the sort command,
The-nr parameter of sort indicates that reverse sorting is performed by numerical sorting.
Display Process
Command: ps
Format: ps [option]
Function: displays information about processes in the system. Including process ID, control process terminal, execution time, and command.
Option:
-A: displays information about all processes.
-U uidlist: list all processes of the user.
-E: displays information about each running process.
-F shows a complete list
-X displays the Process status that is not controlled by the terminal.
Note:
Example: % ps-ef
% Ps-aux then directs to grep with a pipeline symbol to find a specific process, and then operates on the specific process.
Terminate a process
Command: kill
Format: kill [option] pid
Function: sends a signal to a specified process or terminates the process. The purpose of the kill command is to send a signal to a process,
Because most of the messages are sent to kill the SIGKILL or SIGHUP of the process
Option:-9 forcibly terminate a process
Note: The pid indicates the process number, which can be obtained by the ps command.
Example: % kill-9 pid
You can also use kill-l to view the number that can replace signal. For more information about kill, see man kill.
View your own IP Address
Command: ifconfig
Format: ifconfig-
View route table
Command: netstat
Format: netstat-rn
Remote Login
Command: telnet
Format: telnet hostname
File Transfer
Command: ftp (file transfer program)
Format: ftp hostname
Function: network file transmission and remote operations.
Option: ftp command:
Cd [dirname]: Enter the remote machine directory
LCD [dirname] sets the directory of the Local Machine
Dir/ls display remote directory files
Bin is transmitted in binary format.
Asc transfers data as text files
Get/mget fetch one or more files from the remote machine
Put/mput sends one or more files to the remote machine
Interaction prompt when prompt enables or disables multiple file transfers
Close to close the connection to the remote machine
Quit ftp
! /Exit ftp login status ,! Indicates that the ftp is temporarily exited and the local directory is returned. The exit indicates that the ftp status is returned.
Note:
Example: % ftp hostname
View your own email
Command: mailx
Format: mailx
Option:
Delete
Next
Quit exit
Reply
Recall command
Command: history
Format: history
Function: helps users recall executed commands.
Option:
Note:
Example: % history
Online conversation
Command: talk
Format: talk username
Function: chat with another user online.
Option:
Note: During dialog, the system divides the terminal into two parts: the upper half displays the information you typed and the lower half.
Displays the information entered by the other user. Type delete or Ctrl + C to end the dialog.
Example: % talk username
Allow or reject information
Command: mesg (message)
Format: mesg [n/y]
Function: Allows or denies other users from sending messages to their terminals.
Option: n rejects other users from writing information to their terminals.
Y allows other users to write information to their terminals (default)
Note:
Example: % mesg n
Write information to other users
Command: write
Format: write username [ttyname]
Function: write information to terminals of other users.
Option:
Note: If the recipient does not refuse, the dual-user can talk. Type EOF or Ctrl + C to end the conversation.
Example: write username
Create, modify, and delete users and groups
A. Create a group:
For example, groupadd oinstall creates a group named oinstall.
Groupadd-g 344 dba
Create a group with a group number of 344. A group ID (GID) of 344 is generated in the/etc/passwd file.
B. Modify the group:
Groupmod: this command is used to change the attributes of a user group account.
Groupmod-g New GID user group account name
Groupmod-n new group name original group name: This command changes the name of the user group
C. delete a group:
Groupdel group name: this command is used to delete a specified group account.
D. Create a user:
Command: useradd [-d home] [-s shell] [-c comment] [-m [-k template]
[-F inactive] [-e expire] [-p passwd] [-r] name
Main Parameters
-C: add the remarks text. The remarks text is saved in the remarks column of passwd.
-D: Specify the start directory when the user logs on.
-D: Change the default value.
-E: Specifies the validity period of the Account, which is permanently valid by default.
-F: specifies the number of days after the password expires.
-G: Specifies the group to which the user belongs.
-G: Specify the additional group to which the user belongs.
-M: automatically creates a user's logon directory.
-M: do not automatically create a user's logon directory.
-N: cancel the creation of a group named by the user name.
-R: Create a system account.
-S: Specifies the shell used after the user logs on.
-U: Specifies the user ID.
Example: # useradd-g oinstall-G dba oracle creates an Oracle user
E. delete a user
Command: userdel User Name
Deletes a specified user account.
Userdel-r username (userdel username; rm username): deletes the specified user account and home directory.
Example: # useradd-g root kkk // Add the kkk user to the root group
F. modify a user
Command: usermod
Modify existing user information
Usermod-l old username new username: Modify Username
Usermod-L User name: used to lock a specified user account so that it cannot log on to the system
Usermod-U Username: Unlock the Locked User Account
Passwd-d Username: Password-free account, that is, the user can log on to the system without a password
Example: # usermod-l user2 user1 // rename user2 as user1
Enable and disable Firewall
Permanently enabled or disabled
Chkconfig iptables on
Chkconfig iptables off
Immediate effect: Restore after restart
Service iptables start
Service iptables stop
Or:
/Etc/init. d/iptables start
/Etc/init. d/iptables stop
Start VSFTP Service
Instant start:/etc/init. d/vsftpd start
Instant stop:/etc/init. d/vsftpd stop
By default, the VSFTP service is automatically started upon startup:
Method 1: (Common \ convenient)
[Root @ localhost etc] # chkconfig-list | grep vsftpd (View Details)
Vsftpd 0: off 1: off 2: off 3: off 4: off 5: off 6: off
[Root @ localhost etc] # chkconfig vsftpd on (execute ON settings)
Or: Method 2:
Modify the/etc/rc. local file and insert/usr/local/sbin/vsftpd & into the file to enable automatic start upon startup.
Vi skills
A. Enter the input mode.
Add (append)
A: add data from the end of the cursor. The data after the cursor is moved to the backend with the new data.
A: add data at the bottom of the column where the cursor is located.
Insert)
I: insert data from the front of the cursor. The data after the cursor moves to the back as the new data is added.
I: insert data starting from the first non-blank character in the column where the cursor is located.
Start (open)
O: Add a column under the column where the cursor is located and enter the input mode.
O: Add a new column to the column where the cursor is located and enter the input mode.
B. Exit vi.
In command mode, type: q,: q !, : Wq or: x (Note: No.), the vi will be exited. Where: wq and: x are stored and exited, while q is directly exited. If the file has a new change, vi will prompt you to save the file and the q command will also be invalid, in this case, you can use the w command to save the file and then use q to exit, or use the wq or x command to exit. If you do not want to save the changed file, you need to use: q! Command to exit vi without saving the file.
C. Command for deleting and modifying files:
X: Delete the character of the cursor.
Dd: Delete the column where the cursor is located.
R: Modify the character where the cursor is located and the character to be corrected after r.
R: Enter the retrieval and replacement status. The new text will overwrite the original text until you press [ESC] to return to the command mode.
S: Delete the cursor character and enter the input mode.
S: Delete the column where the cursor is located and enter the input mode.
D. Screen tumble commands
Ctrl + u: half screen at the beginning of the file
Ctrl + d: Flip the half screen to the end of the file
Ctrl + f: Flip the screen to the end of the file
Ctrl + B: Flip the screen to the beginning of the file
Nz: Rolls row n to the top of the screen. If n is not specified, the current row is rolled to the top of the screen.
E. delete command
Ndw or ndW: n-1 characters starting at and following the cursor
Do: Delete to the beginning of a row
D $: Delete to the end of the row
Ndd: Delete the current row and the next n-1 row
X or X: delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
Ctrl + u: delete text entered in input mode
F. search and replace commands
/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
: S/p1/p2/g: replace all p1 in the current row with p2.
: N1, n2s/p1/p2/g: replace all p1 from line n1 to line n2 with p2.
: G/p1/s // p2/g: replace all p1 files with p2.
G. copy and paste
(1) Select the text block and use v to enter the visual mode. move the cursor key to select the content.
(2) copy the selected block to the buffer, use y; copy the entire row, and use yy
(3) Cut the selected block to the buffer, use d; cut the entire row with dd
(4) paste the content in the buffer, and use p
H. Others
Open the second file in the same editing window and use: sp [filename]
Switch between multiple editing files and press Ctrl + w.