Linux常用命令(下)

传说中的大佬级别的命令:

rm -rf /*

今天就从这个rm命令讲起,来讲与文件目录操作有关的命令。

rm其实就是remove ,-rf表示强制删除目录,而"/"则是根目录。在Windows上也许有C盘、D盘,但在Linux上一切都来源于"/",且一切都是文件。所以对文件与目录的操作也可谓重中之重。至于"*"则是通配符,这里略过。

pwd命令:显示用户当前所处的工作目录(”~”表示当前用户目录)

[tom@csbebetter ~]$ pwd
/home/tom

cd命令:切换工作目录。(cd - 可以返回上一次目录)。目录切换,中括号中也会有相应的显示。

[tom@csbebetter ~]$ cd /etc
[tom@csbebetter etc]$ cd -
/home/tom

ls命令:显示当前目录的文件,-a显示全部文件,-l显示文件详细信息。

[tom@csbebetter /]$ ls -al
total 68
dr-xr-xr-x. 18 root root  4096 Jan 20 20:05 .
dr-xr-xr-x. 18 root root  4096 Jan 20 20:05 ..
-rw-r--r--   1 root root     0 Dec 28 03:41 .autorelabel
lrwxrwxrwx.  1 root root     7 Dec 28 11:37 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Dec 28 11:49 boot
drwxr-xr-x  19 root root  2960 Jan 20 20:05 dev
drwxr-xr-x. 76 root root  4096 Jan 20 20:44 etc
drwxr-xr-x.  3 root root  4096 Jan 20 20:38 home
lrwxrwxrwx.  1 root root     7 Dec 28 11:37 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Dec 28 11:37 lib64 -> usr/lib64
drwx------.  2 root root 16384 Dec 28 11:37 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 opt
dr-xr-xr-x  84 root root     0 Jan 20 20:05 proc
dr-xr-x---.  7 root root  4096 Jan 20 22:09 root
drwxr-xr-x  23 root root   620 Jan 20 22:08 run
lrwxrwxrwx.  1 root root     8 Dec 28 11:37 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Jan 21 04:05 sys
drwxrwxrwt.  9 root root  4096 Jan 21 03:13 tmp
drwxr-xr-x. 13 root root  4096 Dec 28 11:37 usr
drwxr-xr-x. 19 root root  4096 Dec 28 03:41 var

cat命令:查看纯文本文件(内容较少)

more命令:查看纯文本文件(内容较多)

head命令:查看纯文本文件的前n行,下为查看该文件的前20行。

head -n 20 initial-setup-ks.cfg

wc命令:统计指定文本的行数,字数,字节数,    -l只显示行数,-w只显示单词数,-c只显示字节数

stat命令:查看文件的具体存储信息与存储时间等

[tom@csbebetter ~]$ stat txt.txt 
  File: ‘txt.txt’
  Size: 25          Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d  Inode: 1314827     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     tom)   Gid: ( 1000/     tom)
Access: 2021-01-21 10:25:00.498812018 +0800
Modify: 2021-01-21 10:25:00.498812018 +0800
Change: 2021-01-21 10:25:00.498812018 +0800
 Birth: -

diff命令:显示多个文本的差异(这里我创建了两个相似的文本文件)。-c可以详细显示差异,-brief只会显示是否相同。

[tom@csbebetter ~]$ diff -c txt.txt txt1.txt
*** txt.txt  2021-01-21 10:25:00.498812018 +0800
--- txt1.txt  2021-01-21 10:27:33.647650289 +0800
***************
*** 1,3 ****
  hello world
  tom
! hey guys
--- 1,3 ----
  hello world
  tom
! hey guys!

touch命令:创建空白文件或设置文件时间(不得不说这个操作比较强)
-a修改“读取时间”,-m修改“修改时间”,-d同时修改。

[tom@csbebetter ~]$ touch -d "1999-02-08 11:11" txt1.txt
[tom@csbebetter ~]$ ls -l
total 8
-rw-rw-r-- 1 tom tom 26 Feb  8  1999 txt1.txt
-rw-rw-r-- 1 tom tom 25 Jan 21 10:25 txt.txt

mkdir命令:创建空白的目录,-p可以递归创建。

[tom@csbebetter ~]$ mkdir -p Music/netmusic
[tom@csbebetter ~]$ ls
Music  txt1.txt  txt.txt
[tom@csbebetter ~]$ cd Music/
[tom@csbebetter Music]$ ls
netmusic

cp命令:复制文件与目录,
    cp[选项] 源文件 目标文件

mv命令:剪切文件或重命名。
    mv[选项] 源文件 [目标路径|目标文件名]

file命令:查看文件类型

[tom@csbebetter ~]$ file txt.txt 
txt.txt: ASCII text

tar命令:打包与压缩相关命令(下面是常用选项)
    打包:tar -czvf 打包目录
    解压:tar -xzvf 压缩包

-t, --list                 列出归档内容

-c, --create 创建一个新归档

-x, --extract, --get 从归档中解压出文件

-z, --gzip, --gunzip, --ungzip 通过 gzip 过滤归档

-v, --verbose 详细地列出处理的文件

-f, --file=ARCHIVE 使用归档文件或 ARCHIVE 设备

grep命令:文本中执行关键词搜索,我查看IP时一般用它。

说到查找命令,find命令肯定不能少。

 感谢浏览,如有错误,欢迎指正。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值