只显示文件或只显示目录,并且显示全路径,shell命令怎么写"/>
Linux:只显示文件或只显示目录,并且显示全路径,shell命令怎么写
1.只显示当前目录下的目录
find . -mindepth 1 -maxdepth 1 -type d
或
find . -maxdepth 1 -type d
或
ls -p | grep /
或
ls -d */
2.只显示当前目录下的文件
find . -mindepth 1 -maxdepth 1 -type f
或
find . -maxdepth 1 -type f
或
ls -p | grep -v /
若文件都有后缀名,则有一种更简单的办法
ls *.*
3.只显示指定目录下的文件,并且显示全路径
把.替换成当前目录的全路径,比如:
find /temp/consul -mindepth 1 -maxdepth 1 -type f
或
find /temp/consul -maxdepth 1 -type f
若文件都有后缀名,也可以
ls /temp/consul/*.* | xargs -d ' '
或
ls /temp/consul/*.* | tr -t ' ' '\n'
更加通用的方法
ls -dp /temp/consul/* | grep -v /$
如果是查找当前目录下的所有文件
ls -dp $PWD/* | grep -v /$
另外,-p有时也可以用-F替代,-F的解释如下:
ls -F appends symbols to filenames. These symbols show useful information about files.
@ means symbolic link (or that the file has extended attributes).
* means executable.
= means socket.
| means named pipe.
> means door.
/ means directory.ls -F | grep -Ev '/|@|*|=|>|\|'
4.window下显示全路径的方式
dir /B /S
参考文档
How to display full path/absolute path with ls command
How do I list files with full paths in Linux?
How to list files without directories, and filter by name (ls options)
更多推荐
Linux:只显示文件或只显示目录,并且显示全路径,shell命令怎么写
发布评论