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
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, 2015 at 13:41
  • You'll want to look at stat and getfacl Aug 27, 2015 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, 2015 at 2:07

2 Answers 2

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.