[SOLVED] How to obtain more than one information from the same result
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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}')
What gives me the date and time of modification of files that have been modified in the last 24 hours.
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?
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:
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
The first one really gives me the long listing format of the last modified files; the second one gives me the long listing format of the whole directory.
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:
But if I wanted to obtain the date of the last access instead, I couldn't write the same code, using the -atime extension. That is, if I write the following line:
I really get the files I was looking for, but the 8, 9 and 10 columns have the date of the last modification, not the date of the last access. How could I insert the stat command in the line above to get the right date? I'm trying things like this (without success, obviously):
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 {} \;
this will find the files with the appropriate mtime and ls will show them.
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 {} \;
I don't get the same date and hour than when I use the line:
Code:
stat -c %x namefile
That's the reason why I was trying to combine the stat commands with the output from find.Do you think it could be possible to do? I think so, but I don't know how...
Thank you one more time for your patience.
Regards.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.