How to view processes, kill processes, start processes and other common commands in Linux

Keywords: linux Check process, kill process, start process
1. Check process
    ps command to find the PID number related to the process:
    ps a Display all programs under the current terminal, including programs of other users.
    ps -A shows all programs.
    When ps c lists programs, display the actual command name of each program, without the path, parameter, or resident service designation.
    ps -e This parameter has the same effect as specifying the "A" parameter.
    ps e When listing programs, display the environment variables used by each program.
    ps f Use ASCII characters to display a tree structure, expressing the relationship between programs.
    ps -H Displays a tree-like structure, representing the interrelationships between programs.
    ps -N displays all programs, except the programs under the ps command terminal.
    ps s Displays program status in program signal format.
    ps S When listing programs, include interrupted subroutine data.
    ps -t <terminal number> Specifies the terminal number and lists the status of programs belonging to that terminal.
    ps u Displays program status in a user-focused format.
    ps x displays all programs, regardless of terminal.
  
    The most common method is ps aux, and then use the grep command to filter through the pipeline to find a specific process, and then operate on the specific process.
    ps aux | grep program_filter_word,ps -ef |grep tomcat

ps -ef|grep java|grep -v grep Show all java processes, remove the current grep process.
  
2. Kill the process
   Use the kill command to end the process: kill xxx
   Commonly used: kill -9 324
   Linux also provides a killall command, which can directly use the process name instead of the process identification number, for example: # killall -9 NAME

3. Enter to Under the path where the execution file of the process is located, the execution file./file name

Attachment :

This is what I spent two days sorting out, and some of the most commonly used commands that people on earth know are omitted! Finally provide pdf manual download

1. Change file owner
Command : chown [-cfhvR] [--help] [--version] user[:group] file... Function
: Change the owner of a file or folder       user : the user ID of the new file owner group : the user group (group) of the new file owner          -c : if the file owner has indeed changed, only display the change action          -f : if the file owner cannot Don't show an error message even if changed          -h : only make changes to the link, not the file the link actually points to          -v : show the details of the owner change






         -R : Make the same owner change for all files and subdirectories in the current directory (that is, change one by one in a recursive manner).

For example: chown -R oracle:oinstall /oracle/u01/app/oracle 
      Change the owner of the directory to oracle

2. Modify the permission
    command: chmod (change mode)
    function: change the read, write and execute permissions of the file. Signed and octal numbers.
    Options: (1) Notation:
  Command format: chmod {u|g|o|a}{+|-|=}{r|w|x} filename
          u (user) means the user himself.
          g (group) means users in the same group.
          o (oher) means other user.
          a (all) means all users.
          + is used to grant permissions to the specified user.
          - Used to revoke the permission of the specified user.
          = assigns the permitted permissions to the file.
          r (read) Read permission, indicating that the contents of the file or directory can be copied.
          w (write) Write permission, indicating that the contents of the file or directory can be modified.
          x (execute) execute permission, indicating that the file can be executed or the directory can be entered.
 
          (2) Octal number method:  
  Command format: chmod abc file
  where a, b, and c are each an octal number, representing the permissions of User, Group, and Other, respectively.
          4 (100) means readable.
          2 (010) means writable.
          1 (001) means executable.
  4+2+1=7 for rwx attributes;
  4+2=6 for rw- attributes;
  4+1=5 for rx attributes.

    For example: # chmod a+rx filename
            makes the file filename readable and executable by all users.
          # chmod go-rx filename
            cancels the permissions of the same group and other users to read and execute the file filename.
          # chmod 741 filename
            makes the file filename readable and writable by myself, readable by users in the same group, and executable by other users.
  # chmod -R 755 /home/oracle
    recursively changes directory permissions, I can read and write, users in the same group can read and execute, and other users can read and execute

3. Date of modification of the file
    Command: touch
    Format: touch filenae
    Function: Change the date of the file, do not change the content of the file, and create a new file if the file does not exist.
    For example: % touch file

