列出当前目录的文件和文件夹

ls
bin   CloudResetPwdUpdateAgent  dev  home  lib64       media  opt   root  sbin  sys  usr
boot  CloudrResetPwdAgent       etc  lib   lost+found  mnt    proc  run   srv   tmp  var

 

查看目录所有档案及隐藏的文件,即"."和".."

ls -a
.   .autorelabel  boot                      CloudrResetPwdAgent  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
..  bin           CloudResetPwdUpdateAgent  dev                  home  lib64  media       opt  root  sbin  sys  usr

 

列出排除"."和".."以外的所有文件

ls -A
.autofsck     bin   data  etc   lib    lost+found  mnt  proc  run   selinux  sys  usr
.autorelabel  boot  dev   home  lib64  media       opt  root  sbin  srv      tmp  var

 

按最近修改排序显示文件

ls -lt
total 68
drwxr-xr-x. 77 root root  4096 Aug  8 20:10 etc
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
drwx------.  2 root root 16384 Feb 27 14:58 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
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv

 

以列表的形式整齐的列出所有文件

ls -al
total 76
dr-xr-xr-x. 20 root root  4096 Aug  8 20:08 .
dr-xr-xr-x. 20 root root  4096 Aug  8 20:08 ..
-rw-r--r--   1 root root     0 Feb 27 15:09 .autorelabel
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 20:20 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 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  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var

 

将当前或指定目录信息写入文件

ls -al > mydirectorylist.txt

 

递归列出子目录

ls -R /etc/nginx/
/etc/nginx/:
conf.d        fastcgi.conf.default    koi-utf     mime.types.default  scgi_params          uwsgi_params.default
default.d     fastcgi_params          koi-win     nginx.conf          scgi_params.default  win-utf
fastcgi.conf  fastcgi_params.default  mime.types  nginx.conf.default  uwsgi_params

/etc/nginx/conf.d:
default.conf  ssl.conf  virtual.conf

/etc/nginx/default.d:

 

以文件的大小进行排序

ls -S
lost+found  lib64  sbin  bin  boot  data  etc  home  lib  media  mnt  opt  root  run  selinux  srv  tmp  usr  var  dev  proc  sys

 

列出并区分文件和目录类型

ls -F 
bin@                       dev/   lib64@       opt/   sbin@  usr/
boot/                      etc/   lost+found/  proc/  srv/   var/
CloudResetPwdUpdateAgent/  home/  media/       root/  sys/
CloudrResetPwdAgent/       lib@   mnt/         run/   tmp/

// "@" 表示符号链接、"|" 表示 FIFOS、"/" 表示目录、"=" 表示套接字。

列出某个非当前目录的文件或文件夹

ls /boot
config-3.10.0-957.21.3.el7.x86_64
config-3.10.0-957.5.1.el7.x86_64
config-3.10.0-957.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-4284cfe27c5b48c38adde30f33b4bb60.img
initramfs-3.10.0-957.21.3.el7.x86_64.img
initramfs-3.10.0-957.21.3.el7.x86_64kdump.img
initramfs-3.10.0-957.5.1.el7.x86_64.img
initramfs-3.10.0-957.5.1.el7.x86_64kdump.img
initramfs-3.10.0-957.el7.x86_64.img
symvers-3.10.0-957.21.3.el7.x86_64.gz
symvers-3.10.0-957.5.1.el7.x86_64.gz
symvers-3.10.0-957.el7.x86_64.gz
System.map-3.10.0-957.21.3.el7.x86_64
System.map-3.10.0-957.5.1.el7.x86_64
System.map-3.10.0-957.el7.x86_64
vmlinuz-0-rescue-4284cfe27c5b48c38adde30f33b4bb60
vmlinuz-3.10.0-957.21.3.el7.x86_64
vmlinuz-3.10.0-957.5.1.el7.x86_64
vmlinuz-3.10.0-957.el7.x86_64

