need terminal command to list files

i want to find all files of a given kind within a directory, including subdirectories, and list them according to their size. i've looked into the ls and find commands, but i'm totaly new to terminal. could anyone help me?

to be just a bit more specific:
i have a folder containing up to three levels of subfolders, and within these, i got some .fbx files.
i need a list of these, sorted by size

MBP 2.6GHz C2D, 4GB RAM, Mac OS X (10.5.6)

Posted on Feb 12, 2009 5:53 PM

Reply
25 replies

Feb 12, 2009 7:08 PM in response to 2point5

thanks to all three of you!

niel: your method returns a list of the subfolders, their sizes in descending order, and all the files in them, not only the .fbx'es.
that doesen't help me much, - i only want to list the .fbx files according to size.
also, i don't understand what you mean by 'sorting the output by the fifth column'.

m and chris: your methods doesen't result in anything being listed..
i don't se how i could have been doing anything wrong.

thanks again all, i hope you're not bothered

Feb 12, 2009 7:23 PM in response to horne9

Might have been because I assumed that you would be in the home folder when you issued the command which would mean it would look through all folders subordinate to the home folder no matter how deeply nested.

I ran it from my home folder for files with .txt and it did what I expected.

ls -lRS | grep '.txt'

mkramer: I couldn't tell the difference in performance between egrep and grep (not that my file selection was particularly large).

Chris

Feb 12, 2009 7:54 PM in response to mkramer

It sorts by size on Linux! 🙂 Running a bit blind here...

PS. Think you want a \. in your grep (. alone is a wildcard)

Edit: No, you're right as well as I forgot I have an alias for ls setup here. -RSl (lower case L) seems to give the right results.

Edit 2: Which is what Chris said above (sorry, late over here, time for some sleep I reckon...)

Anyway, lots of ways to skin this Leopard!

Feb 12, 2009 7:53 PM in response to iBod

ls -RS ~/coding/ | grep '\.txt' | sort -n -k5

Yeah, good catch on the \. Anyway, if I run
*ls -RS ~/coding/ | grep '\.txt' | sort -n -k5* I get a lexically sorted list of .txt's in my coding directory, no sizes next to them
*ls -RSi ~/coding/ | grep '\.txt' | sort -n -k5*
I get a list sorted by serial number (node number)
eg like this
2382637 qt.txt
2382638 ut.txt
2382639 uc.txt
2382640 ft.txt
2382641 fxt.txt
2382642 fyt.txt
2382643 fzt.txt
2442686 outputs138.80.txt
2442688 readme.txt
937046 LICENSE.txt
937221 GPL.txt
937311 LICENSE.txt
bigspring:filemerger mas
My way gives something like this

952K /Users/masonkramer/coding//latticesim/build/Debug/lmax,100,da,1.0,swaps,24003,d x,1.0,dy,1.0,dz,1.0,px,.1,py,.1,pz,.1/swaplog.txt
952K /Users/masonkramer/coding//latticesim/build/Debug/lmax,100,da,1.0,swaps,24004,d x,1.0,dy,1.0,dz,1.0,px,.1,py,.1,pz,.1/swaplog.txt
952K /Users/masonkramer/coding//latticesim/build/Debug/lmax,100,da,1.0,swaps,24005,d x,1.0,dy,1.0,dz,1.0,px,.1,py,.1,pz,.1/swaplog.txt
956K /Users/masonkramer/coding//latticesim/build/Debug/lmax,100,da,1.0,swaps,24001,d x,1.0,dy,1.0,dz,1.0,px,.1,py,.1,pz,.1/swaplog24001.txt
960K /Users/masonkramer/coding//latticesim/build/Debug/lmax,100,da,1.0,swaps,24002,d x,1.0,dy,1.0,dz,1.0,px,.1,py,.1,pz,.1/swaplog24002.txt

Feb 12, 2009 7:54 PM in response to mkramer

Works perfect for me. Here's a snapshot of the listing from my MacBook running 10.5.6 using
ls -RSl | grep '\.txt' | sort -n -k5
from the HOME folder
-rw-rw-rw-@ 1 boxerflat4 admin 1569 30 Sep 12:11 log-bb-2008-09-26-stats.txt.submitted
-rw-r--r-- 1 boxerflat4 admin 1574 24 Jun 2007 layer-stamp.txt
-rw-rw-rw-@ 1 boxerflat4 admin 1576 22 Sep 11:22 log-bb-2008-09-17-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 1746 28 Jul 2008 log-bb-2008-07-26-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 1759 11 Sep 23:53 log-bb-2008-09-10-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 1819 16 Sep 12:16 log-bb-2008-09-15-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 1977 21 Jul 2008 log-bb-2008-07-19-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 1981 21 Jul 2008 log-bb-2008-07-20-stats.txt.submitted
-rw-r--r-- 1 boxerflat4 admin 2167 8 Jun 2007 readme.txt
-rw-rw-rw-@ 1 boxerflat4 admin 2309 1 Sep 09:20 log-bb-2008-08-29-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 2428 12 Sep 22:05 log-bb-2008-09-11-stats.txt.submitted
-rw-rw-rw-@ 1 boxerflat4 admin 2443 5 Aug 2008 log-bb-2008-08-03-stats.txt.submitted
-rw-r--r-- 1 boxerflat4 admin 3280 29 Nov 13:22 AMRestoreLog.txt
-rw-r--r--@ 1 boxerflat4 admin 4082 15 Jul 2007 broadcast email list.txt
-rw-r--r--@ 1 boxerflat4 boxerflat4 4306 13 Dec 2007 2008MotorsportCalendar.txt
-rw-r--r-- 1 boxerflat4 admin 7274 5 Aug 2008 MySQLReadMe.txt
-rw-r--r--@ 1 boxerflat4 boxerflat4 8588 18 Nov 2007 CocktailLogFile.txt
-rw-r--r--@ 1 boxerflat4 admin 12966 16 Dec 09:46 cookies.txt
-rw-r--r-- 1 boxerflat4 admin 16500 7 Nov 2007 FileInfoLibPrefs.txt
-rw-rw-rw- 1 boxerflat4 admin 18211 4 Sep 10:55 rgb.txt
-rw-r--r-- 1 boxerflat4 admin 19005 14 Jun 2007 VelaCrashDump.txt
-rw-r--r-- 1 boxerflat4 admin 8973661 9 Dec 12:05 mysqlinfo.txt

