【问题标题】:Linux - Print only filenames for the directory and sub-directoriesLinux - 仅打印目录和子目录的文件名
【发布时间】:2023-03-15 17:24:01
【问题描述】:

我是 Linux 世界的新手。

我的 linux (centos rhel fedora") 上有以下目录:

Folder_Root:
    /root/main
        /root/main/files
            /root/main/files/file_1.txt
            /root/main/files/file_2.ssh
        /root/main/files/file_2.txt
    /root/main/file_3.txt

我正在尝试打印所有目录中的所有文件。基本上我正在尝试获取以下列表:

file_1.txt
file_2.ssh
file_2.txt
file_3.txt

我已经尝试了“ls”命令和“ls -al”:but it prints also the direcotry name.

我也尝试使用 'ls -lR |更多':but it prints a lot of details that I don't want to use.

你有什么命令推荐吗?

【问题讨论】:

  • ls -1 -R怎么样
  • 谢谢 :) 太好了!但是是否可以排除有关目录的详细信息?

标签: linux ls


【解决方案1】:

如何使用:

find . -type f -exec basename {} \;

甚至:

find . -type f -printf "%f\n"

这里有一个类似的问题,它有很多答案,希望这会有所帮助:

List only file names in directories and subdirectories in bash

【讨论】:

    【解决方案2】:

    find怎么样:

    find /root/main -type f
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 2018-05-13
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      相关资源
      最近更新 更多