//列出 boot 文件夹

当前目录搜索某个文件

ls lib*
lib:
binfmt.d   firmware  kdump       modules         rpm               systemd
cpp        games     kernel      modules-load.d  sendmail          tmpfiles.d
debug      gcc       locale      NetworkManager  sendmail.postfix  tuned
dracut     grub      lsb         polkit-1        sse2              udev
firewalld  kbd       modprobe.d  python2.7       sysctl.d          yum-plugins

lib64:
audit                         libmpc.so.3.0.0
cracklib_dict.hwm             libmpfr.so.4
cracklib_dict.pwd             libmpfr.so.4.1.1
cracklib_dict.pwi             libm.so
crt1.o                        libm.so.6
crti.o                        libncurses.so.5
...

//列出所有以 lib 开头的文件或文件夹

列出以.txt 结尾的文件

ls *.txt
test.txt

 

列出当前目录的文件和文件夹详细信息

ll
total 68
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 20:10 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 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  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var 

//功能相同于 ls -l

按文件大小(以 KB、MB、GB 模式)显示文件

ls -lhS
total 68K
drwx------.  2 root root  16K Feb 27 14:58 lost+found
dr-xr-xr-x.  5 root root 4.0K Jun 24 10:17 boot
drwxr-xr-x   7 root root 4.0K Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root 4.0K Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x. 77 root root 4.0K Aug  8 20:10 etc
drwxr-xr-x.  3 root root 4.0K Aug  7 16:39 home
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 media
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 mnt
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 opt
dr-xr-x---.  6 root root 4.0K Jun 24 10:39 root
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 srv
drwxrwxrwt.  9 root root 4.0K Aug  8 03:36 tmp
drwxr-xr-x. 13 root root 4.0K Feb 27 14:58 usr
drwxr-xr-x. 19 root root 4.0K Feb 27 15:09 var
drwxr-xr-x  19 root root 3.0K Aug  7 15:09 dev
drwxr-xr-x  23 root root  640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root    9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root    8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root    7 Feb 27 14:58 bin -> usr/bin
lrwxrwxrwx.  1 root root    7 Feb 27 14:58 lib -> usr/lib
dr-xr-xr-x  89 root root    0 Aug  7 15:08 proc
dr-xr-xr-x  13 root root    0 Aug  7 15:12 sys

//功能相同于 ll -h

按修改时间排序

ls -lt
total 68
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxr-xr-x. 77 root root  4096 Aug  8 19:50 etc
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
drwx------.  2 root root 16384 Feb 27 14:58 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
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv

 

按创建时间排序

ls -lc
total 68
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 19:50 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 media
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 mnt
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var

 

按访问时间排序

ls -lu
total 68
lrwxrwxrwx.  1 root root     7 Aug  8 16:01 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Aug  8 19:47 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  8 19:47 dev
drwxr-xr-x. 77 root root  4096 Aug  7 18:10 etc
drwxr-xr-x.  3 root root  4096 Aug  8 19:47 home
lrwxrwxrwx.  1 root root     7 Aug  8 19:25 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Aug  8 15:24 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 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 Aug  7 18:10 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Aug  8 19:25 root
drwxr-xr-x  23 root root   640 Aug  7 15:08 run
lrwxrwxrwx.  1 root root     8 Aug  8 16:01 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxrwxrwt.  9 root root  4096 Jun 24 10:39 tmp
drwxr-xr-x. 13 root root  4096 Aug  8 19:26 usr
drwxr-xr-x. 19 root root  4096 Apr 11  2018 var

 

追加 r 为反序排序,追加 a 为显示隐藏文件


友情提示:本站所有文章,如无特殊说明或标注,均为何星星原创发布。与此同时,趋于近年来本站的文章内容频繁被他站盗用与机器采集,现已全局禁用网站文字内容操作,了解详情或转载文章请 点此 继续!
分类: 系统运维

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注