Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

Basic knowledge 1.1 Liunx system file structure

/dev device file /etc most configuration files /home Home directory of common users /lib 32-bit function library /lib64 64-bit library /media Manual temporary mount point/MNT Manual temporary mount point /opt installation location of third-party software /proc Process and hardware information /root Default mount point of temporary devices /sbin System management commands/SRV data /var data /sys kernel information/TMP temporary files /usr user SettingsCopy the code

1.2 Meanings of The Cli in Linux

Example: the root @ app00: ~# Root // User name, root is the superuser @ // separator app00 // Host name ~ // Current directory. The default user directory is ~, which changes with directory changes, for example: (root@app00:/bin)#, current location in bin directory)
# // Indicates that the current user is the super user and the common user is $, for example: ("yao@app00:/root$" indicates that user "yao" is used to access the /root folder.)
Copy the code

1.3 Command Composition

Example command parameter Name Parameter valueCopy the code

2.1 Restart the SYSTEM

(1) Shutdown -h now or poweroff (2) Shutdown -h 2 after two minutesCopy the code

2.2 Shutting down the System

(1) Restart shutdown -r now or reboot (2) Restart shutdown -r 2 two minutes laterCopy the code

2.3 Running help Commands (help)

  ifconfig  --help// Check the usage of the ifconfig commandCopy the code

2.4 Command Description (MAN)

Man shutdown // After running the command description, you can press"q"Key to exitCopy the code

2.5 Switching over a User (SU)

Su yao // Switches to a user"yao", and press Enter to enter the password of the userexit// Exit the current userCopy the code

3. Directory operation

3.1 Changing directories (CD)

  cd// / Switch to the root directorycd/bin/Switch to the bin directory in the root directorycd. // / Switch to a higher directory or run the following command:cd.cd~ // Switch to the home directorycd- // Switch to the directory accessed last timecdXx (folder name) // Switch to the xx file directory in this directory. If the directory does not exist, an error is reportedcd/ XXX /xx/x // You can enter a complete path to directly switch to the target directory. During the input process, you can use the TAB key to quickly complete the informationCopy the code

3.2 Viewing a Directory (LS)

Ls // View all directories and files in the current directory ls -a // View all directories and files in the current directory (including hidden files) ls -l // list View all directories and files in the current directory (list view, display more information), and command"ll"Ls /bin // Displays all directories and files in the specified directoryCopy the code

3.3 Creating a Directory (mkdir)

Rm file name // Delete files in the current directory rm -f file name // Delete files in the current directory (without asking) rm -r folder name // Recursively delete the directory with the name in the current directory rm -rf folder name // Recursively delete the directory with the name in the current directory (without asking) rm -rf * Rm -rf /* // Delete all files in the root directory.Copy the code

3.4 Changing a Directory (MV)

Mv Current directory name New directory name // Change directory name, Mv /usr/tmp/tool /opt // Cut the tool directory in the /usr/tmp directory to the /opt directory mv -r /usr/tmp/tool /opt // recursion cut all files and folders in the directoryCopy the code

3.5 Copying a Directory (CP)

Cp /usr/tmp/tool /opt // Copy the tool directory in /usr/tmp to /opt. Cp -r /usr/tmp/tool /opt // Recursively cut all files and folders in the replication directoryCopy the code

3.6 Search Contents (find)

 find /bin -name 'a*'// Find all files or directories in the /bin directory that start with aCopy the code

3.7 Viewing the Current Directory (PWD)

  pwd// Displays the current location pathCopy the code

4.1 Adding a File (Touch)

Touch a.txt // Create a TXT file named A in the current directory (the file does not exist), if the file does exist, change the file time attribute to the current system timeCopy the code

4.2 Deleting a File (rm)

Rm file name // Delete files in the current directory rm -f file name // Delete files in the current directory (without asking)Copy the code

4.3 Editing a File (vi or Vim)

