1

Before I begin please assume I have only basic knowledge in UNIX. Basic meaning I have only started reading about it since last week for a work related purpose.

I have been experimenting with the ls command to provide lists of a particular directory containing video media. I needed to display the filename, filesize and the date it was created. I achieved this by using the command:

ls -gohU

This was fine but the search also included the sub-directories within this directory. After searching I found another command which displays the files and excludes the folders:

find . -maxdepth 1 -not -type d

What I would like to know is if there is a command that can find all files within the directory excluding sub-directories and display their filenames, size and the date they were created.

P.S. I am also using Terminal - bash on Mac OS 10.6.8 if that helps.

1
  • fwiw Filesystems other than ext4 don't generally record file creation time (I believe this includes HFS+). Bear that in mind when you're interpreting the date. "mtime" is time of last file modification "ctime" is the last time the metadata changed and "atime" is the last access time.
    – Bratchley
    Apr 9, 2013 at 16:20

4 Answers 4

5

Use the -exec option to combine both the commands that work for you:

find . ! -name . -prune ! -type d -exec ls -gohU {} +
2

If first character is d then a file is directory. To list lines beginning with other characters use:

ls -gohU | grep '^[^d]'
1
  • Thank you very much, I found this method to work best for what I wanted displayed. I'm very grateful
    – user36833
    Apr 9, 2013 at 15:54
1

Alternative to ls if you only want some fields is OS/X's stat command:

find . ! -name . -prune ! -type d -exec stat -t '%FT%T' -f '%15z %SB %N' {} +

Or with zsh:

command stat -t '%FT%T' -f '%15z %SB %N' -- *(D^/)

(%B, ls -U are OS/X specific, other Unices generally don't have inode birth times).

0

Most versions of find support -ls option so the following should give you what you're going for:

find . -maxdepth 1 -type f -ls

You must log in to answer this question.

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