System operation
#使用shutdown命令马上重启系统
[Email protected] ~]# Shutdown–r now
#使用shutdown命令马上关闭系统
[Email protected] ~]# Shutdown–h now
#使用shutdown命令设置在15分钟以后自动重启系统
[Email protected] ~]# shutdown–r +15
Show online login user who
Show current Operation user WhoAmI
Display host name hostname
Display System Information uname
Dynamic display of currently consuming resources up to process information top
Open service ntpd Start
View service status Services NTPD status
Close Service ntpd Stop
Boot from Chkconfig ntpd on
SSH login ssh [email protected]
Network conditions
View network conditions Ifconfig
Test network Connectivity Ping
Show Network status information Netstat-tap | grep MySQL
See if the port is occupied netstat-ant |grep 3306
View Process Ps-ef | grep MySQL
Kill the process, you can first use the PS or top command to see the process ID, and then kill the process kill-9 1234 process number
Shut down the firewall systemctl stop iptables (CentOS7)
File operations
View your current working directory pwd
Directory Jump cd/usr/local go to the local folder
Return to the previous level CD.
Return to last catalog CD-
Find/-name file1 from '/' to the root file system to search for files and directories
Create folder mkdir-p XXX Create directory, if no parent directory, create p (parent)
Create file Touch xxx Create an empty file
Create a file with content echo xxx
View files Cat xxx
View all files and directories under directory structure including hidden A (all) Ls-al xxx
Copy the file cp/usr/local/abc.txt/usr copy the abc.txt to the/usr directory
Delete files Rm-rf xxx with-R for recursive deletion, can delete subdirectories and files with-F for forced deletion
Move or rename mv xxx xxx1
Sometimes without permission, so you have to add sudo
sudo mv Abc.jar
Edit File Vi/etc/network/interfaces
Then press the I key to enter the input mode
After editing, press the ESC key to save the exit file directly: Wq
File Append Content
Cat Authorized_keys_from_yang >> Authorized_keys
Package operations
Extracting Files TAR-ZXVF hadoop.tar.gz
User group actions
Store user account/etc/passwd
Storage group Account/etc/group
Store password for user account/etc/shadow
Password to store user group account/etc/gshadow
SU user switches the user, loads the configuration file. You may need to enter a password after BASHRC
Groupadd group_name Create a new user group
Useradd-c "Name Surname"-G admin-d/home/user1-s/bin/bash user1 create a user who belongs to the "admin" user group
File Permission Actions
Chown–r hadoop:hadoop Hadoop #将文件夹 "Hadoop" Read permissions assigned to Hadoop users
chmod 0755 File # Changes files permissions to-rxwr-xr-x
chmod g+w File # Adds a user group writable permission to files ' permissions
user and user groups for changing files
sudo chown [-r] Owner[:group] {file| Directory}
For example: Also take jdk-7u21-linux-i586.tar.gz as an example. belongs to user Hadoop, group Hadoop
You want to switch the users and groups to which this file belongs. You can use commands.
sudo chown-r root:root jdk-7u21-linux-i586.tar.gz
redirect
Description: The standard input device in a Linux system is the keyboard, the standard output device is the screen, but in some cases we want to be able to read data from other input devices other than the keyboard, or to send the data to other output devices outside the screen, which is called redirection. The input-output redirection in the shell is primarily based on redirection symbols, which are usually a file.
Input redirection: Input redirection is the way that incoming input in a command is redirected from the default keyboard to the specified file, and you need to use the < redirection operator. The command "WC < F1" means that the information of the F1 file is used as input to the WC command.
Output redirection: Output redirection redirects the output of the command to a file instead of being displayed on the screen. Output redirection uses the ">" or ">>" operators, respectively, to overwrite and append files. The file specified later in the ">" redirect if it does not exist, the file is created in the command execution and the command results are saved to the file. If the file specified after the ">" redirect is present, the command executes to empty the contents of the file and saves the command result to the file.
#查看 the contents of the/etc/passwd file and save the output to the Pass.txt file.
[Email protected] ~]# cat/etc/passwd > Pass.txt
After executing the command, a file named Pass.txt is generated in the current directory, and the contents of the file are the results of the "cat/etc/passwd" command execution.
The >> redirect operator redirects the result of the command execution and appends it to the end of the specified file, without overwriting the contents of the file.
#查看 the following 3 lines of the/etc/shadow file and append the output results to the Pass.txt file.
[Email protected] ~]# tail-3/etc/shadow >> pass.txt
Pipeline
Description: Pipe symbol "|" Used to connect the left and right two commands, the "|" The execution result of the left command as "|" The input to the right command, so "|" It is like a pipe connected to the left and right two commands, and in the pipeline to achieve the data from a to-go transmission.
#分页显示 the details of all files and subdirectories in the/etc directory.
[Email protected] ~]# Ls-lh/etc | More
#显示 the details of all files and subdirectories that contain the "NET" keyword in the/etc directory.
[Email protected] ~]# Ls-lh/etc | grep net
-rwxr-xr-x. 1 root root 1.3K April auto.net
-rw-r--r--. 1 root root 74 May issue.net
-rw-r--r--. 1 root root 767 November Netconfig
-rw-r--r--. 1 root root 58 May Networks
Drwxr-xr-x. 2 root root 4.0K January 8 19:14 xinetd.d
#统计一下 the number of files ending with ". conf" in the/etc directory.
[Email protected] ~]# Ls-l/etc/*.conf | Wc–l 44
#查看 the/etc/httpd/conf/httpd.conf file except for lines and blank lines that begin with "#".
[Email protected] ~]# grep-v "^#"/etc/httpd/conf/httpd.conf | Gerp–v "^$"
Utility Collection Linux Command memo