暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Linux入门级命令,让你玩转Linux(2)

赤子孤独 2021-06-25
274

点击蓝字

关注我们

昨天的文章结尾展示了删库跑路的命令,今天,来,音乐走起。
    rm -rf *
    复制

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


    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命令肯定不能少。


                        就这么多了,感谢浏览。

                        谢谢大家。


                        扫码关注我们


                        微信号|赤子孤独




                        文章转载自赤子孤独,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                        评论