4. Link file
    command: ln (link)
    Format: ln [option] filename linkname
          ln [option] directory pathname
    Function: Create a chain for a file or directory. Among them, filename and directory are the source file name and
          source directory name; linkname and pathname respectively represent the file or directory linked with the source file or source directory name
          .
    Options: -s Make a symbolic link to a file or directory. Without -s, it means to establish a hard link for a file or directory.
    Note: The purpose of the link is to give a file or directory more than two names, so that it can
          appear in different directories, so that the file or directory can be shared, and Can save disk space.
    For example: %ln -s filename linkname

5. Display date
    command: date
    Example: % date

6. Display calendar
    command: cal (calendar)
    Format: cal [month] year
    Function: Display the calendar specified in a certain year
    For example: % cal 1998 

7. Display the file header
    Command: head
    Format: head [option] filename
    Function: Display the header of the file
    Option: display the file's header by default The first 10 lines.
          -i Display the first i line of the file.
    For example: % head filename

8. Display file tail
    command: tail
    format: tail [option] filename
    function: display file tail
    option: default Display the last 10 lines of the file.
          -i Display the last i line of the file.
          +i Displays from line i of the file.
    For example: % tail filename

9. Display the user ID
    command: id
    format: id [option] [user]
    Function: Display the user ID and all groups to which the user belongs.
    OPTIONS: -a Display the user name, user ID, and all group
    comments to which the user belongs:
    For example: % id username

10. View the currently logged in users
    Command: users

11. Display who is logged in to the machine
    Command: who
    Format: who
    Function: Display all user names currently in the system, use the terminal device number, registration time.
    For example: % who

12. Display the user name on the current terminal
    Command: whoami
    Format: whoami
    Function: Display the user used on the current terminal.
    For example: % whoami

13. Find file
    command: find
    Format: find pathname [option] expression
    Function: Find the file that matches the expression under the given path name.
    Options: -name means the file name
          -user username, select the file to which the user belongs
          -size Search by size, in block, a block is 512B
          -mtime n Search by the last modification time, select the file modified within n days
  -perm find by permission
          -type find by file type
  -atime Search by the last access time

    , for example: % find ./ -name '*abc*' -print

14. Search files for matching characters
    Command: grep
    Format: grep [option] pattern filenames
    Function: Search the specified file line by line or standard input, and display each line that matches the pattern.
    Option: -i ignore case when matching
  -v find out the lines with mismatched patterns

    for example: % grep -i 'java*' ./test/run.sh

15. Count the number of words in the file
    command: wc [option] filename
    function: count The number of file lines, words, and characters in the file.
    Options: -l Count the number of lines in the file     Options: -a: Display the disk usage of all file systems and partitions -i: Display the usage of i-nodes -k: The size is expressed in k (default value) - t: Display the disk usage of all partitions of a certain file system -x: Display the disk usage of all partitions not of a certain file system -T: Display the name of the file system to which each partition belongs -h: Indicates the use of "Human" -readable" output, that is, use a readable format such as GB, MB, etc. in the file system size.     Notes:
file -w count the number of words in the
file -c count the number of characters in the file
    Comment: if the default file name refers to the standard input
    , for example: % wc -c ./test/run.sh

16. Display Disk space
    command: df (disk free)
    Format: df [option]
    Function: Display the usage of disk space, including the file system installation directory name, block device name, total
          bytes, used bytes, remaining bytes occupancy percentage.









    For example: % df -hi

17. Query the disk usage space of a file or directory
    Command: du (disk usage)
    Format: du [option] [filename]
    Function: Display each subdirectory under the specified directory as a unit Disk space size
    options occupied by all files in the directory :
-a: Display the disk space occupied by all files in the directory and the next directory
-b: The size is expressed in bytes (the default value is k bytes)
-c: The last Add the total (default value)
-s: only display the total size of each file
-x: only calculate the files belonging to the same file system
-L: calculate the size of all files
-h: indicate the file system size using GB, MB etc. readable format.
    For example: % du -a
% du -sh /etc only displays the total of the directory.
% du /etc | sort -nr | more The statistical results are sorted by the sort command
.

