linux(十)目录相关命令ll、pwd、cd

2023年 10月 11日 18.0k 0

Linux的常用基本命令,大概先了解下他目录相关的命令,linux的目录其实就是windows下的文件夹,文件夹,是windows系统引入的一个概念。这个大概了解一下。

一:查看目录下的文件的命令ll/ls

1 :ls命令

(1):ls -a 查看所有文件,包含隐藏文件

root@iZijvdp1z0m5q4Z:/opt# ls -a
.  ..  .cache  libaio-0.3.109-13.el7.x86_64.rpm  libaio-devel-0.3.109-13.el7.x86_64.rpm  oci8-2.2.0.tgz  oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm  oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

注:文件名前边有.的都是隐藏文件

 

(2):ls -l 查看文件详情

root@iZijvdp1z0m5q4Z:/opt# ls -l
total 53748
drwxr-xr-x  2 root root     4096 Aug 26 10:50 ./
drwxr-xr-x 23 root root     4096 Jul  7 16:13 ../
-rw-r--r--  1 root root        0 Aug 26 10:50 .cache
-rw-r--r--  1 root root    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r--  1 root root    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
-rw-r--r--  1 root root   196449 Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r--  1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r--  1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(3):ls -lh 查看文件详细信息,以人类可读的形式显示文件大小,h单独使用是没有效果的,只有配合l使用的时候,才能发挥其效果。

root@iZijvdp1z0m5q4Z:/opt# ls -lh
total 53M
-rw-r--r-- 1 root root  25K Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root  13K Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root 192K Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r-- 1 root root  52M Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root 599K Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(4):ls -A 查看除 . .. 之外的所有文件及目录的信息

root@iZijvdp1z0m5q4Z:/opt# ls -A
.cache  libaio-0.3.109-13.el7.x86_64.rpm  libaio-devel-0.3.109-13.el7.x86_64.rpm  mysql  oci8-2.2.0.tgz  oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm  oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

查看详细信息的话,可以组合使用

root@iZijvdp1z0m5q4Z:/opt# ls -lA
total 53744
-rw-r--r-- 1 root root        0 Aug 26 10:50 .cache
-rw-r--r-- 1 root root    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
drwxr-xr-x 2 root root     4096 Aug 26 11:03 mysql
-rw-r--r-- 1 root root   196449 Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(5):ls -lF 查看目录的时候并输出文件类型:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识。

root@iZijvdp1z0m5q4Z:/opt# ls -lF
total 53744
-rw-r--r-- 1 root root    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
drwxr-xr-x 2 root root     4096 Aug 26 11:03 mysql/
-rw-r--r-- 1 root root   196449 Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(6):ls -m 以逗号分隔字符

root@iZijvdp1z0m5q4Z:/opt# ls -m
libaio-0.3.109-13.el7.x86_64.rpm, libaio-devel-0.3.109-13.el7.x86_64.rpm, mysql, oci8-2.2.0.tgz, oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm, oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(7):ls -I 显示文件索引节点号(inode)。一个索引节点代表一个文件;

root@iZijvdp1z0m5q4Z:/opt# ls -i
 262184 libaio-0.3.109-13.el7.x86_64.rpm        1323947 mysql            269376 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
 269478 libaio-devel-0.3.109-13.el7.x86_64.rpm   269375 oci8-2.2.0.tgz   269476 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(8):ls -n:以用户识别码和群组识别码替代其名称;

root@iZijvdp1z0m5q4Z:/opt# ls -ln
total 53744
-rw-r--r-- 1 0 0    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 0 0    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
drwxr-xr-x 2 0 0     4096 Aug 26 11:03 mysql
-rw-r--r-- 1 0 0   196449 Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r-- 1 0 0 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 0 0   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(9):ls -R 递归显示当前目录下的所有文件,注意,递归显示所有,这个命令很耗资源

root@iZijvdp1z0m5q4Z:/opt# ls -R
.:
libaio-0.3.109-13.el7.x86_64.rpm  libaio-devel-0.3.109-13.el7.x86_64.rpm  mysql  oci8-2.2.0.tgz  oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm  oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
 
./mysql:
1.txt

 

(10):ls –full-time 完整的显示时间

root@iZijvdp1z0m5q4Z:/opt# ls --full-time
total 53744
-rw-r--r-- 1 root root    24744 2015-11-25 22:50:54.000000000 +0800 libaio-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root    13176 2015-11-25 22:50:57.000000000 +0800 libaio-devel-0.3.109-13.el7.x86_64.rpm
drwxr-xr-x 2 root root     4096 2020-08-26 11:29:54.073539019 +0800 mysql
-rw-r--r-- 1 root root   196449 2020-08-11 09:08:08.000000000 +0800 oci8-2.2.0.tgz
-rw-r--r-- 1 root root 54172532 2020-08-11 09:12:20.000000000 +0800 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root   612416 2020-08-11 09:12:01.000000000 +0800 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm

 

(11):ls -lt 按时间排序显示

