ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QSH - change the time format of LS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QSH - change the time format of LS

    When using QSH, how can I get the ls command to format the dates as an ISO Date/Time? I've been googling, but haven't found anything that works yet.

  • #2
    I don't know of any way to get ls to output in ISO Date/Time format. Not in QShell nor PASE (nor Linux nor ...). I won't be too surprised if Scott posts a way, though.

    I'd get it done in one of two ways. First, I wouldn't use ls at all. I'd use the various APIs to read the entries I wanted and format output however I needed it. And second, I'd use the ls -lT option to put the full timestamp into the output. Then I'd read that output file and convert the date/time to a "YYYY-MM-DD HH:MI:SS" format, putting updated lines to a new file.

    It might be possible with a script, but it's faster for me to code a basic proc using the ILE CEE* APIs.
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      You can use the -lT (little ell, big tee) switches with ls to get the complete date and time, but you'd need to pipe the output into something else to reformat the date and time. I think Perl might be able to do that.

      Comment


      • #4
        Thanks for the responses. I was hoping for a quick way to switch it in QSH, as I was on a customer box. I've used the API's to compare the time stamps, unfortunately I was dealing with a customer who hadn't updated our software in two years, so my utility doesn't exist on their system. I ended up getting the output of ls into Excel, and manipulating the dates there.

        From googling it seems like it might be possible if you create a custom local and manipulate the LC_TIME environment variable. But I was on a customer box and didn't feel like playing around on their system too much.

        http://www.ibm.com/support/knowledge...eatelocale.htm

        Comment


        • #5
          You can set a preferred date/time format by creating (or updating) a locale, but I'm not aware of that having an appropriate effect on ls output. If I look at the default locale on one of my systems, it has no relationship to the ls date/time formats. The job locale for me is *SYSVAL, which points to the QLOCALE system value, which points to /QSYS.LIB/EN_US.LOCALE. I haven't done any testing, but I then guess that ls simply doesn't use a locale for it.

          Could be worth trying, though.
          Tom

          There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

          Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

          Comment


          • #6
            Depending on why you're comparing timestamps, there might be better solutions than using 'ls'

            For example, the 'find' utility has options for comparing if one file is newer/older than another. It also has options for finding files that have/haven't been modified/accessed within a certain number of days, etc.

            Sounds like this is already solved.. but, if it comes up again, giving us a bigger picture would give us the chance to point out different tools (besides ls) tht might make your life easier.

            Comment

            Working...
            X