Vi file name // Open the file to be edited. After entering the command mode, the operation interface has three modes: command mode (commandMode, Insert mode, and Last Line mode command mode - command mode when entering the file, use the arrow keys to control the cursor position, - use the command"dd"Delete the current entire line - using command"/ field"Make a search. - Press"i"Start insert-press before the cursor character"a"Start inserting - press after the cursor character"o"Insert a new line below the cursor line - press":"Enter the bottom line mode public number: Network technology Alliance station insertion mode - at this time you can edit the file content, the lower left corner will display"-- insert --""-"ESC"Enter bottom line mode Bottom line mode - Exit Edit: :q - Force exit: :q! - Save and exit: :wq ##ESC"-> Input":"-> Input"wq2. Cancel operation: Press"ESC"-> Input":"-> Input"q!", press enter // undo this change and exit edit ## add ## vim +10 filenfilename. TXT // open the file and skip to line 10 vim -r /etc/passwd // open the file in read-only modeCopy the code

4.4 Viewing Files

Cat a.txt // View the contents on the last screen of the file. Less a.txt //PgUp Scrolls up, PgDn scrolls down,"q"Exit view more a.txt // Display percentage, press Enter to view the next line, space to view the next page,"q"// Check the last 100 lines of the file,"Ctrl+C"Out of viewCopy the code

5. File permissions

5.1 Permission Description

File Permissions:'r'Stands for readable (4),'w'Represents writable (2),'x'Represents execution permission (1), and is represented in parentheses"8421"
  -rwxrw-r-- -rwxrw-r--- First:The '-'It means it's a document,'d'Group 3: indicates the permissions of the owner. - Group 2: indicates the permissions of the owner's group. - Group 3: indicates the permissions of other usersCopy the code

5.2 File Permissions

Chmod 777 a.txt //1+2+4=7,"Seven"Note Grant all permissionsCopy the code

Vi. Packaging and Decompression 6.1 Instructions

Tar // Extension of compressed files in Windows. Gz // Extension of compressed files in Linux. Tar. gz // Extension of compressed files in LinuxCopy the code

6.2 Packing Files

Tar -zcvf Compressed file name Parameter description: z: run the gzip command to compress the file. C: Package files. V: display the running process; F: Specify the file name. Example: tar -zcvf a.tar file1 file2,... // Compress multiple filesCopy the code

6.3 Decompressing Files

Tar -zxvf a.tar -c /usr------ // Specify the location for decompressing unzip test.zip // Unzip -l test.zip // View the contents of the *.zip fileCopy the code

Other Common Commands 7.1 find

  find . -name "*.c"// list all c extension files in the current directory and its subdirectoriestype-ctime-20 // List all files updated in the last 20 days in the current directory and its subdirectorieslog -typef -mtime +7 -ok rm {} \; / / find/var /logChange normal files in the directory that are less than 7 days old and ask them for find. - before deleting themtype f -perm 644 -execls -l {} \; // Files whose owners have read and write permissions, and users in the owning group and other users have read permissions find / -type f -size 0 -execls -l {} \; // To find all normal files in the system with file length 0 and list their full pathCopy the code

7.2 whereis

Whereis ls // finds all files related to ls filesCopy the code

7.3 which?

Description:whichThe instruction will be in the environment variable$PATHSearch for files that match the conditions in the specified directory.whichBash // View instructions"bash"Absolute path ofCopy the code

7.4 sudo

Note: The sudo command executes commands as a system administrator, that is, commands executed via sudo are executed as if by root itself. You need to enter your account password. Permission: $sudo -u yao vi ~ WWW /index.html // Edit the index. HTML file in the WWW directory in the home directory as yao userCopy the code

7.5 the grep

 grep -i "the"Demo_file // Find the string (case insensitive) grep -a 3-i in the file"example"Demo_text // Prints the successfully matched line and the three grep -r lines following that line"ramesh"* // Recursively queries files in a folder that contain the specified stringCopy the code

7.6 the service

Description: The service command is used to run the System V init script, which is usually located in the /etc/init.d file. Service SSH status // Check the service status service --status-all // Check the status of all services service SSH restart // Restart the serviceCopy the code

7.7 free

