What's new

Produce list of files (Linux ls command help)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Andrew.L

Occasional Visitor
I'm not very familiar with Linux commands and need some help in producing the kind of list I need.

My directory structure is as follows:
  • Fagan_NAS_01 (root)
    • Fagan_General (directory)
      • #recycle (directory)
      • list (directory)
      • TossMe (directory)
        • testfile.txt (file)
      • testfile.txt (file)
    • Output (directory)
      • #recycle (directory)
      • filesfolders.txt (file)
I can enter a task with the following user defined script:
Code:
ls -FARX /volume1/Fagan_General > /volume1/Output/filesfolders.txt

The code will get me a list close to what I want, but I'd prefer something more like the following:
Code:
/volume1/Fagan_General/testfile.txt
/volume1/Fagan_General/Tossme/testfile.txt
/volume1/Output/filesfolders.txt

Is this possible? If so, what would be the syntax? I'm not getting it figured out.

Thanks in advance,
Andrew
 
The default action of the find command is "-print" which prints the filename. So you end up with a list of files similar to ls.

I don't know whether the output is exactly what you want because "something more like the following" isn't specific.

Code:
# find /lib
/lib/
/lib/alsa
/lib/alsa/init
/lib/alsa/init/info
/lib/alsa/init/test
/lib/alsa/init/00main
/lib/alsa/init/hda
/lib/alsa/init/help
/lib/alsa/init/ca0106
/lib/alsa/init/default
/lib/python
/lib/python/pysamba
/lib/terminfo
/lib/terminfo/v
/lib/terminfo/v/vt52
/lib/terminfo/v/vt100
 
Last edited:
My apologies if I wasn't clear. I'm trying to output the list to a file, as shown in the sample "ls" command I've tried. That command gets me results, but I'm thinking I should be able to get it closer to the example output I provided.

When I say, "more like the following", this is the example that would be the ideal, but I'd be accepting of trailing asterisks, dots between the directory name and the file name etc. I can parse the extra material out in Excel. But the format of "/directory/sub-directory/filename.extension" would be ideal.

I do not understand how the find command creates an output file. Do I append the destination? The following perhaps? (I hesitate to just try running code blindly.)

Code:
find /volume1/Fagan_General > /volume1/Output/filesfolders.txt
 
I do not understand how the find command creates an output file. Do I append the destination? The following perhaps? (I hesitate to just try running code blindly.)

Code:
find /volume1/Fagan_General > /volume1/Output/filesfolders.txt
Yes, that is exactly the code you want. Bear in mind that Linux doesn't have the concept of file extensions like DOS/Windows does. There's just filenames. i.e.

/volume1/Output/this-is_my.list-files_folders-and-stuff
 
UPDATE:
Against my better judgement, I ran the following code.
Code:
find /volume1/Fagan_General > /volume1/Output/filesfolders.txt
It output the following:
Code:
/volume1/Fagan_General
/volume1/Fagan_General/@eaDir
/volume1/Fagan_General/@eaDir/@tmp
/volume1/Fagan_General/#recycle
/volume1/Fagan_General/TossMe
/volume1/Fagan_General/TossMe/testfile.txt
/volume1/Fagan_General/testfile.txt
/volume1/Fagan_General/list
I can work with this. I can use Excel to filter out all the rows that do not represent a path/file.

But if there were syntax options I could add so the directory rows were not 'printed' then that would be great. Is this possible? If so, how?

Thanks again,
Andrew
 
Is there a way to suppress outputting the directories?
Yes, you could say "print all files of type 'file'":

find /lib -type f

Alternatively you could say "print all file types that are not directories":

find /lib ! -type d

There is a subtle difference between the two commands because as well as files and directories Linux also has block devices, character devices, pipes, links and sockets.

But normally you'd just use the first command ;).
 
Similar threads
Thread starter Title Forum Replies Date
D How to recover lost files from Synology NAS DS415+ Synology 15

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top