madasafish
Technical User
I have a directory listing with files that keep updating and I need to check the last modify/access time of the directory plus the total number of files in that directory.Keeping the newest/latest modified directory listing at the top.
For example...
[root@instructor home]# ls -ltR mydir*
mydir2:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:11 file21
-rw-r--r--. 1 root root 0 Aug 11 06:10 file2
mydir3:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:10 file31
-rw-r--r--. 1 root root 0 Aug 11 06:10 file3
mydir1:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:10 file12
-rw-r--r--. 1 root root 0 Aug 11 06:09 file1
I need to output
DIRNAME MONTH DAY TIME No_FILES
mydir2 Aug 11 06:11 2
mydir3 Aug 11 06:10 2
mydir1 Aug 11 06:10 2
The following simple command gets the first 4 outputs..
ls -ltd mydir* |awk '{print $9,$6,$7,$8}'
but I am struggling to get the FILETOT. I know I can pipe the first command into "grep -v" to remove the "total" lines but it would be more elegant to have it all done in awk.
Any help appreciated,
Thanks in advance,
Madasafish
For example...
[root@instructor home]# ls -ltR mydir*
mydir2:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:11 file21
-rw-r--r--. 1 root root 0 Aug 11 06:10 file2
mydir3:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:10 file31
-rw-r--r--. 1 root root 0 Aug 11 06:10 file3
mydir1:
total 0
-rw-r--r--. 1 root root 0 Aug 11 06:10 file12
-rw-r--r--. 1 root root 0 Aug 11 06:09 file1
I need to output
DIRNAME MONTH DAY TIME No_FILES
mydir2 Aug 11 06:11 2
mydir3 Aug 11 06:10 2
mydir1 Aug 11 06:10 2
The following simple command gets the first 4 outputs..
ls -ltd mydir* |awk '{print $9,$6,$7,$8}'
but I am struggling to get the FILETOT. I know I can pipe the first command into "grep -v" to remove the "total" lines but it would be more elegant to have it all done in awk.
Any help appreciated,
Thanks in advance,
Madasafish