18. Display process
    command: ps
    Format: ps [option]
    Function: Display the information of the process in the system. Including process ID, controlling process terminal, execution time and command.
    Options:
  -a Display all process information
  -U uidlist List all processes of this user
          -e Display information about each currently running process
          -f Display a complete list
  -x Display the status of processes including those without terminal control.
    Note:
    For example: % ps -ef
  % ps -aux Then use a pipe symbol to direct grep to find a specific process, and then operate on a specific process.

19. Terminate the process
    command: kill
    format: kill [option] pid
    function: send a signal to the specified process or terminate the process. The purpose of the kill command is to send a signal to a certain process,
    because most of them are SIGKILL or SIGHUP used to kill the process, so it is called kill 
    Option: -9 Forcibly terminate the process
    Note: pid indicates the process number, which can be obtained by the ps command.
    For example: % kill -9 pid
    You can also use kill -l to see numbers that can replace the signal number. For details on kill, see man kill.

20. Check your own IP address
    command: ifconfig
    format: ifconfig -a
  
21. View routing table
    command: netstat
    format: netstat -rn

22. Remote login
    command: telnet
    format: telnet hostname

23. File transfer
    command: ftp (file transfer program )
    Format: ftp hostname
    Function: Network file transfer and remote operation.
    Option: ftp command:
           cd [dirname] Enter the directory of the remote machine
           lcd [dirname] Set the directory of the local machine
           dir/ls Display the remote directory file
           bin Transfer in binary mode
   asc Transfer as a text file
           get/mget Get one or more files from
           the remote machine put/mput Send one or more files to the remote machine
           prompt Open or close the interactive prompt when transferring multiple files
           close Close the connection with the remote machine
           quit Quit ftp
   !/exit ftp In the login state, ! means to temporarily exit the ftp state and return to the local directory, and exit means to return to the ftp state.
    Notes:
    For example: % ftp hostname

24. Check your own email
    command: mailx
    format: mailx
    options:
delete delete
next
quit quit
         reply reply    29. Create, Modify, delete users and groups     a. Create groups:

25. recall command
    Command: history
    format: history
    function: help users recall the executed commands.
    Options:
    Comments:
    Example: %history

26. Online conversation
    command: talk
    Format: talk username
    Function: Have a conversation with another user on the Internet.
    Option:
    Note: During the dialog, the system divides the terminal into two parts: the upper part displays the information entered by yourself, and the lower part
          displays the information entered by the other party. Type delete or Ctrl+C to end the conversation.
    For example: % talk username

27. Allow or deny receiving information
    Command: mesg (message)
    Format: mesg [n/y]
    Function: Allow or deny other users to send information to their own terminal.
    Options: n Deny other users to write information to their own terminal
          y Allow other users to write information to their own terminal (default value)
    Comment:
    For example: % mesg n

28. Write information to other users
    Command: write
    format: write username [ttyname]
    function: write information to other users' terminals.
    Option:
    Note: If the other party does not refuse, the two users can chat. Type EOF or Ctrl+C to end the conversation.
    For example: write username



For example: groupadd oinstall creates a group with the group name oinstall
groupadd -g 344 dba 
creates a group with the group number 344, and a project with the 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 the 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 the group Group:
groupdel Group name: This command is used to delete the specified group account

    d. New user:
Command: useradd [-d home] [-s shell] [-c comment] [-m [-k template]]
[-f inactive] [-e expire] [-p passwd] [-r] name
main parameter -G: Specifies the additional group to which the user belongs. -m: Automatically create the user's login directory. -M: Do not automatically create the user's login directory. -n: Cancel the creation of a group named after the user name. -r: Create a system account. -s: Specifies the shell used by the user after logging in. -u: Specifies the user ID number. Example: # useradd -g oinstall -G dba oracle Create Oracle user
-c: add remark text, the remark text is saved in the remark column of passwd. 
-d: Specifies the starting directory when the user logs in.
-D: Change the default value.
-e: Specifies the validity period of the account. The default is permanent.
-f: Specifies how many days after the password expires to close the account.
-g: Specifies the group to which the user belongs.









   
    e. Delete user
Command : userdel user name
Delete the specified user account
userdel -r user name (userdel user name; rm user name): delete the specified user account and host Directory
Example : #useradd -g root kkk //Add the kkk user to the root group

    f. Modify the user