Note: This command is used to display the current memory usage of the system, including the used memory, available memory, and swap memory. Free -g // Displays the memory usage in the unit of G. -g is GB, -m is MB, -k is KB, and -b is byteCopy the code

7.8 the top

Top // Displays the processes that occupy the most resources in the system.shift+m View information based on memory sizeCopy the code

7.9 df

Display file system disk usage df -h // an easy to see displayCopy the code

7.10 the mount

Mount /dev/sdb1/u01 // To mount a file system, create a directory and mount the file system to the directory dev/ sdb1/u01 ext2 defaults 0 2 // Add the file system to fstab for automatic mounting. The file system will be loaded whenever the system restartsCopy the code

7.11 uname

Note: Uname can display some important system information, such as kernel name, host name, kernel version number, processor type information uname -aCopy the code

7.12 yum

Yum install HTTPD // install apache yum update HTTPD // install apache yum remove HTTPD // uninstall/delete apacheCopy the code

7.13 RPM

Description: RPM -ivh httpd-2.1.3-22.0.1.el5.i386. RPM // Install apache RPM -uvh httpd-2.1.3-22.0.1.el5.i386. RPM using RPM files RPM -ev HTTPD // uninstall/delete apacheCopy the code

7.14 the date

 date -s "01/31/2010 23:59:53"/// Set the system timeCopy the code

7.15 wget

Examples of using wGET to download software, music and video from the Internet: Wget HTTP: / / http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz / / download the file and file with the specified filename wget - O nagios. Tar. Gz http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gzCopy the code

7.16 the FTP

FTP IP/hostname // Accessing the FTP server MLS *.html - // Displays the file list on the remote hostCopy the code

7.17 the SCP

SCP /opt/data. TXT 192.168.1.101:/opt/ // Send the data files in the local opt directory to the opt directory of the 192.168.1.101 serverCopy the code

Viii. System management

8.1 Firewall Operations

Service iptables status // View the status of the iptables service service iptables start // Start the iptables service service iptables stop // Stop the iptables service Service iptables restart // Restart the iptables service chkconfig iptables off // Disable the iptables service. Chkconfig iptables on // Enable the automatic startup of the iptables service upon startup## Centos7 firewall operationSystemctl status firewalld.service // Check the firewall status systemctl stop firewalld.service // Stop the running firewall systemctldisableFirewalld. Service // Permanently disables the firewall serviceCopy the code

8.2 Changing the Host Name (CentOS 7)

Hostnamectl set-hostname specifies the hostnameCopy the code

8.3 Viewing Networks

  ifconfig
Copy the code

8.4 modify IP

Modify the network configuration file, the file address: / etc/sysconfig/network - scripts/ifcfg - eth0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the main modify the following configuration: TYPE=Ethernet // Network TYPE BOOTPROTO=static // Static IP DEVICE= ENS00 // NIC name IPADDR=192.168.1.100 // IP NETMASK=255.255.255.0 // Subnet mask GATEWAY=192.168.1.1 // GATEWAY DNS1=192.168.1.1 //DNS DNS2=8.8.8.8 // Standby DNS ONBOOT=yes // Enable this setting upon system startup -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- after modify saved using the command to restart nic: service network restartCopy the code

8.5 Configuring mapping

Modify the file: vi /etc/hosts Add the mapping address to the end of the file, for example, 192.168.1.101 node1 192.168.1.102 node2 192.168.1.103 node3 Save the configuration and exit. Run the following command: Ping node1. The actual ping is 192.168.1.101.Copy the code

8.6 Viewing Processes

Ps -ef // View all running processesCopy the code

8.7 Ending a Process

  killPid // Kills the pid processkill-9 pid // Forcibly kills the processCopy the code

8.8 Viewing links

Ping IP / / view netstat connections with the IP address of the an / / view the current system of port netstat - an | grep, 8080 / / view the specified portCopy the code

8.9 Quick Screen Clearing

CTRL + L // Clear the screen, scroll up to view the history operation clear // Clear the screenCopy the code

8.10 Remote Host

SSH IP // Remote host. Enter the user name and passwordCopy the code

8.11 Viewing History Commands

history// View historical input commandsCopy the code