Linux:只显示文件或只显示目录,并且显示全路径,shell命令怎么写

编程入门 行业动态 更新时间:2024-10-24 18:19:35

Linux:<a href=https://www.elefans.com/category/jswz/34/1758372.html style=只显示文件或只显示目录,并且显示全路径,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命令怎么写

本文发布于:2023-12-03 12:37:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1655429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:只显示   路径   命令   文件   目录

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!