Comprehensive analysis of high-level core knowledge in Java-basic Linux commands (switching, adding, deleting, modifying, searching, compressed files, permission commands, user management, and other common commands)

1. Directory switching command

  • cd usr: Switch to the usr directory under this directory
  • cd ..(或cd../): Switch to the upper directory
  • cd /: Switch to the system root directory
  • cd ~: Switch to the user's home directory
  • cd -: Switch to the directory where the previous operation is located

Two, directory operation commands (addition, deletion, modification and check)

  1. mkdir 目录名称 : Add catalog

  2. ls或者ll (Ll is the alias of ls -l, the ll command can see the detailed information of all the directories and files in the directory): View directory information

  3. find 目录 参数:
    Example of looking for a directory (check) :

    • List all files and folders in the current directory and subdirectories: find .
    • Find the file name ending in .txt in the /home directory: find /home -name "*.txt"
    • Same as above, but ignoring case: find /home -iname "*.txt"
    • Find all files ending with .txt and .pdf in the current directory and subdirectories: find . \( -name "*.txt" -o -name "*.pdf" \)orfind . -name "*.txt" -o -name "*.pdf"
  4. mv 目录名称 新目录名称: Modify the name of the directory (change)
    Note: The syntax of mv can not only rename the directory but also rename various files, compressed packages, etc. The mv command is used to rename files or directories, or move files from one directory to another. Another usage of mv command will be introduced later.

  5. mv目录名称目录的新位置: Move the location of the directory-cut (change)
    Note: mv syntax can not only cut the directory, but also cut files and compressed packages. In addition, the results of mv and cp are different, mv seems to "move" the files, and the number of files has not increased. While cp copies files, the number of files has increased.

  6. cp -r 目录名称 目录拷贝的目标位置: Copy directory (change), -r stands for recursive copy
    Note: The cp command can not only copy directories but also files, compressed packages, etc. You don’t need to write -r recursively when copying files and compressed packages

  7. rm [-rf] 目录: Delete the directory (deleted)
    Note: rm can not delete the directory, you can also delete other files or archive, in order to enhance everyone's memory, regardless delete any directory or file directly using rm -rfthe directory / file / archive

Three, file operation commands (addition, deletion, modification, and inspection)

  1. touch 文件名称 : File creation (increment)
  2. cat/more/less/tail File name file view (check)
    • [] cat: View the content of the displayed file
    • more:Percentage can be displayed, press enter can go down one line, space can go down one page, q can exit view
    • less: You can use PgUp and PgDn on the keyboard to page up and down, q end view
    • tail-10 : View the last 10 lines of the file, Ctrl+C ends

Note: The command tail -f file can dynamically monitor a certain file, such as the log file of tomcat. The log will change as the program runs. You can use tail -f catalina-2016-11-11.log to monitor the file Variety

  1. vim 文件: Modify the content of the file (change) The
    vim editor is a powerful component in Linux and an enhanced version of the vi editor. There are many commands and shortcuts for the vim editor, but I will not explain them here, and you don’t need to study Very thorough, the way to edit and modify files with vim is basically enough.
    In actual development, the main function of using the vim editor is to modify the configuration file, the following are the general steps:
    vim file------>enter file----->command mode------>press i to enter Edit mode ----->Edit file------->Press Esc to enter the bottom line mode ----->Enter: wq/q! (Enter wq means write content and exit, that is, save; enter q! stands for forced exit without saving.)

  2. rm -rf 文件: Delete files (delete)
    the same directory Delete: Remember what rm -rf 文件you can

Four, compressed file operation command

1. Pack and compress files:

Packed files in Linux generally end in .tar, and compressed commands generally end in .gz.

Generally, packaging and compression are carried out together, and the suffix of the packaged and compressed file is generally .tar.gz.
Command: tar -zcvf 打包压缩后的文件名 要打包压缩的文件
where:

  • Call gzip compression command to compress
  • Package file
  • Show running process
  • Specify file name

For example, if there are three files in the test directory: aaa.txt bbb.txt ccc.txt, if we want to package the test directory and specify the compressed package name as test.tar.gz, we can use the command: tar -zcvf test.tar.gz aaa.txt bbb.txt ccc.txtor:tar -zcvf test.tar.gz /test/

2. Unzip the compressed package:

Command: tar [-xvf] compressed file

Among them: x: represents decompression

Example:

  1. To extract test.tar.gz under /test to the current directory, you can use the command: tar -xvf test.tar.gz
  2. Decompress test.tar.gz under /test to the root directory /usr: tar -xvf test.tar.gz -C /usr(-C represents the location to decompress)

Reference: "Comprehensive Analysis of Java Intermediate and Advanced Core Knowledge"
, please click here to add community, get it for free

Five, Linux permissions commands

Each file in the operating system has specific permissions, users and groups. Permission is a mechanism used by the operating system to restrict access to resources. In Linux, permissions are generally divided into three groups: readable, writable, and excutable. Corresponding to the owner, group, and other users of the file, respectively, through such a mechanism to restrict which users and which groups can perform what operations on a particular file. By ls -lpermissions on the file or directory command we can see a directory under

Example: ls -l

The information in the first column of a random directory is explained as follows:

The following will explain in detail the types of files, permissions in Linux, and what are the owners, groups, and other groups of the files?

File type:

  • d: representative directory
  • -: Representative file
  • l: Represents a soft link (can be considered as a shortcut in the window)

