Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I am trying to get the total file size for certain files per directory. I am using find `pwd` /DirectoryPath -name '*.dta' -exec ls -l {} \; | awk ...
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    1

    Getting the disk usage for certain files per directory.

    Hi,

    I am trying to get the total file size for certain files per directory.

    I am using

    find `pwd` /DirectoryPath -name '*.dta' -exec ls -l {} \; | awk '{ print $NF ": " $5 }' > /users/cergun/My\ Documents/dtafiles.txt

    but this lists all the files in the directories.

    I need the total per directory for all dta files.

    Any suggestions?

  2. #2
    Just Joined! its_really_me's Avatar
    Join Date
    Mar 2010
    Location
    Germany
    Posts
    24
    Try this:

    Code:
    du -ch *.dta
    If you have many files and you just want to see the last line with the summary, use the following:

    Code:
    du -ch *.dta | grep total
    But this only shows the directory you are in or have selected (i. e.)
    Code:
    du -ch /DirectoryPath/*.dta | grep total > /users/cergun/My\ Documents/dtafiles.txt
    for your example.

    du in general can list an summarize sub directories but then, you can not select a filename.

    If beside the .dta files there are only files ending with .bak, you can do this using the exclude option.

    Code:
     du -sh --exclude *.bak
    or
    Code:
     du -sh --exclude /DirectoryPath/*.bak | grep total  > /users/cergun/My\ Documents/dtafiles.txt
    for your example.

    If you have multiple filetypes you can put those in a file and call it duexlude.lst and then call it as follows.

    Code:
     du -sh -X duexclude.lst /DirectoryPath/*.bak | grep total  > /users/cergun/My\ Documents/dtafiles.txt
    hope this helps. Try man du for more options.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...