【Linux】Linux常用操作命令
时间:2022-12-26 09:30:00
概述
显示目录内容
ls pathls -a path # 查看所有文件 包括隐藏文件ls -l =ll # 查看文件的详细信息 包括权限 类型 时间 大小等ll -h path # 表示人性化的显示内容ll * # * 通配符表示任何字符 ? 表示只有一个字符
切换目录
pwd # 检查你目前的目录cd path # 注意自己写的是相对还是绝对的 还可结合特殊符号使用cd ./cd /cd ../cd ~
创建、删除
[root@node1 ~] # mkdir /a/b/cmkdir: cannot create directory ‘ /a/b/c ’ : No such file or directory[root@node1 ~] # mkdir -p /a/b/c[root@node1 ~] # rm -rf /a/b/c[root@node1 ~] # rm -rf /a-f # 强制删除 不给与提示-r # 递归删除 针对文件夹-rf # 杀伤力极大 问问自己在干什么坐牢眼: rm -rf /*
复制、移动
cp [options] source... directorymv source_file ( 文件 ) dest_file ( 文件 ) # 将源文件名 source_file 改为目标文件名 dest_filemv source_file ( 文件 ) dest_directory ( 目录 ) # 将文件 source_file 移动到目标目录 dest_directory 中mv source_directory ( 目录 ) dest_directory ( 目录 ) # 目录名 dest_directory 已存在,将source_directory 移动到目录名 dest_directory 中;目录名 dest_directory 不存在则source_directory 改名为目录名 dest_directorymv source_directory ( 目录 ) dest_file ( 文件 ) # 出错
文件内容查看
其他
[root@node1 ~] # ls1.txt anaconda-ks.cfg hello lrzsz-0.12.20.tar.gz test test.file[root@node1 ~] # ls | grep ^ttesttest.file# 相当于 print 将内容输出 console 控制台[root@node1 test] # echo 111111[root@node1 test] # echo "hello "hello
解压压缩命令
# tar cvf 打包名 .tar 文件或者目录[root@node1 test] # ll-rw-r--r-- 1 root root 0 Aug 10 19:27 1.txt-rw-r--r-- 1 root root 0 Aug 10 19:27 2.txt[root@node1 test] # tar -cvf test.tar 1.txt 2.txt1.txt2.txt[root@node1 test] # ll-rw-r--r-- 1 root root 10240 Aug 10 19:28 1.txt-rw-r--r-- 1 root root 0 Aug 10 19:27 2.txt-rw-r--r-- 1 root root 20480 Aug 10 19:28 test.tar
# tar xvf 打包名 .tar# tar xvf 打包名 .tar -C 指定解包目录[root@node1 test] # ll-rw-r--r-- 1 root root 20480 Aug 10 19:28 test.tar[root@node1 test] # tar xvf test.tar1.txt2.txt[root@node1 test] # ll-rw-r--r-- 1 root root 10240 Aug 10 19:28 1.txt-rw-r--r-- 1 root root 0 Aug 10 19:27 2.txt-rw-r--r-- 1 root root 20480 Aug 10 19:28 test.tar
[root@node1 test] # ll-rw-r--r-- 1 root root 10240 Aug 10 19:28 1.txt-rw-r--r-- 1 root root 0 Aug 10 19:27 2.txt[root@node1 test] # tar zcvf test.tar.gz 1.txt 2.txt[root@node1 test] # tar zcvf test.tgz 1.txt 2.txt[root@node1 test] # ll-rw-r--r-- 1 root root 10240 Aug 10 19:28 1.txt-rw-r--r-- 1 root root 0 Aug 10 19:27 2.txt-rw-r--r-- 1 root root 142 Aug 10 19:35 test.tar.gz-rw-r--r-- 1 root root 142 Aug 10 19:35 test.tgz
[root@node1 test] # tar zxvf test.tar.gz # 解压到当前目录1.txt2.txt[root@node1 test] # tar zxvf test.tar.gz -C /root/ #-C 参数可以设定解压到指定目录1.txt2.txt
时间、日期查看
[root@node1 linux02] # dateTue May 18 14:44:13 CST 2021[root@node1 linux02] # date +"%Y-%m-%d %H:%M:%S"2021-05-18 14:44:53[root@node1 linux02] # calMay 2021Su Mo Tu We Th Fr Sa12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31
内存、磁盘用率查看
[root@node1 linux02] # df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 12M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/centos-root 38G 1.5G 36G 5% / # 重点关注这一行/dev/sda1 1014M 152M 863M 15% /boot/dev/mapper/centos-home 19G 33M 19G 1% /hometmpfs 378M 0 378M 0% /run/user/0tmpfs 378M 0 378M 0% /run/user/1000# 内存使用情况[root@node1 linux02] # free -htotal used free shared buff/cache availableMem: 3.7G 257M 3.0G 11M 467M 3.2GSwap: 3.9G 0B 3.9G