1

I would like to display a file's ctime, mtime and atime along with whether it has extended attributes or not. There are 2 commands that can do this but I have not been able to combine them into a single command to give a single line of output.

find /tmp -maxdepth 1 -printf "%a _ %c _ %t _ %P\n"

gives the output similar to this:

Thu Aug 27 09:51:11 2015 _ Thu Aug 27 09:48:40 2015 _ Thu Aug 27 09:48:40 2015 _ tempfile.tmp

and

ls -l /tmp

gives the output similar to this:

-rw-rw----+ 1 root root       5 Aug 27 04:39 tempfile.tmp

I'm interested only in the "+" symbol after the permissions in the ls output.

Ideally I'd like the output to be similar to this:

+ Thu Aug 27 09:51:11 2015 _ Thu Aug 27 09:48:40 2015 _ Thu Aug 27 09:48:40 2015 _ tempfile.tmp
  Thu Aug 27 09:51:11 2015 _ Thu Aug 27 09:48:40 2015 _ Thu Aug 27 09:48:40 2015 _ anothertempfile.tmp
KennyC
  • 113
  • 3
  • Which distribution? On Ubuntu 14.04 I found `%M` mentioned in the man page, but that's only standard permissions. Looks like `find` doesn't know about extended attributes. – kasperd Aug 27 '15 at 13:41
  • You'll want to look at [`stat`](http://manpages.ubuntu.com/manpages/trusty/en/man1/stat.1.html) and [`getfacl`](http://manpages.ubuntu.com/manpages/trusty/en/man1/getfacl.1.html) – glenn jackman Aug 27 '15 at 14:16
  • @kasperd RedHat Enterprise Linux 5 to be specific. I think you're right, I don't see `find` having that feature in the docs and man pages I read. – KennyC Aug 28 '15 at 02:07

2 Answers2

0

So write a shell script to collect your data into variables. After you have the data in variables, you can reformat and print them exactly how you want.

EEAA
  • 109,363
  • 18
  • 175
  • 245
0

You could write a little script to do it for you (this is ugly but works):

#!/bin/bash
for f in *; do
  flag="x"
  attr=$(getfattr $f)
    if [ "$attr" = "" ]
      then flag=" "
    fi
  find -name $f -printf "$flag %a _ %c _ %t _ %P\n"
done
nico
  • 26
  • 2