Linux common commands (files, directories, system management, users, disks, etc.)

content

Commands related to files and directories

system management commands

User and user group management commands

User group management

User Management

Permission related commands

View disk and free space


Commands related to files and directories

1. ls lists the names of the current files and folders

  • ls -a: Display all file and folder names (including hidden ones such as .book)
  • ls -l=ll: Display detailed information about files and folders
  • drwxr-xr-x 1 root root 4096: The folders starting with d are all 4096 in size
  • ls -R: recursively display the directories of the current folder

 

2.mkdir creates a new directory

  • mkdir test: create a folder with the folder test
    • mkdir test01 test02 test03: Create folders named test01, test02, test03 respectively
  • mkdir -p: directly recursively create all directories (including the previous directory)
    • mkdir -p test04/test04-01/test04-01-01

3.rmdir: delete empty directories

  • rmdir test: delete the folder with the folder name test (the contents of the folder are empty)
  • rmdir -p test/test01: directly delete the test folder, including the empty directory test01 in it. (If there are files in test01, the deletion is unsuccessful)

4.cd switch directory

(1) Absolute path

Path writing, starting from the root directory/: cd /root/test1/test2

(2) Relative path

  • Click the tab key to automatically complete the file/folder name
  • Double-click the tab to list all files and folders in the current directory
  • The path is not written from /: cd test1/test2 in the root directory
  • cd ~ into the user home directory
  • cd .. go back one level
  • cd ../.. go back to parent
  • cd / into the root directory

5.pwd: Display the absolute path of the current folder

6.vi text editor

  • vi today: open today, if the file does not exist, create a new today

model

(1) Insert edit mode (click on the keyboard to insert, or i, a, o) the sign appears in the lower left corner --INSERT--

(2) Esc command mode (click Esc on the keyboard, the logo is in the lower left corner--INSERT--disappears)

  • q: quit the program; w: save the file
  • :wq: save and exit
  • :wq! : Force save and exit
  • :q! : Force quit
  • u: undo the last input
  • G: Skip to the last line of text
  • gg: jump to the first line of text
  • ? bcbx: find bcbx, press n to find the next
  • /bcbx: find bcbx, press n to find the previous one
  • crtl+c: terminate
  • ctrl+b: page up
  • ctrl+f: page down

7.cat to view the content of the file (without entering the content, the knowledge shows the content) (displayed from the first line)

  • cat -n sey: Display the line number of the sey file

8. cp to copy a file or directory

  • cp source file target file path (absolute path recommended)
  • cp /root/fuyao /root/modaozushi
  • -r: recursive continuous copy for whole folder copy behavior. Such as: cp -r source folder destination folder: cp -r /root/day /root/modaozushi
  • create copy cp 0001 0002 (nonexistent filename): created copy 0002 of 0001 (nonexistent filename)

 

9.rm delete a file or directory

  • rm source file name (prompt "whether to delete the XX file, this command cannot directly delete the folder")
  • rm -r source filename: delete folder
  • rm -f : force delete file
  • rm -rf: Force delete a file or folder

10.mv move or rename files and folders

  • mv source file/folder target folder/file (rename if target folder/file does not exist)
  • mv source file/folder destination folder (move a file or folder to a folder)

11.find finds a folder or file under the specified file and prints the absolute path

  • find path-name "folder or file name" (part of the name plus *, * is a wildcard)
  • Know the full name: find / -name "ylem-hadse"
  • Know only the beginning of the name: find / -name "ylem-h*"
  • Know only the name ending: find / -name "*em-hades"
  • Don't know the middle part: find / -name "yle*des"

12.tar compresses or decompresses files

  • Compression: tar -cvf Compressed package name (recommended to end with .tar for easy identification) The file you want to compress
    • tar -cvf ylem.tar / bcbx22 / kingrealhart
  • Unzip: tar -xvf the name of the compressed package (unzip the compressed package to the current folder)
    • tar -xvf ylem.tar

13.tail view the following lines of the file (default 10 lines)

  • tail filename (look at the last 10 lines of the file)
  • tail -n filename (look at the last n lines of the file)
  • tail -f filename (dynamically keep viewing the file until you press ctrl+c to exit)

