1. Common commands
(1) Basic commands
1. shutdown
shutdown -h now 立刻关机
shutdown -h 5 5分钟后关机
poweroff 立刻关机
2. Restart
shutdown -r now 立刻重启
shutdown -r 5 5分钟后重启
reboot 立刻重启
3. help
--help命令
shutdown --help:
ifconfig --help:查看网卡信息
man命令(命令说明书)
man shutdown
注意:man shutdown打开命令说明书之后,使用按键q退出
(2) Directory commands
1. Directory switching
cd / 切换到根目录
cd /usr 切换到根目录下的usr目录
cd ../ 切换到上一级目录 或者 cd ..
cd ~ 切换到home目录
cd - 切换到上次访问的目录
2. Directory files and folders view
ls [-al]
ls 查看当前目录下的所有目录和文件
ls -a 查看当前目录下的所有目录和文件(包括隐藏的文件)
ls -l 或 ll 列表查看当前目录下的所有目录和文件(列表查看,显示更多信息)
ls /dir 查看指定目录下的所有目录和文件 如:ls /usr
(1)ls
(2)ls -a
(3)ls -l
(3) Directory operation
1. Create a directory
command: mkdir directory
mkdir aaa 在当前目录下创建一个名为aaa的目录
mkdir /usr/aaa 在指定目录下创建一个名为aaa的目录
Create directories recursively -p parameter
mkdir -p /a/b/c/d
Create multiple directories and subdirectories at the same time
2. Delete directory or file
Command: rm [-rf] dir -r recurse -f force
(1) Delete files
rm 文件 删除当前目录下的文件
rm -f 文件 删除当前目录的的文件(不询问)
(2) Delete directory
rm -r aaa 递归删除当前目录下的aaa目录
rm -rf aaa 递归删除当前目录下的aaa目录(不询问)
(3) Delete all
rm -rf * 将当前目录下的所有目录和文件全部删除
rm -rf /* 【自杀命令!慎用!慎用!慎用!】将根目录下的所有文件全部删除
Notice:
rm can not only delete directories, but also delete other files or compressed packages . For the convenience of everyone’s memory, no matter you delete any directory or file, you can directly use rm -rf directory/file/compressed package
3. Directory modification
Commands: mv and cp
(1) Rename directory
command: mv current directory new directory
For example: change directory aaa to bbb
mv aaa bbb
Note: The syntax of mv can not only rename directories but also rename various files, compressed packages, etc.
(2) Cut directory (move directory)
Command: mv directory name directory new location
Example: Cut the aaa directory under the /usr/tmp directory to the /usr directory
mv /usr/tmp/aaa /usr
Note: The mv syntax can not only cut directories, but also cut files and compressed packages.
(3) Copy directory
Command: cp -r directory name directory copy target location
-r stands for recursive
example: copy the aaa directory under the /usr/tmp directory to the /usr directory
cp /usr/tmp/aaa /usr
Note: The cp command can not only copy directories but also copy files, compressed packages, etc., you don’t need to write -r recursively when copying files and compressed packages
For example: copy the test.xml file in the current directory to the test2 folder
4. Search directory
Command: find search scope --name file name
What does the 'a*' wildcard start with
Example: Find all directories or files starting with a in the /usr/tmp directory
find /usr/tmp -name 'a*'
find . -name 'a*'
In the current directory, look for directory files and folders starting with t
(4) File operation
1. Create a new file
Command: touch filename
Example: Create a file named aa.txt in the current directory
touch aa.txt
2. Delete files
Command: rm -rf filename
3. Modify the file
command vi or vim
[3 modes of vi editor]
Basically, vi can be divided into three states, which are command mode , insert mode and last line mode. The functions of each mode are as follows:
1) command line mode command mode)
to control the movement of the screen cursor, delete characters, words or lines, search, move and copy a section and enter Insert mode, or go to last line mode.
Commonly used commands in command line mode:
[1] Control cursor movement: ↑, ↓, j
[2] Delete current line: dd
[3] Search: / character
[4] Enter edit mode: ioa
[5] Enter bottom line mode ::
2) Editing mode (Insert mode)
Only in Insert mode (press the i key on the keyboard) can you do text input, and press the "ESC" key to return to the command line mode.
Common commands in edit mode:
【1】ESC to exit the editing mode and return to the command line mode;
3) The last line mode (last line mode)
saves the file or exits vi, and can also set the editing environment, such as searching for strings, listing line numbers, etc.
Commonly used commands in bottom line mode:
【1】Exit editing: :q
【2】Force quit: :q!
【3】Save and exit: :wq
4. Open the file
Command: vi file name
Example: Open the aa.txt file in the current directory
vi aa.txt
vim aa.txt
Note: After using the vi editor to open the file, it cannot be edited, because it is in the command mode at this time, click the keyboard i/a/o to enter the editing mode.
5. Edit the file
After opening the file with the vi editor, click the button: i, a or o to enter the editing mode.
i: Insert before the character where the cursor is located
a: Insert after the character where the cursor is located
o: Insert a new line below the line where the cursor is located
save or cancel editing
(1) Save the file:
Step 1: ESC to enter command line mode
Step 2: shift+: Enter bottom line mode
Step 3: wq! Save and exit editing
(2) Cancel editing:
The first step: ESC to enter the command line mode
The second step:: Enter the bottom line mode
The third step: q! Undo this modification and exit the editor
6. Viewing files
Command: cat /more/less/tail
cat: see the last screen
Example: Use cat to view the /etc/sudo.conf file, only the last screen content can be displayed
cat sudo.conf
more: percentage display
Example: use more to view the /etc/sudo.conf file, and the percentage can be displayed, the carriage return can go down one line, the space can go down the page, and q can exit the view
more sudo.conf
less: turn the page to view
Example: Use less to view the /etc/sudo.conf file, you can use PgUp and PgDn on the keyboard to page up and down, and q to end viewing
less sudo.conf
tail: specify the number of lines or view dynamically
Example: Use tail -10 to view the last 10 lines of the /etc/sudo.conf file , Ctrl+C ends
tail -10 sudo.conf
(5) Log view
(6) Authority modification
rwx: r stands for readable, w stands for writable, x stands for the file is an executable file
If any position of rwx becomes -, it means that the file is not readable or writable or executable.
Example: Change the permission of the aaa.txt file to executable file permission, the permission of the aaa.txt file is -rw-------
The first digit: - means it is a file, and d means it is a folder.
The first paragraph (3 digits): represents the authority of the owner.
The second paragraph (3 digits): represents the group the owner belongs to, and
the third paragraph of the permissions of the group members (Last 3 digits): Represents the permissions of other users
421 421 421
- rw- --- ---
Command: chmod +x aaa.txt or use 8421 method
chmod 100 aaa.txt
For example: give the folder test2 permission 777
(7) Packaging and compression
1. Packing and compression
platform | Format |
Compressed file extension for Windows | .zip/.rar |
Packaging files in linux | aa.tar |
compressed files in linux | bb.gz |
Packaged and compressed files in linux | .tar.gz |
Packaged files in Linux generally end with .tar , and compressed commands generally end with .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 pack the compressed file name of the file to be packed
Among them: z: call the gzip compression command to compress
c: pack the file
v: display the running process
f: specify the file name
Example: pack and compress under /usr/tmp The designated name of the compressed package after all files is xxx.tar
tar -zcvf ab.tar aa.txt bb.txt
tar -zcvf ab.tar *
2. Unzip
Command: tar [-zxvf] compressed file
where: x: stands for decompression
Example: decompress ab.tar under /usr/tmp to the current directory
Example: extract ab.tar under /usr/tmp to the root directory /usr
tar -xvf ab.tar -C /usr
C stands for specifying the location of decompression
(8) Search
1.grep
The grep command is a powerful text search tool
ps -ef | grep java # 查找指定java服务进程
ps -ef | grep sshd | grep -v grep # 查找指定服务进程,排除gerp身
ps -ef | grep java -c # 查找指定进程个数
2.find
The find command searches a directory structure for files and performs specified actions on the search results.
find searches the current directory and its subdirectories by default, and does not filter any results (that is, returns all files), displaying them all on the screen.
find . -name "*.log" -ls 在当前目录查找以.log结尾的文件,并显示详细信息。
find /root/ -perm 600 查找/root/目录下权限为600的文件
find . -type f -name "*.log" 查找当目录,以.log结尾的普通文件
find . -type d | sort 查找当前所有目录并排序
find . -size +100M 查找当前目录大于100M的文件
3.locate
locate allows users to quickly search for a path.
By default, it is automatically updated once a day , so the latest changed files cannot be found using the locate command.
To avoid this situation, you can use the updatedb command to manually update the database before using locate.
If there is no query data in the database, it will report
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory This error! updatedb will do!
yum -y install mlocate
If it is a simplified version of the CentOS system, the locate command needs to be installed
Example of use:
updatedb
locate /etc/sh 搜索etc目录下所有以sh开头的文件
locate pwd 查找和pwd相关的所有文件
4.whereis
The whereis command is to locate executable files, source code files, and help files in the file system. The attributes of these files should belong to source code, binaries, or help files.
Example of use:
whereis ls will find all the files related to the ls file
whereis java
5.which
The function of the which command is to search for the location of a system command in the path specified by the PATH variable and return the first search result.
Example of use:
which pwd finds the path where the pwd command is located
which java finds the path of java in the path
(9) System Services
(9) Network and scheduled tasks
1. Host name configuration
[root@node1 ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1
2. IP address configuration
[root@node1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
3. Domain name mapping
The /etc/hosts file is used for ip address resolution when accessing through the host name.
So, what kind of host name you want to visit, you need to put the host name and its corresponding ip address.
[root@node1 ~]# vi /etc/hosts
#### 在最后加上
192.168.52.201 node1
192.168.52.202 node2
192.168.52.203 node3
4. Timing task command crontab configuration
crontab is an instruction used by Unix and Linux to set up scheduled tasks. Through the crontab command, you can execute specified system commands or shell scripts at regular intervals. The unit of time interval can be minute, hour, day, month, week and any combination of the above.
crontab install:
yum install crontabs
Service Operation Instructions:
service crond start ## 启动服务
service crond stop ## 关闭服务
service crond restart ## 重启服务
9.1 Command format
crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
Parameter Description:
-u user: used to set the crontab service of a certain user
file: file is the name of the command file, which means that file is used as the task list file of crontab
And load crontab.
-e: Edit the contents of a user's crontab file. If no user is specified, it means to edit the current
The user's crontab file.
-l: Display the contents of a user's crontab file. If no user is specified, it means display the current
The content of the user's crontab file.
-r: Delete the scheduled task configuration, delete a user's crontab from the /var/spool/cron directory
file, if no user is specified, the crontab file of the current user will be deleted by default.
Command example:
crontab file [-u user] ## 用指定的文件替代目前的crontab
crontab -l [-u user] ## 列出用户目前的crontab
crontab -e [-u user] ## 编辑用户目前的crontab
9.2 Configuration instructions and examples
Command: * * * * * command
Explanation: Hour, day, month, week order
The first column indicates the minute 1~59 and each minute is expressed by * or */1
The second column represents the hour 0~23 (0 represents 0 o'clock)
The third column represents the date 1~31
Column 4 represents the month 1 to 12
The identification number in the fifth column is 0~6 (0 means Sunday)
Command to run in column 6
Configuration example:
First open the file where the scheduled task is located:
crontab -e
execute the date command every minute
*/1 * * * * date >> /root/date.txt
Restart apache every night at 21:30.
30 21 * * * service httpd restart
Restart Apache at 4:45 on the 1st, 10th, and 22nd of each month.
45 4 1,10,22 * * service httpd restart
Restart apache every Saturday and Sunday at 1:10.
10 1 * * 6,0 service httpd restart
Restart apache every 30 minutes between 18:00 and 23:00 every day.
0,30 18-23 * * * service httpd restart
Between 11pm and 7am, restart apache every hour
(10) Other commands
1. View the current directory: pwd
Command: pwd View the current directory path
2. View process: ps -ef
command: ps -ef view all running processes
3. End the process: kill
command: kill pid or kill -9 pid (forcibly kill the process) pid: process number
4. Network communication command:
ifconfig: View network card information
Command: ifconfig or ifconfig | more
ping: check the connection with a machine
Command: ping ip
netstat -an: view the current system port
Command: netstat -an
Search for a specified port
Command: netstat -an | grep 8080
You can also use grep -ef | grep 8080
5. Configure network
command: setup
6. Restart the network
command: service network restart
7. Switch user
command: su - username
8. Turn off the firewall
command: chkconfig iptables off
or:
iptables -L;
iptables -F;
service iptables stop
9. Modify file permissions
Command: chmod 777
10. Clear screen
command: ctrl + l
11. After the shortcut key esc in vi mode
:
Save and exit shortcut key: shift+z+z
The cursor jumps to the last line shortcut key: shift+g
Delete a line: dd
Copy a line of content: y+y
Paste what you copied :p
(11) Linux project deployment
11.1 Install jdk1.8
and uninstall open-jdk first
java -version
rpm -qa | grep java
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
Start installation:
mkdir /usr/local/src/java
rz upload jdk tar package
tar -zxvf jdk-8u181-linux-x64.tar.gz
yum install glibc.i686
Configure environment variables:
vi /etc/profile
Add #set java environment
JAVA_HOME=/usr/local/src/jdk8/jdk1.8.0_181
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH at the end of the line
Save and exit
source /etc/profile Make the changed configuration take effect immediately
java -version Check the JDK version information, if it shows 1.8 it proves success
11.2 Install MySQL5.6
11.2.1 Upload the tar package of MySQL5.6
Create directory: mkdir /usr/local/src/mysql5.6
Upload: MySQL-5.6.34-1.rhel5.x86_64.rpm-bundle.tar to the above directory
11.2.2 Installation
Step 1: Unzip
Instruction: tar -xvf MySQL-5.6.34-1.rhel5.x86_64.rpm-bundle.tar
Step 2: Check if mysql is already installed
Command: rpm -qa | grep mysql
If it is already installed, uninstall it, such as:
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
Step 3: Install the MySQL server
Instruction: rpm -ivh MySQL-server-5.6.34-1.rhel5.x86_64.rpm
Step 4: Install the MySQL client
Instruction: rpm -ivh MySQL-client-5.6.34-1.rhel5.x86_64.rpm
Step 5: View the running status of the MySQL service
Instruction: service mysql status
Step 6: Start the MySQL service
Command: service mysql start
Step 7: Log in to mysql with the root account
There is a hint when installing mysql server:
Note: This password is not safe, so the initial password needs to be changed.
Use the password to log in to the mysql account: mysql -uroot -p
Modify the root password: SET PASSWORD = PASSWORD('root'
)
;
chkconfig --add mysql
Automatically start:
chkconfig mysql on
Query list:
chkconfig
Note: When it is not closed (off), it will not start automatically.
11.2.4 Enable remote access
Login:
mysql -uroot –proot
Set up remote access (using root password):
grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;
Exit mysql, open 3306 firewall in centos environment
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status
11.3 Install the tomcat deployment project
Preparatory work: pack the web project into a war package and rename it to ROOT.war
11.3.1 Create ucenter user
In general, the root user is not used to publish applications, and an ordinary user needs to be created to publish programs;
Create ucenter user:
useradd -d /ucenter ucenter
set password:
passwd ucenter (password ucenter)
Switch user:
su - ucenter
11.3.2 Install Tomcat
Tomcat can be used as long as it is decompressed.
1. Create a web directory
mkdir /ucenter/web
2. Upload apache-tomcat-7.0.57.tar.gz
3. Decompression: tar -xvf apache-tomcat-7.0.57.tar.gz
4. Rename: mv apache-tomcat-7.0.57 itcast-usermanage
5. Start tomcat:
cd itcast-usermanage/bin/
./startup.sh or sh startup.sh
6. Check the log:
tail -f ../logs/catalina.out
7. Check the effect http://192.168.0.160:8080/
Found inaccessible:
8. Firewall opens port 8080
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
9. The installation is successful