Is there a command to list files, exclude sub-directories and display size and date?

5,605

Solution 1

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

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

Solution 2

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

ls -gohU | grep '^[^d]'

Solution 3

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).

Share:
5,605

Related videos on Youtube

user36833
Author by

user36833

Updated on September 18, 2022

Comments

  • user36833
    user36833 over 1 year

    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.

    • Bratchley
      Bratchley about 11 years
      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.
  • user36833
    user36833 about 11 years
    Thank you very much, I found this method to work best for what I wanted displayed. I'm very grateful