car*_*ett 91
使用find
:
find . -maxdepth 1 -type f
Run Code Online (Sandbox Code Playgroud)
使用该-maxdepth 1
选项可确保您只查看当前目录(或者,如果您.
使用某个路径替换该目录).如果您想要该子目录中的所有文件的完整递归列表,只需删除该选项即可.
我喜欢使用ls
选项,例如:
-l
使用长列表格式-t
按修改时间排序,最新的在前-r
排序时倒序-F
,--classify
将指示符(*/=>@| 之一)附加到条目-h
,--human-readable
使用 -l 和 -s,打印尺寸如 1K 234M 2G 等...
有时--color
和其他所有时间。(看ls --help
)
这将显示文件、符号链接、设备、管道、套接字等。
所以
find /some/path -maxdepth 1 ! -type d
Run Code Online (Sandbox Code Playgroud)
可以轻松地按日期排序:
find /some/path -maxdepth 1 ! -type d -exec ls -hltrF {} +
Run Code Online (Sandbox Code Playgroud)
或者
find /some/path -maxdepth 1 -type f
Run Code Online (Sandbox Code Playgroud)
按大小排序:
find /some/path -maxdepth 1 -type f -exec ls -lSF --color {} +
Run Code Online (Sandbox Code Playgroud)
要不显示隐藏条目(名称以点开头),您可以添加! -name '.*'
:
find /some/path -maxdepth 1 ! -type d ! -name '.*' -exec ls -hltrF {} +
Run Code Online (Sandbox Code Playgroud)
然后
您可以替换/some/path
为.
列出当前目录或父..
目录。
find
基于carlpett的答案(find . -maxdepth 1 -type f
)在原理上有效,但与使用的ls
./
ls
含义不同:您会得到一个可能未排序的文件名列表,都带有前缀,并且失去了应用多个选项的能力;
也find
总是查找隐藏的项目,而ls
'的行为取决于-a
or -A
选项的存在与否。
亚历克斯·霍尔(Alex Hall)在对该问题的评论中提出了一项改进,那就是将Shell Globing与以下各项组合:find
find * -maxdepth 0 -type f # find -L * ... includes symlinks to files
Run Code Online (Sandbox Code Playgroud)
ls
的许多其他排序/输出格式选项。汉斯·罗格曼(Hans Roggeman)的ls
+ grep
回答很实用,但是使您-l
无法使用long()输出格式。
为了解决这些局限性,所以我写的fls
(˚F iltering LS)实用程序,
ls
又提供类型过滤功能,f
文件,d
目录和l
符号链接)放在ls
参数列表之前(运行fls --help
或fls --man
了解更多信息)即可。例子:
fls f # list all files in current dir.
fls d -tA ~ # list dirs. in home dir., including hidden ones, most recent first
fls f^l /usr/local/bin/c* # List matches that are files, but not (^) symlinks (l)
Run Code Online (Sandbox Code Playgroud)
支持平台
注意:即使您不使用Node.js,它的程序包管理器npm
仍然可以跨平台使用并且易于安装;尝试
curl -L https://git.io/n-install | bash
随着Node.js的安装,安装如下:
[sudo] npm install fls -g
Run Code Online (Sandbox Code Playgroud)
注意事项:
bash
脚本下载为fls
。chmod +x fls
。$PATH
,例如/usr/local/bin
(macOS)或/usr/bin
(Linux)。 归档时间: |
|
查看次数: |
81361 次 |
最近记录: |