1

I had 5 folders each with a couple of files (2-3).

I wanted to print all of them in one shot. I found ways to do it in Linux but I couldn't get them to work here.

The two alternatives I found for Linux were:

find -type f -print0 | xargs -0 ls -t

find . -type f -printf "%T@ %p\n" | sort -nr | cut -d\ -f2-

How do I accomplish this on a Mac?

I'd prefer not downloading any package for this and to accomplish this solely through terminal.

  • 1
    What happens if you try the commands in Terminal? – nohillside Sep 16 '13 at 19:27
  • -t is not recongnized and printf not defined respectively. – Wyatt Sep 16 '13 at 19:51
  • It's find complaining about -t, not ls :-) – nohillside Sep 16 '13 at 20:06
2

An easy way to get the same result is

find . -type f

which basically is identical to

find . -type f -print0 | xargs -0 -n 1 ls
| improve this answer | |
  • 1
    The -t in your ls command is superfluous. find does not do any time-based ordering; and, as only one file at a time is passed to xargs, sorting the one file at a time by the file's date (as -t would normally do) is not very useful. – Kent Sep 16 '13 at 23:44
1

POSIX requires specifying the path argument for find (like find . instead of find) and -printf is a GNU extension.

List regular files sorted by modification date:

find . -type f -exec stat -f'%m %N' {} + | sort -rn | cut -d' ' -f2-
zsh -o dotglob -c 'printf %s\\n **/*(.om)'

List regular files:

find . -type f
zsh -o dotglob -c 'printf %s\\n **/*(.)'

List all files (including directories):

find .
shopt -s globstar dotglob; printf %s\\n ** # bash 4.0 or later
brew install tree; tree -a . # -a includes files that start with .
mdfind 'kMDItemFSInvisible=1||kMDItemFSInvisible=0' -onlyin .

List only directories:

find . -type d
shopt -s globstar dotglob; printf %s\\n **/ # bash 4.0 or later
tree -ad .
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .