Linux基础命令 ls
1. ls 列出目录的内容
常用选项如下:
-a --all:
显示目录下所有的文件或子目录,包括隐藏文件、当前目录"."和上级目录".."
[root@localhost ~]# ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .cshrc .pki .tcshrc .viminfo
-A --almost-all:
显示目录下所有的文件或子目录,包括隐藏文件,但不包括"."和".."
[root@localhost ~]# ls -A
.bash_history .bash_logout .bash_profile .bashrc .cshrc .pki .tcshrc .viminfo
-b --escape:
打印 C 风格的转义非图形字符
[root@localhost tmp]# ls
\ test_dir test_txt
[root@localhost tmp]# ls -b
\\ test_dir test_txt
--block-size=SIZE:
配合"-l"选项使用,输出的文件或目录的大小由SIZE决定(值有,K, M, G, T, P...)
[root@localhost tmp]# ls -l --block-size=M
total 0M
drwxr-xr-x 2 root root 1M Apr 19 21:46 \
drwxr-xr-x 2 root root 1M Apr 19 21:44 test_dir
-rw-r--r-- 1 root root 0M Apr 19 21:44 test_txt
[root@localhost tmp]# ls -l --block-size=P
total 0P
drwxr-xr-x 2 root root 1P Apr 19 21:46 \
drwxr-xr-x 2 root root 1P Apr 19 21:44 test_dir
-rw-r--r-- 1 root root 0P Apr 19 21:44 test_txt
--color:
是否显示颜色,有三个选项:never', 'auto' 或 'always'
[root@localhost tmp]# ls --color=auto
\ test_dir test_txt
--d --directory:
显示目录本身,而不会显示目录下的内容
[root@localhost tmp]# ls -d
.
[root@localhost tmp]# ls -ld
drwxrwxrwt. 9 root root 152 Apr 19 21:46 .
-F:
向条目追加指示器(其中之一* / = > @
)
[root@localhost tmp]# ls -F
\/ test_dir/ test_dir_link@ test_txt test_txt_link
--file-type:
于-F相同,但不显示*
[root@localhost tmp]# ls --file-type
\/ test_dir/ test_dir_link@ test_txt test_txt_link
--format=WORD:
显示格式-x
-横向排序(默认),-m
横向排序,逗号分隔,-1
一行显示一个数据
[root@localhost tmp]# ls -x
\ test_dir test_dir_link test_txt test_txt_link
[root@localhost tmp]# ls -m
\, test_dir, test_dir_link, test_txt, test_txt_link
[root@localhost tmp]# ls -1
\
test_dir
test_dir_link
test_txt
test_txt_link
--full-time:
长格式显示,显示详细时间,精确到后9位
[root@localhost tmp]# ls --full-time
total 8
drwxr-xr-x 2 root root 6 2019-04-19 21:46:15.623050216 +0800 \
drwxr-xr-x 2 root root 6 2019-04-19 21:44:19.657044687 +0800 test_dir
lrwxrwxrwx 1 root root 9 2019-04-19 22:21:43.109151663 +0800 test_dir_link -> test_dir/
-rw-r--r-- 2 root root 2 2019-04-19 22:22:46.067154665 +0800 test_txt
-rw-r--r-- 2 root root 2 2019-04-19 22:22:46.067154665 +0800 test_txt_link
-g:
与-l
相似,但不输出属主
[root@localhost tmp]# ls -g
total 8
drwxr-xr-x 2 root 6 Apr 19 21:46 \
drwxr-xr-x 2 root 6 Apr 19 21:44 test_dir
lrwxrwxrwx 1 root 9 Apr 19 22:21 test_dir_link -> test_dir/
-rw-r--r-- 2 root 2 Apr 19 22:22 test_txt
-rw-r--r-- 2 root 2 Apr 19 22:22 test_txt_link
-G --no-group:
与-l
相似,但不输出数组
[root@localhost tmp]# ls -lG
total 8
drwxr-xr-x 2 root 6 Apr 19 21:46 \
drwxr-xr-x 2 root 6 Apr 19 21:44 test_dir
lrwxrwxrwx 1 root 9 Apr 19 22:21 test_dir_link -> test_dir/
-rw-r--r-- 2 root 2 Apr 19 22:22 test_txt
-rw-r--r-- 2 root 2 Apr 19 22:22 test_txt_link
-h --human-readable
与-l
一起使用,打印人性化格式(1K, 1M, 1G)
[root@localhost tmp]# ls -lh /etc/rc.d/init.d/functions
-rw-r--r-- 1 root root 18K Aug 24 2018 /etc/rc.d/init.d/functions
--si:
使用1000位单位,而不是1024
[root@localhost tmp]# ls -l /etc/wgetrc
-rw-r--r--. 1 root root 4479 Oct 31 00:54 /etc/wgetrc
[root@localhost tmp]# ls -l --si /etc/wgetrc
-rw-r--r--. 1 root root 4.5k Oct 31 00:54 /etc/wgetrc
--hide=:
不要列出匹配shell模式的隐含条目(被 -a 或 -A 覆盖)
[root@localhost tmp]# ls
\ test_dir test_dir_link test_txt test_txt_link
[root@localhost tmp]# ls --hide=test*
\
-i --inode:
打印每个文件的索引号
[root@localhost tmp]# ls -i
50812413 \ 16777295 test_dir_link 16777289 test_txt_link
33689716 test_dir 16777289 test_txt
-Q --quote-name:
用双引号将名称括起来
[root@localhost tmp]# ls -Q
"\\" "test_dir" "test_dir_link" "test_txt" "test_txt_link"
-r --reverse:
倒序
[root@localhost tmp]#
[root@localhost tmp]# ls
\ test_dir test_dir_link test_txt test_txt_link
[root@localhost tmp]# ls -r
test_txt_link test_txt test_dir_link test_dir \
-R --recursive:
递归地列出子目录
[root@localhost tmp]# ls -R
.:
\ test_dir test_dir_link test_txt test_txt_link
./\:
./test_dir:
-s --size:
打印每个文件的分配大小,以块为单位
[root@localhost tmp]# ls -ls
total 2048
0 drwxr-xr-x 2 root root 6 Apr 19 21:46 \
0 drwxr-xr-x 2 root root 6 Apr 19 21:44 test_dir
0 lrwxrwxrwx 1 root root 9 Apr 19 22:21 test_dir_link -> test_dir/
1024 -rw-r--r-- 2 root root 1048576 Apr 19 23:28 test_txt
1024 -rw-r--r-- 2 root root 1048576 Apr 19 23:28 test_txt_link
-S:
按文件大小进行排序
[root@localhost tmp]# ls -lhaS
total 16K
-rw-r--r-- 2 root root 512 Apr 19 23:30 test_txt
-rw-r--r-- 1 root root 512 Apr 19 23:30 test_txt_a
-rw-r--r-- 2 root root 512 Apr 19 23:30 test_txt_link
-rw-------. 1 root root 247 Apr 17 06:35 .ifstat.u0
dr-xr-xr-x. 17 root root 244 Apr 17 09:29 ..
drwxrwxrwt. 9 root root 212 Apr 19 23:30 .
drwxr-xr-x 2 root root 21 Apr 19 23:30 test_dir
lrwxrwxrwx 1 root root 9 Apr 19 22:21 test_dir_link -> test_dir/
drwxr-xr-x 2 root root 6 Apr 19 21:46 \
drwxrwxrwt. 2 root root 6 Apr 16 22:49 .font-unix
drwxrwxrwt. 2 root root 6 Apr 16 22:49 .ICE-unix
drwxrwxrwt. 2 root root 6 Apr 16 22:49 .Test-unix
drwxrwxrwt. 2 root root 6 Apr 16 22:49 .X11-unix
drwxrwxrwt. 2 root root 6 Apr 16 22:49 .XIM-unix
-U:
不进行排序,按目录顺序列出条目
-t:
按修改时间排序,即最近更改的时间进行排序
[root@localhost tmp]# ls -lht
total 12K
-rw-r--r-- 2 root root 519 Apr 19 23:46 test_txt
-rw-r--r-- 2 root root 519 Apr 19 23:46 test_txt_link
-rw-r--r-- 1 root root 512 Apr 19 23:30 test_txt_a
drwxr-xr-x 2 root root 21 Apr 19 23:30 test_dir
lrwxrwxrwx 1 root root 9 Apr 19 22:21 test_dir_link -> test_dir/
drwxr-xr-x 2 root root 6 Apr 19 21:46 \
-X:
按条目扩展按字母顺序排序
-u:
显示最后一次访问的时间,而不是最近修改时间
--time-style=:
显示时间的格式,可选参数有:full-iso,long-iso,iso,locale,或者+FORMAT
[root@localhost tmp]# ls -l test_txt --time-style=full-iso
-rw-r--r-- 2 root root 519 2019-04-19 23:46:52.748395309 +0800 test_txt
[root@localhost tmp]# ls -l test_txt --time-style=long-iso
-rw-r--r-- 2 root root 519 2019-04-19 23:46 test_txt
[root@localhost tmp]# ls -l test_txt --time-style=iso
-rw-r--r-- 2 root root 519 04-19 23:46 test_txt
[root@localhost tmp]# ls -l test_txt --time-style=locale
-rw-r--r-- 2 root root 519 Apr 19 23:46 test_txt
[root@localhost tmp]# ls -l test_txt --time-style=+"%F %T"
-rw-r--r-- 2 root root 519 2019-04-19 23:46:52 test_txt
Linux基础命令 ls的更多相关文章
- Linux基础命令ls
目录处理命令:ls -a 显示所有文件,包括隐藏文件 --all -l h 详细信息显示 --long --human -d 查看目录属性 - -i 查看文件唯一编号 -表示文件 d表示目录 l ...
- 第四节,Linux基础命令
第四节,Linux基础命令 命令是系统操作员对系统传入的指令,传入指令后回车,系统接收到指令做出相应的行为 1.查看用户位于系统什么位置 [pmd]检查操作用户位于系统的什么位置 命令 ...
- 【Python之路】第一篇--Linux基础命令
pwd 命令 查看”当前工作目录“的完整路径 pwd -P # 显示出实际路径,而非使用连接(link)路径:pwd显示的是连接路径 . 表示当前目录 .. 表示上级目录 / 表示根目录 ls ...
- linux基础命令学习笔记(二)
linux基础命令学习笔记(二) 1.kill :终止进程 kill pid (唯一标示一个进程) kill -9 强制终止 kill -15 命令未结束不能终止 # ps aux 查看所有进程 ...
- 2.Linux基础命令
linux内一切皆文件,没有文件夹只有目录,目录也是一种文件 1.一些常用按键: 将鼠标的光标从虚拟机里切换回来:Ctrl+Alt 拖动Ubuntu内的对话框:Alt键+鼠标左键拖动 清屏:Ctrl+ ...
- linux基础命令一
linux基础命令一 1.date命令 date命令介绍:显示或者设置系统日期 date命令的语法: 显示日期:date [options...] [+FORMAT] FORMAT:为显示日期的格 ...
- linux基础命令:
linux基础命令: 显示 echo 输出我写的内容 ls 查看当前目录的文件 pwd 查看当前目录 ifconfig 查看网卡信息 grep 过滤 -v 取反 -n man 查看命令的帮助信息 md ...
- 常用的linux基础命令
常用的linux基础命令 1.ls 显示目录属性 -l:(也可以简写成ll),列表显示权限等属性 -a:显示所有文件包括隐藏文件等 -d:只列出目录本身 2.chgrp 改变档案所属群组 eg:chg ...
- Linux基础命令-文件与目录
Linux基础命令-文件与目录 参考:<鸟哥linux私房菜>五-七章,17/12/5复习,18/01/15复习 文件权限 rwx421:用户,用户组,其他 umask查看默认权限:000 ...
随机推荐
- vue案例 - vuex+sessionstorage解决vue项目刷新后页面空白/数据丢失
第一部分 SessionStorage 首先查看sessionStorage的地方在控制台的 Application > Storage > Session Storage这里: 根据se ...
- TUN/TAP编程实现
其实关于这两种设备的编程,基本上属于八股文,大家一般都这么干. 启动设备之前 有的linux 并没有将tun 模块编译到内核之中,所以,我们要做的第一件事情就是检查我们的系统是否支持 TUN/TAP ...
- 2018php最新面试题之PHP核心技术
一.PHP核心技术 1.写出一个能创建多级目录的PHP函数(新浪网技术部) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?php ...
- To me
1.流泪的时候不做任何决定: 2.不反复思考同一个问题: 3.不害怕做错什么: 4.有负面情绪是正常的: 5.一切的烦恼都是自找的: 6.说过的话一定要做到: 7.不要去害怕做一件事: 8.无论是对是 ...
- Apache ab性能测试结果分析
Apache ab性能测试结果分析 测试场景:模拟10个用户,对某页发起总共100次请求. 测试命令: ab -n 100 -c 10 地址 测试报告: Server Software: 被测服务器软 ...
- sass基础常用指南
一.变量 $global-color:red; .nav{ background:$global-color; } 二.sass命名时横杠和下划线不区分 $global-color:yellow; . ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- GDB基础学习
GDB基础学习 要调试C/C++程序,首先在编译时,我们必须要把调试信息加到可执行文件中.使用编译器(cc/gcc/g++)的-g参数可以做到这一点,比如: gcc -g test.c -o test ...
- 转 Master-Worker模式 并行程序设计模式--Master-Worker模式
简介 Master-Worker模式是常用的并行设计模式.它的核心思想是,系统有两个进程协议工作:Master进程和Worker进程.Master进程负责接收和分配任务,Worker进程负责处理子任务 ...
- SDWebImage之UIView+WebCache
UIView+WebCache是我们能很方便的使用sd_setImageWithURL:系列方法来加载图片的关键类.UIButton(WebCache).MKAnnotationView(WebCac ...