0

I'd like to check the status my directories

    $ ls
    Foo   Bar  Zoo

Check their status

    $ ls | xargs stat -x
      File: "Zoo"
      Size: 384          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/ ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8603392907    Links: 12
    Access: Fri Mar 30 09:12:06 2018
    Modify: Wed Mar 28 10:07:32 2018
    Change: Wed Mar 28 10:07:32 2018
      File: "Bar"
      Size: 160          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/  ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8604964551    Links: 5
    Access: Fri Mar 30 09:12:06 2018
    Modify: Thu Mar 29 20:48:46 2018
    Change: Thu Mar 29 20:48:46 2018
      File: "Zoo"
      Size: 416          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/  ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8603830641    Links: 13
    Access: Fri Mar 30 09:28:54 2018
    Modify: Fri Mar 30 09:28:54 2018
    Change: Fri Mar 30 09:28:54 2018

The format is dense, I prefer a sparse format to distingish each file or dir intuitively.

    $ ls | xargs stat -x
      File: "Foo"
      Size: 384          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/ ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8603392907    Links: 12
    Access: Fri Mar 30 09:12:06 2018
    Modify: Wed Mar 28 10:07:32 2018
    Change: Wed Mar 28 10:07:32 2018

      File: "Bar"
      Size: 160          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/  ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8604964551    Links: 5
    Access: Fri Mar 30 09:12:06 2018
    Modify: Thu Mar 29 20:48:46 2018
    Change: Thu Mar 29 20:48:46 2018

      File: "Zoo"
      Size: 416          FileType: Directory
      Mode: (0755/drwxr-xr-x)         Uid: (  501/  ..)  Gid: (   20/   ..)
    Device: 1,4   Inode: 8603830641    Links: 13
    Access: Fri Mar 30 09:28:54 2018
    Modify: Fri Mar 30 09:28:54 2018
    Change: Fri Mar 30 09:28:54 2018

How to achieve it?

2 Answers 2

3

Since you're using BSD stat, you can use the -f option to specify the format explicitly, including any trailing new lines you want. Writing out the entire format string for -x by hand might be a bit tedious, so here's the format string obtained from the source, combined into a single string:

'  File: "%N"%n  Size: %-11z  FileType: %HT%n  Mode: (%OMp%03OLp/%.10Sp)         Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%nDevice: %Hd,%Ld   Inode: %i    Links: %l%nAccess: %Sa%nModify: %Sm%nChange: %Sc'

Add a couple of %n to the end to get the effect you want:

$ stat_format='  File: "%N"%n  Size: %-11z  FileType: %HT%n  Mode: (%OMp%03OLp/%.10Sp)         Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%nDevice: %Hd,%Ld   Inode: %i    Links: %l%nAccess: %Sa%nModify: %Sm%nChange: %Sc%n%n'
$ stat -f "${stat_format}"  .zshrc .bashrc
  File: ".zshrc"
  Size: 5878         FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (  502/muru)  Gid: (   20/   muru)
Device: 1,5   Inode: 8596072804    Links: 1
Access: Mar 30 11:40:18 2018
Modify: Mar 26 13:34:14 2018
Change: Mar 26 13:34:14 2018

  File: ".bashrc"
  Size: 3768         FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (  502/muru)  Gid: (   20/   muru)
Device: 1,5   Inode: 8593701774    Links: 1
Access: Mar 30 11:40:18 2018
Modify: Jan 28 11:15:12 2018
Change: Jan 28 11:15:12 2018
1

There are many ways to do what you want. One of the simplest is the following:

$ ls | xargs stat -x | sed 'n;n;n;n;n;n;s/$/\n/' 

Note - The number of n;s may be off by one as I am not on a system that supports the -x output option.

4
  • I upvoted, the command ls | xargs stat -x | sed 'n;n;n;n;n;n;s/$/\n/ output the same without separating each files. Commented Mar 30, 2018 at 3:10
  • Are you saying that the sed command did not work for you? Commented Mar 30, 2018 at 3:39
  • Yes, BSD --version May 10, 2005 Commented Mar 30, 2018 at 3:44
  • 1
    Ah, the BSD version of sed is different. Try sed 's/$/\NEWLINE/' i.e. replace NEWLINE with an actual newline. Commented Mar 30, 2018 at 3:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.