Linux命令

Linux 运维之道

命令工具

1,touch  创建/修改文件时间 touch  hello.txt 文件不存在则创建,存在则更新为当前系统时间

2,mkdir -p /tmp/test/bank 创建多级目录

3,cp -r 复制目录

cp -r /var/log/ /tmp/ #复制目录/var/log至/tmp/目录下

cp /etc/hosts /tmp/ #复制文件/etc/hosts 至/tmp目录下

cp /etc/hosts /tmp/host #复制文件/etc/hosts 至/tmp目录下并改名为host

4,rm -f 强制删除,

rm-i  提示删除

rm-r 删除目录

5,mv hello.doc  /root/ 移动到root目录下

mv hello.txt hello.doc

6,find /root-name “*.log” 查看以log结尾的的文档

find -iname “Job” 不区分大小查找档案 “Job”

find -empty 查找全部空文档

find -group tom 查找所有属性组为tom的文档

find /mtime -3 查看3天内被修改的文档

find /mtime +4 查看4天前被修改的文档

find /mtime 2 2两天前被修改的文档

find  ./  size +100M 当前目录下大于100M文件

find ./ -type f 查看当前目录下所有普通文件

find / -user tom 查看用户tom拥有的文档

find / -size +1M -a -type f 查找计算机所有大于1M的文件

7,du -sh 显示磁盘空间总和

8,cat -n显示行号包括空白行,-b不显示空白行

9,more 分页查看,空格下一页 q退出

10,less  分页查看

11,head 查看文件头部内容,

head -c 2k /root/install.log #查看文件前2k内容

head -n /root/install.log #查看文件前20行

12,查看文件尾部内容,默认10行

tail -c 2k /root/install.log

tail -20 /root/install.log

tail -f /root/install.log   实时查看

13 wc

wc -c /root/install.log 查看文件字节信息

wc -l /root/install.log 显示文件行数

wc -w /root/install.log 显示文件单词个数

14grep

查找关键词并打印匹配行

grep -i the test.txt 不区分大小写匹配test.txt文件中的the

-w 匹配单词

-v 取反匹配

15,echo 输出

ehco “Hello The Word”

echo -e “a” 计算机蜂鸣

——————————————————————————
gzip压缩与解压缩

gzip hello.txt #压缩文件为 htllo.txt.gz

gzip -d hello.txt.gz #解压缩

bzip2

bzip2 hello.txt

bzip2 -d hello.txt.bz2

——————————————————————————

tar -cf etc.tar /etc/ 将/etc/目录打包保存为etc.tar

tar -xzf etc.tar.bz2 -C /tmp 指定解压路径为tmp

——————————————————————————

网络端口监控 netstat -an|grep 8080

磁盘空间 df-g

——————————————————————————

sudo -i 切换至 root  然后修改密码

su切换身份

原文地址:https://www.cnblogs.com/daimz/p/8426476.html