bash - 剪切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
给出空行。
解决方案
试试这个:
find -type f \( -name "*.sh" \) -printf "%f\n"
推荐阅读
- json - 如何读取json文件并将值分配给shell中的变量
- r - 根据季度时间序列绘制堆积条形图
- android - 如何解决“当 Android Studio 自动将某些代码转换为符号时”的问题
- visual-studio-2015 - Visual Studio 安装项目和 msm 文件
- microsoft-graph-api - 如何通过 Microsoft Graph 检查 Outlook 自定义属性
- typo3 - 使用 M:M 关系扩展 TYPO3 新闻存储库
- javascript - 在下面的代码中,为什么会提示“OUCH”?
- yeoman - 找不到“哟”二进制文件。确保它已安装并在您的 $PATH 中。你能告诉我问题是什么吗?
- java - ConcurrentModificationException 偶尔
- google-sheets - 如何准确识别 Google 表格中的错误类型?