1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Produce list of files (Linux ls command help)

Discussion in 'Synology' started by Andrew.L, Jun 19, 2018.

  1. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    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
     
  2. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,774
    Location:
    UK
    find /volume1

    EDIT: Removed trailing slash for clarity.
     
    Last edited: Jun 19, 2018
  3. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    This doesn't make sense to me. I'm trying to list files in a directory, not find them. Please elaborate on how this helps me. Thank you.
     
  4. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,774
    Location:
    UK
    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: Jun 19, 2018
  5. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    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
     
  6. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,774
    Location:
    UK
    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
     
  7. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    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
     
  8. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    Thanks!

    It looks like our posts crossed.

    Is there a way to suppress outputting the directories?
     
  9. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,774
    Location:
    UK
    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 ;).
     
  10. Andrew.L

    Andrew.L Occasional Visitor

    Joined:
    Jun 12, 2018
    Messages:
    18
    Perfect!

    I'm learning. Thank you!