skip to Main Content

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?

2

Answers


  1. How about using find:

    find /root/main -type f
    
    Login or Signup to reply.
  2. How about using:

    find . -type f -exec basename {} ;

    or even:

    find . -type f -printf "%fn"

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search