Find the answer to your Linux question:
Results 1 to 7 of 7
I am working on a shell script that will notify me when a specific file folder reaches a certain capacity. In this case I would like to email myself when ...
  1. #1
    Just Joined! pendal's Avatar
    Join Date
    Jan 2008
    Posts
    15

    reporting file/folder size for use in script

    I am working on a shell script that will notify me when a specific file folder reaches a certain capacity.

    In this case I would like to email myself when the folder reaches 4.5GB

    i was hoping to use the du command, but how do use the output of the du command inside the script?

    i.e. if i run the du command

    Code:
    du /path/to/dir/
    that will report
    Code:
    24431424            /path/to/dir/
    how can I get the du command to return just the size of the folder and not the rest of the information?

    thanks,
    -C

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Hi and Welcome !

    Code:
    du  /path/to/dir | cut -f 1
    You can use -m option with du for output in MB. Check manual of du.
    man du
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined! pendal's Avatar
    Join Date
    Jan 2008
    Posts
    15
    excellent .. the | cut -f 1 command was exactly what I was looking for.

  4. #4
    Just Joined! pendal's Avatar
    Join Date
    Jan 2008
    Posts
    15
    new problem with du has arisen.

    a user has thrown me for a loop and created a directory within the directory i am trying to monitor

    i am using the following command

    du -m /path/to/dir | cut -f 1

    that returns the total amount of megabytes used by the folder.
    however, if there is a folder within that folder .. it sends my two lines of data.
    one for each directory involved.

    what command can I run that returns just the amount of MB used by the folder in question .. regardless of it's contents??

    i tried the -c command for a grand total .. but that outputs three lines of info.

    thanks,
    -chris

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The "-s" flag is what you're looking for:
    Code:
           -s, --summarize
                  display only a total for each argument
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Have you tried looking at the du man page and reading what the "-s" option does? This might be exactly what you need.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined! pendal's Avatar
    Join Date
    Jan 2008
    Posts
    15
    ahh yes .. .the -s command.

    I'm sorry for wasting time. I only is the -S in the man docs and missed the -s.

    I guess that's what happens when you are debugging code at 4:00pm on a friday afternoon.

    thanks though .. it's working perfectly now.

    -chris

Posting Permissions

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