Linux常用命令

89 阅读1分钟
  • 查看目录大小

du -h /root/ --max-depth=1
  • 挂载分区使用情况

df -lh
  • 端口使用情况

lsof -i :port_number 
lsof -i :port_number |grep "(LISTEN)" 占用情况

netstat -anp|grep port_number
  • 查看软件安装路径

查看软件安装路径:

whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

whereis mongo
mongo: /usr/bin/mongo /usr/share/man/man1/mongo.1

whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/lib64/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz


查询运行文件所在路径:

which mysql 
/usr/bin/mysql

which mongo
/usr/bin/mongo

which nginx
/usr/sbin/nginx


查询文件/文件夹所在位置

find / -name mysql
  • 压缩文件处理

gz gunzip

// 压缩文件
gzip test.txt
// 解压文件
gunzip test.txt.gz
// 保留原文件需要加上-c选项

zip unzip

zip
// 压缩文件
zip test.zip test.txt
// 压缩目录
zip –r test.zip ./test/test.txt

// 解压文件
unzip test.zip 
// 解压到指定目录
unzip -d test.zip ./test 
// unzip解压war包
unzip -oq common.war -d common
  • 查看文件

wc -l 查看文件行数
  • grep添加颜色

vim ~/.bashrc   
alias grep='grep --color'
source ~/.bashrc 
  • CentOS 安装rz和sz命令

yum install lrzsz