Command : usermod
modify the information of the existing user
usermod -l old user name new user name: modify user name
usermod -L user name: Used to lock the specified user account so that it cannot log in to the system
usermod –U username: unlock the locked user account
passwd –d username: make the account without a password, that is, the user can log in to the system without a password
Example : #usermod - l user2 user1 //Rename user user2 to user1

30. Start and close the firewall
Permanently open or close
chkconfig iptables on
chkconfig iptables off
Immediate effect: restore
service iptables start
service iptables stop after restarting
     or:
/etc/init.d/iptables start
/etc/init.d/iptables stop

31. Start VSFTP service
Instant start : /etc/init.d/vsftpd start
Immediate stop: /etc/init.d/vsftpd stop The

default VSFTP service starts automatically:
Method 1: (commonly used\convenient)
[[email protected] etc]# chkconfig --list|grep vsftpd (check the situation)
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected] etc]# chkconfig vsftpd on (execute ON setting)
or: Method 2:
Modify the file/ etc/rc.local , insert the line /usr/local/sbin/vsftpd & into the file to automatically start at boot.

32. vi skills
a. Enter the input mode
Add (append)
a: start adding data from behind the cursor position, and the data behind the cursor move backwards with the new data .
A: Add data from the last position of the column where the cursor is located.

Insert
i: Insert data from the front of the cursor position, and the data behind the cursor will move backward with the new data.
I : Insert data before the first non-blank character in the row where the cursor is located.

Open (open)
o : Add a new column under the column where the cursor is located and enter input mode.
O: Adds a new column above the column where the cursor is located and enters input mode.
b. Exit vi.
Type :q, :q!, :wq or :x (note: sign) in command mode, and vi will be exited. Among them: wq and :x are to save and exit, and :q is to exit directly. If the file has new changes, vi will prompt you to save the file and the :q command will also be invalid. At this time, you can use the :w command to save the file after Then use :q to exit, or use the :wq or :x command to exit. If you don't want to save the changed file, you need to use the :q! command, which will directly exit vi without saving the file.

c. Commands for deleting and modifying files:
x: delete the character where the cursor is located.
dd : Delete the column where the cursor is located.
r : Modify the character where the cursor is located, followed by the character to be modified.
R: Enter the replacement state, the new text will overwrite the original text, until you press [ESC] to return to the command mode.
s: Delete the character where the cursor is and enter the input mode.
S: Delete the column where the cursor is located and enter input mode.

d. Screen scrolling commands
Ctrl+u: scroll half a screen to the g. copy, paste (1 ) Select a text block, use v to enter visual mode; move the cursor key to select the content (2) Copy the selected block to the buffer, use y; copy the entire line, use yy
Ctrl+d: scroll half a screen to the end of
the file Ctrl+f: scroll one screen to the end of the file
Ctrl+b: scroll one screen to the beginning of the file
nz: scroll the nth line to the top of the screen, if n is not specified, scroll the current line to the top of the screen .

e. Delete command
ndw or ndW: delete the n-1 words starting at the cursor and after it
do: delete to the beginning of the line
d$: delete to the end of the line
ndd: delete the current line and the next n-1 lines
x or X: Delete a character, x deletes the cursor, and X deletes the cursor before the cursor
Ctrl+u: delete the text entered in the input mode

f. Search and replace command
/pattern: from the beginning of the cursor to the end of the file to search for pattern
?pattern: from Search pattern from the beginning of the cursor to the beginning of the file
n: Repeat the last search command in the same direction
N: Repeat the last search command in the opposite direction
: s/p1/p2/g: Replace all p1 in the current line with p2
: n1, n2s/p1/p2/g: Replace all p1 in lines n1 to n2 with p2
: g/p1/s//p2/g: Replace all p1 in the file with p2




(3) Cut the selected block to the buffer, use d; cut the entire line, use dd
(4) Paste the content in the buffer, use p

h. Others Open the second file
in the same editing window, use: sp [ filename]
to switch between multiple edited files, use Ctrl+w

Related: How to view processes, kill processes, start processes and other common commands in Linux