Chris

Feb 13, 2009 5:04 AM in response to 2point5

2point5:
this is getting closer!:

ls -lRS | grep '.fbx'
-rw-r--r--@ 1 <user> staff 3021581 Jan 22 16:15 BASE rghfrhgn.fbx
-rw-r--r--@ 1 <user> staff 1339836 Jan 22 16:07 15spiralsteps.fbx
-rw-r--r--@ 1 <user> staff 883073 Jan 22 16:23 dfgehrhed.fbx
-rw-r--r--@ 1 <user> staff 643055 Jan 22 16:17 bbolt.fbx
-rw-r--r--@ 1 <user> staff 549396 Jan 22 16:10 747.fbx
-rw-r--r--@ 1 <user> staff 478151 Jan 22 16:21 by 2.fbx
-rw-r--r--@ 1 <user> staff 296625 Jan 22 16:12 baat gdgf..fbx
-rw-r--r--@ 1 <user> staff 145807 Jan 22 16:19 by 1.fbx
-rw-r--r--@ 1 <user> staff 2940215 Jan 20 00:50 topmod5.fbx
-rw-r--r--@ 1 <user> staff 373434 Jan 20 00:23 slfgeo23.fbx
-rw-r--r--@ 1 <user> staff 1615985 Jan 20 00:27 slfgeo3.fbx
-rw-r--r--@ 1 <user> staff 1263289 Jan 20 00:29 slfgeo4.fbx
-rw-r--r--@ 1 <user> staff 80282 Jan 20 00:31 slfgeo5.fbx
-rw-r--r--@ 1 <user> staff 162263 Jan 20 00:34 slfgeo6.fbx
-rw-r--r--@ 1 <user> staff 392394 Jan 19 23:58 010.fbx

(...)

the top 8 returns, those that are tabbed, are from one of the subfolders. they seem to be sorted according to size.
however, the following returns are not sorted. and for some reason, none of the them are tabbed, even if some are placed deeper within subfolders.

so, to have each individual .fbx sorted according to it's size, would be my goal for this.

and if possible, the path for each file.
is that doable?

Feb 13, 2009 5:14 AM in response to iBod

iBod:
you did it! however, when pasting your command directly, i got an error.
i had to exchange your capital I for a lowecase l.
i changed it here, in case somebody needs to copy it :

ls -RSl <folder/with/the/sub-directories/to/check> | grep '\.fbx' | sort -n -k5

it would still be great to have the filepaths listed though. and maybe extract the privileges an date / time info

Feb 13, 2009 6:01 AM in response to horne9

mason:
when looking closer at the output list, i see that the kilobyte files are sorted after the megabyte ones

du -ha <path> | grep \.fbx | sort -bg
(...)
21M ...
23M ...
37M ...
39M ...
68K ...
80K ...
108K ...
(...)

a bit strange, but it's just a dish of copy paste.

kudos to all, fri 13th's are great too!

Feb 13, 2009 6:22 AM in response to horne9

Yep, sorry about all the mis-postings yesterday (note to self, don't post at 4am...)

it would still be great to have the filepaths listed though. and maybe extract the privileges an date / time info


OK, last try then. Give this a go 😉

find -name '*.fbx' -printf "%s | %TY-%Tm-%Td %Tr | %M | %h/%f\n" | sort

The pipe's ( | ) in the printf statement are there just for display decoration.

(Disclaimer: it works on Linux! Still can't test on OS X...)

Feb 13, 2009 8:13 AM in response to iBod

never mind, it all turned quite interesting..
thanks for still trying to refine this,
however, i see this question as solved.
mason came up wiht this:

du -ha <path> | grep \.fbx | sort -bg

which returned these:

(…)
7.5M /Users/hm/Pictures/3Dmodeller/trar/mosa/mosa.fbx
7.7M /Users/hm/Pictures/3Dmodeller/WoofOBJ/woof.fbx
7.7M /Users/hm/Pictures/3Dmodeller/futity/futity.fbx
(…)

i'm satisfied!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

need terminal command to list files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.