4 ms·
Why not recursive? Use the following command if you want to have one directory per idea, rather than a single file: find -type f -print0 | xargs --null ls -l
by pif 14y ago
Why not recursive? Use the following command if you want to have one directory per idea, rather than a single file:
find -type f -print0 | xargs --null ls -ltr
- q_revert 14y agoI know it gets talked about quite a lot round here but I find zsh really quite useful for this type of thing.. the zsh equivalent of the above, for me would be ls **/* -ltr (Edit)[ for an exact reproduction ] ls **/*(.) -ltr if you wanted to put a date range on it.. for example, only files from the last 5 days.. ls **/*(m-5) -ltr or the last 5 hours ls **/*(mh-5) -ltr there's loads more of these http://grml.org/zsh/zsh-lovers.html http://grml.org/zsh/zsh-lovers.html, obviously your shell is a matter of preference, and if you know bash or something similar well enough then the incentive to change is obviously lessened.. but personally I've found that a whole series of small improvements (for me) added up to a pretty large win edit: as pointed out by pyre, my initial suggestion isn't an exact replica.. but was the first thing that came to mind for me.. i guess s/the\ zsh\ equivalent/something\ similar\ in\ zsh/ edit again: /tmp/ $ mkdir -p /tmp/test1/test2/test3 /tmp/ $ touch /tmp/test1/test2/test3/test4 /tmp/ $ ls -ltr /tmp/test1/**/*(.) -rw-r--r-- 1 usr grp 0 Aug 7 15:49 /tmp/test1/test2/test3/test4 /tmp/ $ find /tmp/test1 -type f -print0 | xargs -0 ls -ltr -rw-r--r-- 1 usr grp 0 Aug 7 15:49 /tmp/test1/test2/test3/test4
- pyre 14y ago**/* does not match the '-type f' part of his filter: $ mkdir -p /tmp/test1/test2/test3 $ touch /tmp/test1/test2/test3/test4 $ ls -ltr /tmp/test1/**/* -rw-r--r-- 1 usr grp 0 2012-08-07 09:59 /tmp/test1/test2/test3/test4 /tmp/test1/test2: total 4 drwxr-xr-x 2 usr grp 4096 2012-08-07 09:59 test3 /tmp/test1/test2/test3: total 0 -rw-r--r-- 1 usr grp 0 2012-08-07 09:59 test4 On the other hand: $ find /tmp/test1 -type f -print0 | xargs -0 ls -ltr -rw-r--r-- 1 usr grp 0 2012-08-07 09:59 /tmp/test1/test2/test3/test4
- pif 14y agoNice to know, thanks! But, how does it work with file names containing spaces (or other strange characters)? Edit: just to clarify: my question concerns the zsh method. Regarding find+xargs, I wrote that comment :-) Actually, this edit would be an answer to zap; HN does not let me reply directly to him: is it to prevent flame-wars?
- zaptheimpaler 14y agoThats what the print0 arg in find and the --null arg in xargs are for. print0 prints the file name followed by a NULL character (rather than newline) Using the --null/-0 arg makes xargs look for NULLs as delimiters and treat everything else literally.
- q_revert 14y ago/tmp/ $ mkdir -p test1/test2/test3 /tmp/ $ touch test1/test2/test3/test4 /tmp/ $ ls -ltr test1/**/*(.) -rw-r--r-- 1 usr grp 0 Aug 9 11:11 test1/test2/test3/test4 /tmp/ $ touch test1/test2/test3/test\ with\ spaces /tmp/ $ ls -ltr test1/**/*(.) -rw-r--r-- 1 usr grp 0 Aug 9 11:11 test1/test2/test3/test4 -rw-r--r-- 1 usr grp 0 Aug 9 11:12 test1/test2/test3/test with spaces
- sefk 14y agoI keep considering moving to zsh. This example sure makes it look worthwhile. Thanks.
- ralph 14y agofind(1) has an -ls built-in, thought the format is slightly different. You can also use -printf to suit. Also, later GNU finds make some uses of xargs unnecessary. find -type f -exec ls -ltr {} +
- pjungwir 14y agoI've used `ls -ltr` for years, and just recently I wrote a recursive version with the help of my local LUG mailing list. Here is my favorite version (put into a script in ~/bin): find "$1" -printf '%TY-%Tm-%Td_%TH:%TM:%TS\t%p\n' | sort -r It'd be easy to add `-type f` if that's what you want.