How to obtain more than one information from the same result
Hello to everybody!
Well, first of all I have to say I'm starting programming in Bash, so I haven't got a deep knowledge about it... so perhaps this question may seem to be too obvious for more than one of you. Anyway, I want to solve this problem: I'm trying to get multiple data (specifically, the file name, user and date of last access) from the same result. So far, what I've done is someting like this: Code:
find . -mtime -1 | stat -c %x $(awk '{print $1}') However, I also want to attach the file name and the associated user in the same line. I have already tried several things, but I cannot find how to run 3 stat commands on the same line to provide the whole information. Is it possible? Or do I need to store the result of the find command in temporary variable previously? Thank you very much in advance. Regards. |
Hello Utsaki, welcome to LQ,
you could for example use the ls command with option -l with the pipe Code:
find . -type f -mtime -1 | ls -l | awk '{ print $3 " " $NF }' Markus |
I'm not sure you can get who accessed the file unless you are running the audit daemon and are auditing for file access. You can get file name and access time with:
Code:
find . -type f -mtime -a -exec /bin/ls -lu {} \; |
Quote:
In fact, one of the options I'm trying is using the ls command. But I noticed I didn't get the same result using these two lines: Code:
find . -mtime -1 -ls Code:
find . -mtime -1 | ls -l Anyway, I still have the same problem. For example, if I want to show the name file, the username who owns the file and the date of the last modification, everything is ok, I just write, for instance, the following line: Code:
find . -mtime -1 -ls | awk '{printf $11; printf $5; printf $9;printf $8; printf $10; printf "\n"}' Code:
find . -atime -1 -ls | awk '{printf $11; printf $5; printf $9;printf $8; printf $10; printf "\n"}' Code:
find . -atime -1 -ls | awk '{printf $11; printf $5; printf $(stat -c %x $(awk '{print $11}'); printf "\n"}' Regards. |
mh, I think I made a mistake. But you did not understand what I did as well.
I've used the find command together with the ls command. ls with option -l or better -lh gives you all information you need, namely the filename and the time and others. What you try is to use find with an option -ls which is something completely different. My mistake was that I did not recognize, that ls does not use the output of the find command. One needs the -exec option for find. Code:
find . -type f -mtime -1 -exec ls -lh {} \; Markus |
Yes, I know what you mean and I also expected that the ls command used the output from the previous command. Anyway, with the code you provided to me in your last message, I still have the same problem with the information of the date an hour. Using the line:
Code:
find . -type f -atime -1 -exec ls -lh {} \; Code:
stat -c %x namefile Thank you one more time for your patience. Regards. |
How about something like
Code:
find . -mtime -1 | stat --printf 'Modification: %x\nFile name: %n\nUser: %U\n' $(awk '{print $1}') |
Yes! That's it!
Thank you very much, catkin :) Well, thank you to everyone for your help and support. |
Glad it worked for you :)
Threads can be marked SOLVED via the Thread Tools menu. |
You can get a file's info directly from find:
Code:
find . -mtime -1 -printf 'name: %p user: %u modification: %a\n' |
All times are GMT -5. The time now is 10:42 AM. |