The permissions in Linux are divided into the following categories:

  • r: represents the authority is readable, r can also be represented by the number 4
  • w: the authority is writable, w can also be represented by the number 2
  • x: the authority is executable, x can also be represented by the number 1

The difference between file and directory permissions:

For files and directories, read-write execution means different meanings.

For files:

For directories: It

should be noted that super users can ignore the permissions of ordinary users, even if the file directory permissions are 000, they can still access it.
Every user in Linux must belong to a group and cannot be independent of the group. In Linux, each file has the concept of owner, group, and other groups.

  • The owner is
    generally the creator of the file. Whoever creates the file will naturally become the owner of the file. You can use the ls ‐ahl command to see the owner of the file. You can also use the chown username and file name to modify all of the file. By.

  • File group
    When a user creates a file, the group of the file is the group of the user. Use the ls ‐ahl command to see all groups of the file. You can also use the chgrp group name and file name to modify the group where the file is located. .

  • Other groups
    Except for the owner of the file and the users in the group, other users of the system are other groups of the file

Let's take a look at how to modify file/directory permissions.

Command to modify the permissions of a file/directory :chmod

Example: Modify the permissions of aaa.txt under /test to the owner has all permissions, the owner’s group has read and write permissions, and other users have only read permissions

chmod u=rwx,g=rw,o=r aaa.txt

chmod -R u=rwx,g=rwx,o=rwx ./log// Recursively authorize all files in the log directory The

above example can also be represented by numbers:

chmod 764 aaa.txt

Add a more commonly used thing:

If we install a zookeeper, what should we do every time we boot to ask it to start automatically?

  1. Create a new script zookeeper
  2. Add executable permissions to the newly created script zookeeper, the command is:chmod +x zookeeper
  3. Add the zookeeper script to the boot entry, the command is: chkconfig --add zookeeper
  4. If you want to see if the addition is successful, the command is: chkconfig --list

6. Linux user management

The Linux system is a multi-user and multi-task time-sharing operating system. Any user who wants to use system resources must first apply for an account from the system administrator, and then enter the system as this account.

On the one hand, user accounts can help system administrators track users who use the system and control their access to system resources; on the other hand, they can also help users organize files and provide users with security protection.

Linux user management related commands:

  • useradd 选项用户名 : Add user account
  • userdel 选项用户名: Delete user account
  • usermod 选项用户名 : Modify account
  • passwd 用户名: Change or create user's password
  • passwd -S 用户名 : Display user account password information
  • passwd -d 用户名 : Clear user password

The useradd command is used for new system users created in Linux. useradd can be used to create user accounts. After the account is established, use passwd to set the password of the account. The userdel can be used to delete the account. The account created by the useradd command is actually stored in the /etc/passwd text file.

The passwd command is used to set user authentication information, including user password and password expiration time. The system administrator can use it to manage the passwords of system users. Only the administrator can specify the user name, and general users can only change their own password.

Seven, Linux system user group management

Each user has a user group, and the system can centrally manage all users in a user group. Different Linux systems have different rules for user groups. For example, a user under Linux belongs to a user group with the same name, and this user group is created at the same time as the user is created.

The management of user groups involves the addition, deletion and modification of user groups. The addition, deletion and modification of groups are actually updates to the /etc/group file.

Linux system user group management related commands:

  • groupadd 选项 用户组 : Add a new user group
  • groupdel 用户组 : To delete an existing user group
  • groupmod 选项 用户组 : Modify the attributes of a user group

8. Other commonly used commands

  • pwd :Display the current location

  • sudo + 其他命令 : Execute commands as the system administrator, that is, commands executed via sudo are as if they were executed by root himself.

  • grep 要搜索的字符串 要搜索的文件 --color : Search command, -color stands for highlight

  • ps -ef / ps -aux: These two commands are to view the current running process of the system, the difference between the two is that the display format is different.
    If you want to view a specific process, you can use this format: ps aux|grep redis(View the process that includes the redis string), or you can use it pgrep redis -a.
    Note: If you use the ps ((Process Status)) command directly, the status of all processes will be displayed, usually combined with the grep command to view the status of a process.

  • kill -9 process pid: kill the process (-9 means forced termination.)
    First use ps to find the process, and then kill it with kill

  • Network communication commands:

  • View the network card information of the current system: ifconfig

  • Check the connection with a machine: ping

  • View the port usage of the current system: netstat -an

  • net-tools and iproute2:
    net-tools originated from the BSD TCP/IP toolbox, and later became a tool for configuring network functions in the old Linux kernel. But since 2001, the Linux community has stopped maintaining it. At the same time, some Linux distributions such as Arch Linux and CentOS/RHEL 7 have completely abandoned net-tools and only support it iproute2. The linux ip command is similar to ifconfig, but has more powerful functions and is intended to replace it.

  • shutdown:: shutdown -h nowSpecify to shut down immediately now;: Specify to shut down shutdown +5 "System will shutdown after 5 minutes"after 5 minutes, and send a warning message to the logged-in user.

  • reboot: reboot: Reboot. reboot -w: Make a simulation of rebooting (only recording does not really reboot).


Reference material: "Comprehensive Analysis of Java Intermediate and Advanced Core Knowledge" is limited to 100 copies. Some people have already obtained it through my previous article!
Seats are limited first come first served! ! !
Students who want to get this learning material can click here to get it for free

Guess you like

Origin blog.csdn.net/Java_Caiyo/article/details/111409662