简体   繁体   中英

Linux - Print only filenames for the directory and sub-directories

I'm very new at Linux world.

I've the following directories on my 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

I'm trying to make a print of all the files in all the directories. Basically I am trying to get the following list:

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

I already try 'ls' command and 'ls -al': but it prints also the direcotry name.

I also try to use 'ls -lR | more': but it prints a lot of details that I don't want to use.

Do you recommend any command?

How about using:

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

or even:

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

There is a similar question asked here and it has many answers, hope this helps:

List only file names in directories and subdirectories in bash

如何使用find

find /root/main -type f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM