Centos common shell commands

Centos common shell commands

File operations

Compress and decompress tar.gz files

Unzip
tar -xzvf 文件名.tar.gz
tar -zxvf 文件名.tar.gz -C 解压文件夹
compression

Centos packages the file into tar.gz command:

tar -zcvf 文件名.tar.gz 要压缩的文件/文件夹

For example, to compress the webfile directory (including the files inside) into
webfile.tar.gz, command:

tar -zcvf webfile.tar.gz webfile

Compress and decompress zip files

Batch decompress all files ending with .zip in the current directory to the specified directory:
for i  in  `find . –name “*.zip”–type f `
do
unzip –d $i /data/www/img/
done

Note: for I in (command); do...done is a common format for for loops, where I is a variable and can be specified by yourself.

File search

Find all files ending with .tar in the current directory and move them to the specified directory:
find . -name “*.tar” -exec mv {
    
    }./backup/ ;

Note:
find –name is mainly used to find a file name.

  • -exec and xargs can be used to take over the previous results and then execute the actions. They are generally used together with find.
    We can extend the use of find.
  • -mtime finds modification time,
  • -type is the specified object type (commonly including f for file and d for directory),
  • -size specifies the size,

For example, it is often used: find LOG files larger than 100M in the current directory 30 days ago and delete them.

find  . -name "*.log" –mtime +30 –typef –size +100M |xargs rm –rf {
    
    };

File movement

The mv command is used to rename files or directories or move files.
Format:

mv options 源文件/目录 目标文件/目录
主要参数:
-i:交互方式操作。如果mv操作将导致对已存在的目标文件的覆盖,此时系统询问是否重写,要求用户回答”y”或”n”,这样可以避免误覆盖文件。
-f:禁止交互操作。mv操作要覆盖某个已有的目标文件时不给任何指示,指定此参数后i参数将不再起作用。

network

Port view

View all port occupancy status
netstat -lnpt  #查看监听(Listen)的端口
netstat -ntlp
# PS:centos7默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools
netstat -antp   #查看所有建立的TCP连接
netstat -tulpn  #查看所有运行中的服务的详细信息
Query the occupancy status of the specified port

Query the occupancy of port 3306

netstat -tulpn |grep 3306

Process management

process port

Query the program occupying the port

Query the PID of the query result to query the details of the occupied program.
Query the PID of the program occupying port 3306 as 10818.

ps -ef | grep 10818

other

language

CentOS7 changes the system display language: Chinese to English

su - switch to root user

vim /etc/locale.conf
将
LANG="zh_CN.UTF-8"
修改为:
LANG="en_US.UTF-8"

Guess you like

Origin blog.csdn.net/u010523811/article/details/132900323
Recommended