Good evening everybody,
I have to find the user owner of the most recently file in the system
How can I do?
Use the search function, there are a lot of threads regarding this topic:
Google Search Results for most recent file | The UNIX and Linux Forums
1 Like
I have solved in this way:
find / -type f | xargs ls -alrt | cut -f 2 | tail -n 1
The output is:
-rw------- 1 root operator 7111 Jun 18 22:01 /root/.viminfo
How can I obtain from this output only the owner of this file?[COLOR="\#738fbf"]
---------- Post updated at 02:49 AM ---------- Previous update was at 02:47 AM ----------
Solved :):)
find / -type f | xargs ls -alt | tail -n 1 | awk '{print $3}'
Hi, that would work as long as there are no spaces in the filenames, otherwise you could use something like this if your find supports print0:
find / -type f -print0 | xargs -0 ls -alt | awk 'NR==1{print $3}'
(my ls -alt has the owner in the third column)
or this if it supports printf:
find / -type f -printf "%A@ %u\n" | sort -rn | awk 'NR==1{print $2}'
Ok but the problem is to find user owner most recently file in the system
If this user is "bin" ?
My solution find it!
find / -type f -user bin -print0 | xargs -0 ls -art1 | tail -1
or
find / -type f -user bin -printf "%A@ %p\n" | sort -rn | awk 'NR==1{print $2}'