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

 一、linux下

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 '/|@|*|=|>|\|'

 二、windows下

1.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)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值