首页 > 解决方案 > 剪切cmd不起作用时如何仅显示文件名?

问题描述

我正在查找所有以 .sh 结尾的文件,但只需要显示文件名而不显示 ./

(find -type f \( -name "*[.sh]" \) ) 

它给了我所有以 .sh 和子目录结尾的文件:

./erj.sh
./another/r5.sh
./another/t9.sh
./another/rrr2.sh
./elro/2039jlfsdjf.sh
./elro/tlr.sh
./elro/823.sh
./222.sh
./my_find_sh
./rrr.sh
./4234.sh
./sdf.sh

但是使用“cut -d.-f1”会给我空输出,因为它需要第一个点作为删除点

find -type f \( -name "*[.sh]" \)  | cut -d. -f1

给出空行。

标签: bash

解决方案


试试这个:

find -type f \( -name "*.sh" \) -printf "%f\n"

推荐阅读