Linux dir命令

Linux dir命令:列出目录或文件信息

Linux dir命令 功能描述

使用dir命令可以列出目录或文件的信息。

Linux dir命令 语法

dir [选项] [文件]

命令中各选项的含义如表所示。

Linux dir命令 语法

Linux dir命令 示例

列出/root目录的信息

[root@rhel ~]# dir /root
anaconda-ks.cfg install.log install.log.syslog公共的 模板 视频 图片 文档 下载 音乐 桌面

列出/root目录的信息,连隐藏文件都列出

[root@rhel ~]# dir -a /root
.             .dbus           .ICEauthority       .ssh
..            .esd_auth         .imsettings.log      .targetcli
.abrt          .gconf           install.log          .tcshrc
anaconda-ks.cfg .gconfd          install.log.syslog     公共的
.bash_history   .gnome2         .local             模板
.bash_logout   .gnome2_private   .nautilus           视频
.bash_profile   .gnote           .pulse             图片
.bashrc       .gnupg          .pulse-cookie        文档
.cache        .gstreamer-0.10    .recently-used.xbel    下载
.config       .gtk-bookmarks    .redhat            音乐
.cshrc        .gvfs            .rnd              桌面

以较长格式列出/root目录的信息

[root@rhel ~]# dir -l /root
总用量 184
-rw-------. 1 root root 8646 12月 3 04:28 anaconda-ks.cfg
-rw-r--r--. 1 root root 103928 12月 3 04:28 install.log
-rw-r--r--. 1 root root 25094 12月 3 04:20 install.log.syslog
drwxr-xr-x. 2 root root 4096 8月 192013 公共的
drwxr-xr-x. 2 root root 4096 8月 192013 模板
drwxr-xr-x. 2 root root 4096 8月 192013 视频
drwxr-xr-x. 2 root root 4096 8月 192013 图片
drwxr-xr-x. 2 root root 4096 8月 192013 文档
drwxr-xr-x. 2 root root 4096 8月 192013 下载
drwxr-xr-x. 2 root root 4096 8月 192013 音乐
drwxr-xr-x. 2 root root 4096 8月 192013 桌面

显示/root/install.log文件的inode号

[root@rhel ~]# dir -i /root/install.log
3670018 /root/install.log

根据修改时间排序,以较长格式列出/root目录的信息

[root@rhel ~]# dir -lt /root
总用量 184
-rw-------.1 root root 8646 12月 3 04:28 anaconda-ks.cfg
-rw-r--r--.1 root root 103928 12月 3 04:28 install.log
-rw-r--r--.1 root root 25094 12月 3 04:20 install.log.syslog
drwxr-xr-x.2 root root 4096 8月 192013公共的drwxr-xr-x.2 root root 4096 8月 192013模板
drwxr-xr-x. 2 root root 4096 8月 192013 视频
drwxr-xr-x. 2 root root 4096 8月 192013 图片
drwxr-xr-x. 2 root root 4096 8月 192013 文档
drwxr-xr-x. 2 root root 4096 8月 192013 下载
drwxr-xr-x. 2 root root 4096 8月 192013 音乐
drwxr-xr-x. 2 root root 4096 8月 192013 桌面

根据文件大小排序,以较长格式列出/root目录的信息

[root@rhel ~]# dir -Sl /root
总用量 184
-rw-r--r--. 1 root root 103928 12月 3 04:28 install.log
-rw-r--r--. 1 root root 25094 12月 3 04:20 install.log.syslog
-rw-------. 1 root root 8646 12月 3 04:28 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 8月 192013 公共的
drwxr-xr-x. 2 root root 4096 8月 192013 模板
drwxr-xr-x. 2 root root 4096 8月 192013 视频
drwxr-xr-x. 2 root root 4096 8月 192013 图片
drwxr-xr-x. 2 root root 4096 8月 192013 文档
drwxr-xr-x. 2 root root 4096 8月 192013 下载
drwxr-xr-x. 2 root root 4096 8月 192013 音乐
drwxr-xr-x. 2 root root 4096 8月 192013 桌面

以块数形式显示/root目录中每个文件分配的尺寸

[root@rhel ~]# dir -s /root
总用量 184
12 anaconda-ks.cfg 32 install.log.syslog  4模板  4图片  4下载  4桌面
108 install.log   4公共的       4视频  4文档  4音乐

根据修改时间排序,排序时保留顺序,以较长格式列出/root目录的信息

[root@rhel ~]# dir -ltr /root
总用量 184
drwxr-xr-x.2 root root 4096 8月 192013桌面
drwxr-xr-x.2 root root 4096 8月 192013音乐
drwxr-xr-x.2 root root 4096 8月 192013下载
drwxr-xr-x.2 root root 4096 8月 192013文档
drwxr-xr-x.2 root root 4096 8月 192013图片
drwxr-xr-x.2 root root 4096 8月 192013视频
drwxr-xr-x.2 root root 4096 8月 192013模板
drwxr-xr-x.2 root root 4096 8月 192013公共的
-rw-r--r--.1 root root 25094 12月 3 04:20 install.log.syslog
-rw-r--r--.1 root root 103928 12月 3 04:28 install.log
-rw-------.1 root root 8646 12月 3 04:28 anaconda-ks.cfg

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程