Mountain |
05-10-2009 12:30 PM |
How do I cut fields with repeated delimiters?
Given a file listing like this:
Code:
$ ls -laR
.:
total 24
drwxr-xr-x 3 auser admin 4096 2009-05-10 13:19 .
drwxr-xr-x 20 auser admin 12288 2009-05-10 13:19 ..
-rw-r--r-- 1 auser admin 998 2008-04-07 13:37 file1.txt
drwxr-xr-x 2 auser admin 4096 2009-05-10 13:21 directory1
./directory1:
total 24
drwxr-xr-x 2 auser admin 4096 2009-05-10 13:21 .
drwxr-xr-x 3 auser admin 4096 2009-05-10 13:19 ..
-rwxr-xr-- 1 auser admin 2176 2008-04-06 13:30 2file.txt
-rw-r--r-- 1 auser admin 249 2008-04-06 23:23 experiment.txt
-rw-r--r-- 1 auser admin 334 2008-04-07 11:29 somefile.txt
-rw-r--r-- 1 auser admin 1604 2008-04-02 13:37 text3.out
I want a list that looks like this:
Code:
2008-04-02 13:37 text3.out
2008-04-06 13:30 2file.txt
2008-04-06 23:23 experiment.txt
2008-04-07 11:29 somefile.txt
2008-04-07 13:37 file1.txt
What I'm trying to do is list all files in all subdirectories recursively and sort by date. (I might also pipe the output through tail to list e.g., only the 100 newest files.)
Here is what I tried:
Code:
$ ls -ogARtr | grep '^-' | cut -d ' ' -f 4-
998 2008-04-07 13:37 file1.txt
2008-04-02 13:37 text3.out
2008-04-06 13:30 2file.txt
249 2008-04-06 23:23 experiment.txt
334 2008-04-07 11:29 somefile.txt
Apparently the extra space before the smaller files makes cut not work as expected. That's my main problem. The other problem is I will apparently have to send it through sort to get an overall (not the ls per-subdirectory) sorting.
How can I achieve the desired result?
|