Find the answer to your Linux question:
Results 1 to 3 of 3
I had a doubt with what the following kind of statement is going to accomplish. The statement is:- -------------------------------------------------------------------------------------- find /backup/ -name '*.gz' -mtime +2 -print -exec rm {} \; ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    33

    Meaning of "find /backup/ -name '*.gz' -mtime +2 -print -exec rm {} \;"

    I had a doubt with what the following kind of statement is going to accomplish. The statement is:-

    --------------------------------------------------------------------------------------

    find /backup/ -name '*.gz' -mtime +2 -print -exec rm {} \;

    --------------------------------------------------------------------------------------

    As per, my understanding, it is going to check in '/backup' path for all the files ending with 'gz' which were modified more than 48 hrs ago. Is, my understanding correct?

    I hope, my question is clear.

    Please, help in solving the doubt.

    regards

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    yes,you are almost correct,

    Code:
    find /backup/ -name '*.gz' -mtime +2 -print -exec rm {} \;
    let's split this command


    find /backup/
    this will check for files under specified directory (which is backup)

    with find you can use plenty of options check "man find"

    here
    -name '*.gz'
    is used to retrieve all files which as .gz as extentsion.

    -mtime +2
    tells to get files that are last modified 2 days ago.

    -print option will display the file name

    find is very powerful command especially when it's used along with
    -exec
    with -exec you can specify the action that needs to be taken on each retrieved fiiles

    here you using rm command , so it will delete files..

    Above command will delete .gz files from /backup which are older than 2 days .
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    33
    thanks, a lot for your answer. You explained it very well.

    regards

Posting Permissions

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