ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Working with Files In Linux

    IT Discussion
    linux
    3
    12
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      I'm not clear what you are asking. Do you want a list of ALL files under said /directory or are you looking for only certain ones?

      anthonyhA 1 Reply Last reply Reply Quote 0
      • anthonyhA
        anthonyh @scottalanmiller
        last edited by

        @scottalanmiller said:

        No need to get the filename, the absolute path will include that already.

        I want the file name and path to said file separate, but I suppose I could separate them through another step. I'm going to be matching by file name. basically table1.filename = table2.filename

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • anthonyhA
          anthonyh @scottalanmiller
          last edited by

          @scottalanmiller said:

          I'm not clear what you are asking. Do you want a list of ALL files under said /directory or are you looking for only certain ones?

          Every single file under /this/directory.

          scottalanmillerS 1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @anthonyh
            last edited by

            @anthonyh said:

            @scottalanmiller said:

            No need to get the filename, the absolute path will include that already.

            I want the file name and path to said file separate, but I suppose I could separate them through another step. I'm going to be matching by file name. basically table1.filename = table2.filename

            Just use a filter on the existing file, no need to make a separate file for that.

            1 Reply Last reply Reply Quote 1
            • scottalanmillerS
              scottalanmiller @anthonyh
              last edited by

              @anthonyh said:

              @scottalanmiller said:

              I'm not clear what you are asking. Do you want a list of ALL files under said /directory or are you looking for only certain ones?

              Every single file under /this/directory.

              Oh okay.

              find /dir -type f -print
              

              Where /dir is the directory name in question. See if that gives you want you want.

              anthonyhA 1 Reply Last reply Reply Quote 1
              • A
                Alex Sage
                last edited by

                This is super easy to do in Linux.... If you know all the commands like @scottalanmiller! 😄

                1 Reply Last reply Reply Quote 1
                • anthonyhA
                  anthonyh @scottalanmiller
                  last edited by

                  @scottalanmiller said:

                  @anthonyh said:

                  @scottalanmiller said:

                  I'm not clear what you are asking. Do you want a list of ALL files under said /directory or are you looking for only certain ones?

                  Every single file under /this/directory.

                  Oh okay.

                  find /dir -type f -print
                  

                  Where /dir is the directory name in question. See if that gives you want you want.

                  That gives me the absolute path, but no date. I found this command that gets me a little closer:

                  find /this/directory -type f -exec stat -c "%n %y" {} ;

                  Gives me this:

                  /this/directory/data/EFile/DOC/227349_FS86478.pdf 2011-08-19 10:21:22.000000000 -0700

                  But it's not ideal, yet. I'd need to delimit the file and timestamp with something other than a space. I would love to eliminate the decimal on the seconds as well as the timezone, but I can work around those.

                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                  • anthonyhA
                    anthonyh
                    last edited by

                    Ooh, I'm very close!

                    find /this/directory -type f -printf "%f\t" -printf "%h\t" -printf "%Tc\n"

                    Gets me this:

                    254405_FS85691.pdf /this/directory/data/EFile/CASEDOC Mon 27 Aug 2012 08:52:15 AM PDT

                    If I can get the timestamp formatted as YYY-MM-DDD HH:MM:SS (24h time) I will be golden! I don't care about PDT vs PST.

                    1 Reply Last reply Reply Quote 0
                    • anthonyhA
                      anthonyh
                      last edited by anthonyh

                      I think I've got it close enough!

                      find /this/directory -type f -printf "%f\t" -printf "%h\t" -printf "%TY-%Tm-%Td %TH:%TM\n"

                      Result:

                      101581_PR78450.pdf /this/directory/data/EFile/MO 2007-10-30 11:16

                      1 Reply Last reply Reply Quote 1
                      • scottalanmillerS
                        scottalanmiller @anthonyh
                        last edited by

                        @anthonyh said:

                        @scottalanmiller said:

                        @anthonyh said:

                        @scottalanmiller said:

                        I'm not clear what you are asking. Do you want a list of ALL files under said /directory or are you looking for only certain ones?

                        Every single file under /this/directory.

                        Oh okay.

                        find /dir -type f -print
                        

                        Where /dir is the directory name in question. See if that gives you want you want.

                        That gives me the absolute path, but no date. I found this command that gets me a little closer:

                        find /this/directory -type f -exec stat -c "%n %y" {} ;

                        Gives me this:

                        /this/directory/data/EFile/DOC/227349_FS86478.pdf 2011-08-19 10:21:22.000000000 -0700

                        But it's not ideal, yet. I'd need to delimit the file and timestamp with something other than a space. I would love to eliminate the decimal on the seconds as well as the timezone, but I can work around those.

                        Easier to work with the date if you use UNIX time instead of a human readable format. And you can use the cut command to trim off anything trailing that you don't want.

                        1 Reply Last reply Reply Quote 1
                        • 1 / 1
                        • First post
                          Last post