linux查看output名称,從linux查找命令輸出目錄名

How do I get the name of a folder from a linux find commnad.

如何從linux find commnad獲取文件夾的名稱。

I have a command like this:

我有這樣的命令:

find /root/wgetlog -name -type d -empty

Whic produces the following results:

Whic產生以下結果:

/root/wgetlog/smil3

/root/wgetlog/smil5

/root/wgetlog/smil4

how do I get just the name of the folder:

如何獲得文件夾的名稱:

Example: smil3 smil4 smil5

例如:smil3 smil4 smil5

4 个解决方案

#1

2

find /root/wgetlog -type d -empty -printf "%f\n"

查找/root/wgetlog -type d -empty -printf "%f\n"

#2

1

If all you need is a relative path, then

如果你需要的只是一個相對路徑。

{ pushd /root/wgetlog/; find . -name -type d -empty; popd; }

is the approach, especially if you do care about subdirectories of /root/wgetlog/*.

是方法,特別是如果您確實關心/root/wgetlog/*的子目錄。

#3

0

使用::

find /root/wgetlog -type d -empty -exec basename {} \;

You don't need -name.

你不需要- name。

#4

0

You could also use sed to filter out the leading elements of each path:

您也可以使用sed來過濾每個路徑的主要元素:

$ find /usr/bin -type d

/usr/bin

/usr/bin/multiarch-i386-linux

/usr/bin/multiarch-x86_64-linux

/usr/bin/gda_trml2pdf

/usr/bin/gda_trml2html

...

$ find /usr/bin -type d | sed 's|.*/||'

bin

multiarch-i386-linux

multiarch-x86_64-linux

gda_trml2pdf

gda_trml2html

...

This might be more portable than using the -printf option of find, although that should not be an issue if you stick to Linux.

這可能比使用find的-printf選項更具可移植性,盡管如果您堅持使用Linux,這應該不是問題。

Disclaimer: this will fail horribly if you have newlines in your file/folder names. On the other hand, this snippet is probably not the only thing that would fail in that case...

免責聲明:如果您的文件/文件夾名稱中有新行,這將嚴重失敗。另一方面,這個片段可能不是在這種情況下唯一會失敗的東西……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值