root@iZijvdp1z0m5q4Z:/opt# ls -lt
total 53744
drwxr-xr-x 2 root root     4096 Aug 26 11:29 mysql
-rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
-rw-r--r-- 1 root root   196449 Aug 11 09:08 oci8-2.2.0.tgz
-rw-r--r-- 1 root root    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
-rw-r--r-- 1 root root    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm

 

(12):显示彩色目录
打开/etc/bashrc, 加入如下一行:

alias ls="ls --color"

下次启动bash时就可以像在Slackware里那样显示彩色的目录列表了, 其中颜色的含义如下:

  • 蓝色-->目录
  • 绿色-->可执行文件
  • 红色-->压缩文件
  • 浅蓝色-->链接文件
  • 灰色-->其他文件 
  • ls -tl --time-style=full-iso sshd
    ls -ctl --time-style=long-iso
    

     

    最后注意一下,这些命令是可以组合使用的,比如 :ls -lht 就是查看文件详细信息,以人类习惯的方式显示文件大小,以及按照时间排序显示

     

    2 :ll 以及 ls的区别

    首先说明,我一般习惯使用ll,看着方便。

    ll 不是命令,而是 ls -l 命令的一个别名。因此,上边ls的参数针对ll也是适用的。

     

    3 :ls配合通配符使用

    通配符 含义
    * 代表任意个数个字符
    代表任意一个字符,至少1个
    [ ] 表示可以匹配字符组中的任意一个,为数字的时候,代表字符个数
    [abc] 匹配a、b、c中的任意一个
    [a-f] 匹配从a到f范围内的任意一个字符

     

    (1): 列出全部文件,递归列出*

    root@iZijvdp1z0m5q4Z:/opt# ll *
    -rw-r--r-- 1 root root    24744 Nov 25  2015 libaio-0.3.109-13.el7.x86_64.rpm
    -rw-r--r-- 1 root root    13176 Nov 25  2015 libaio-devel-0.3.109-13.el7.x86_64.rpm
    -rw-r--r-- 1 root root   196449 Aug 11 09:08 oci8-2.2.0.tgz
    -rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
    -rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
     
    mysql:
    total 8
    drwxr-xr-x 2 root root 4096 Aug 26 11:29 ./
    drwxr-xr-x 3 root root 4096 Aug 26 11:03 ../
    -rw-r--r-- 1 root root    0 Aug 26 11:29 1.txt
    

     

    (2): 代表多个字符*

    root@iZijvdp1z0m5q4Z:/opt# ll ora*
    -rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
    -rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
    

     

    (3):?代表一个字符

    我们将上边的命令修改一下,将o使用?代替,结果如下:

    root@iZijvdp1z0m5q4Z:/opt# ll ?ra*
    -rw-r--r-- 1 root root 54172532 Aug 11 09:12 oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
    -rw-r--r-- 1 root root   612416 Aug 11 09:12 oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
    

     

    (4):[ ] 匹配字符组

    这里有两种情况需要做一下区分:

    1):逗号相隔的字符串

    root@iZijvdp1z0m5q4Z:/opt# ll [1,2,3].h
    -rw-r--r-- 1 root root 0 Aug 26 15:10 2.h
    

     

    2)-拼接的字符串

    root@iZijvdp1z0m5q4Z:/opt# ll [1-3].h
    -rw-r--r-- 1 root root 0 Aug 26 15:10 2.h
    

     

    二:查看当前所在目录命令pwd

    Pwd命令就是查看当前所在的目录

    root@iZijvdp1z0m5q4Z:/opt# pwd
    /opt
    

     

    他还有更高级的用法,但是我目前还看不明白,后期会补充。

     

    三:进入目录命令cd

    cd就是change directory的缩写,即改变目录。

    (1):cd  .  则是表示目前所在的目录,

    root@iZijvdp1z0m5q4Z:/opt# cd .
    root@iZijvdp1z0m5q4Z:/opt#
    

     

    (2):cd  ..  则表示目前目录位置的上一层目录。

    root@iZijvdp1z0m5q4Z:/opt# cd ..
    root@iZijvdp1z0m5q4Z:/#
    

     

    (3):cd      进入用户主目录(家目录);

    root@iZijvdp1z0m5q4Z:/opt# cd
    root@iZijvdp1z0m5q4Z:~# pwd
    /root
    

    (4):cd ~   进入用户主目录;

    root@iZijvdp1z0m5q4Z:/opt# cd ~
    root@iZijvdp1z0m5q4Z:~# pwd
    /root
    

    (5):cd -   返回进入此目录之前所在的目录;

    root@iZijvdp1z0m5q4Z:~# cd -
    /opt
    root@iZijvdp1z0m5q4Z:/opt#
    

    (6):cd ../..  返回上两级目录;

    root@iZijvdp1z0m5q4Z:/opt# cd ../..
    root@iZijvdp1z0m5q4Z:/#
    

     

    以上基本上就是linux目录相关的命令。大概有ls,pwd,cd

     

    有好的建议,请在下方输入你的评论。

    相关文章

    服务器端口转发,带你了解服务器端口转发
    服务器开放端口,服务器开放端口的步骤
    产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
    如何使用 WinGet 下载 Microsoft Store 应用
    百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
    百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

    发布评论