14. echo command

  • Used to view the value of the environment variable after echoing characters on the display (equivalent to printing out print)
    • echo what needs to be displayed
      • echo test
  • echo 'file content' >> file path: echo 'goodman' >> /root/bcbx22/kingrealheart/hades04/test
  • echo "file content" > file path: overwrite the original file content

 

15 touch create file

  • touch test01: Create a file named test01
  • touch test01 test02 test03: respectively create files named test01 test02 test03

system management commands

1.hostname: Display the hostname

2.clear: clear the screen

3.top: View the current process in real time, dynamic, you can see the latest CPU load information, etc. (equivalent to Windows Task Manager)

  • Press M within the command to view sorted by memory usage

4.ps : Display the status of the current process

  • ps -e: show all processes
  • ps -f: show the relationship between programs
  • ps -ef | grep process name: find process
  • | grep content: search by combining with the command with output, such as: cat text | grep good [find/check the text containing good in test]
  • PID: Process ID; PPID: Parent Process ID

5.kill kill process

  • kill process number: kill the process
  • kill -9 process number: force kill process

6.shutdown: shutdown

7.logout: logout

8.reboot: reboot

9.ping: Determine the status of the network and each external host

10.date: Display or set the current time and date of the system

  • deta -s 1994-07-12
  • data-s 21:12:21
  • data -s "1994-07-12 21:12:21"

11.ifconfig: Display the status of network devices

User and user group management commands

User group management

  • cat /etc/group: view user groups
  • groupadd Hades: Add a user group named Hades
  • groupmod -n Ylem Hades: Modify the group name of the user group Hades to Ylem
  • groupdel Ylem: delete user group Ylem
  • groups: View the username of the current user
  • groups Ylem: View Ylem's user groups

User Management

  • cat /etc/passwd: view users
  • useradd John: add a user named John
  • useradd John -c student: Specify a commentary [c] (student) description for John {if no group is specified, the system will automatically create a John group}
  • useradd John -g 1st: Specify the user group to which John belongs [g] as 1st
  • useradd John -c student -g 1st: Specify a commentary [c] (student) description for John, and specify the belonging user group [g] as 1st
  • usermod modify user
    • usermod -l Hades Ylem: Change the username Ylem to Hades
    • usermod -c Codeman Ylem: Modify the user description of user Ylem to Codeman
    • usermod -g root Ylem: Modify the user group of user Ylem to root
  • userdel Ylem: delete user Ylem
  • passwd: set the password for the user
  • passwd Ylem: Set a password for Ylem

Permission related commands

  • su switch users (root users do not need to enter passwords to switch to other users, ordinary users need to enter passwords to switch to other users)
  • su - Ylem: switch to Ylem user
  • chown Change the owner of a file or folder
  • chown user: user group file/folder: chown wzx: root hades01 [change the owner of the hades01 file to wzx whose user group is root]
  • chown -R wzx:root hades02 [Change the owner of the hades02 folder and all files/folders in the folder to wzx whose user group is root]
  • chmod change file/folder permissions
  • A file/folder has a total of 10 characters. The first character represents the file type, and the latter is divided into 3 groups. The 3 characters represent the permissions of the user, the permissions of the same group, except the permissions of the user and others in the same group.
  • File type: - [normal file]; d [folder]; l [symbolic link file, similar to shortcut]; s [soket file]; p [pipe file pipe]
  • Permission: r [4 read permission]; w [2 write permission]; x [1 execute or switch permission]; - [0 no permission]
  • Permission number meaning: 0 [No permission]; 1 [Execute and switch permission] 2 [Write permission]; 3 [Execute and write permission (can be read if able to write)]; 4 [Read permission]; 5 [Execute and read permissions]; 6 [Read and write permissions]
  • chmod -R 777 hades02 [change the permissions of the hades02 folder and all files/folders in the folder to 777]

View disk and free space

  • df displays the free space of the specified disk file
  • du shows disk space usage for each file and directory
  • du -h: display in units of K, M, G
  • du -sh: Display the overall space usage of the current folder
  • du -sh ./* : Display the size of all files and folders under the current folder (folders will not be displayed one level further)
  • free displays the space and memory used by the system
  • free -k: view in kb
  • free -m: view in mb
  • free -g: view in gb
  • netstat -ntpl: view ports

Guess you like

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