Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I want to delete the core files of Dec 26th. What is the command used to delete these files in one shot? All the core files related to only ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    May 2012
    Posts
    110

    Command needed to delete Core files in One shot ?


    Hi,

    I want to delete the core files of Dec 26th.

    What is the command used to delete these files in one shot?

    All the core files related to only Dec 26 I want to delete.

    -rw------- 1 root other 219976 Dec 26 17:35 core.agentInstanceCom.2182
    -rw------- 1 root other 219976 Dec 26 17:41 core.agentInstanceCom.5351
    -rw------- 1 root other 219976 Dec 26 17:54 core.agentInstanceCom.11620
    -rw------- 1 root other 219976 Dec 26 18:02 core.agentInstanceCom.15857
    -rw------- 1 root other 219976 Dec 26 19:07 core.agentInstanceCom.20843
    -rw------- 1 root other 219976 Dec 26 19:26 core.agentInstanceCom.532
    -rw------- 1 root other 219976 Dec 26 19:46 core.agentInstanceCom.10813
    -rw------- 1 root other 219976 Dec 26 20:05 core.agentInstanceCom.20273
    -rw------- 1 root other 219976 Dec 26 20:31 core.agentInstanceCom.3748
    -rw------- 1 root other 219976 Dec 26 20:44 core.agentInstanceCom.10014
    -rw------- 1 root other 219976 Dec 26 21:55 core.agentInstanceCom.18352
    -rw------- 1 root other 219976 Dec 26 22:02 core.agentInstanceCom.22359
    -rw------- 1 root other 219976 Dec 26 22:04 core.agentInstanceCom.23007
    -rw------- 1 root other 219976 Dec 26 22:46 core.agentInstanceCom.14026
    -rw------- 1 root other 219976 Dec 26 23:06 core.agentInstanceCom.24318
    -rw------- 1 root other 219976 Dec 26 23:07 core.agentInstanceCom.24544
    -rw------- 1 root other 219976 Dec 26 23:12 core.agentInstanceCom.27506
    -rw------- 1 root other 219976 Dec 26 23:37 core.agentInstanceCom.9659
    -rw------- 1 root other 219976 Dec 26 23:44 core.agentInstanceCom.13656
    -rw------- 1 root other 219976 Dec 27 00:00 core.agentInstanceCom.20988




    Regards,
    Aparna.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,444
    Have a look at
    Code:
    man find
    Especially the -mtime, -type, -name, -delete and -maxdepth options.

    If you need to specify a date range: find can take more than one -mtime and also understand logical operators such as "and" and "or" to further filter the result.
    You must always face the curtain with a bow.

  3. #3
    Linux Newbie
    Join Date
    May 2012
    Posts
    110
    Hi,

    I want the command like :

    # rm -rf Dec 26 core.agentInstanceCom

    Like this I need the command to delete files belonging to the date December 26 Only.

    Please give me the correct command.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,444
    My first post has all the information you need to build it yourself.
    Just try it.
    Hint: Only add the -delete flag once the resultset is *exactly* what you want
    You must always face the curtain with a bow.

  6. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    54
    Quote Originally Posted by redhat70 View Post
    I want the command like :

    # rm -rf Dec 26 core.agentInstanceCom

    Like this I need the command to delete files belonging to the date December 26 Only.

    Please give me the correct command.
    Irithori gave you the command itself, when he suggested you do a man on find. Some people believe it's better to give a hint instead of a full answer, which means you learn something more than just being spoon-fed the appropriate command string.

    Since you asked again, I'll provide a little more advice.

    The general form of the command you want is:

    sudo find / -name core* -mtime 2 -type f -print0 | xargs -0 /bin/rm -f

    Note that this is not EXACTLY what you are asking for. The -mtime selector specifies 24 hour blocks. It is 2139 on Dec 28th as I write this, which means executing this command would delete files created since 2139 on Dec 25th. In order to get exactly Dec 26th, you are going to have to run this exactly at midnight, and then you are going to need nested find commands using the -v option to eliminate those core files from the 27th and later. I probably could come up with the appropriate code, but having given you this much, I agree with Irithori that you should do some of your own research.

    SPECIAL NOTE: Find with a delete is FOREVER. No recover. It's a good idea to use the -print option in place of the -print0 | xargs -0 /bin/rm -f listed above, at least for the first run. That lets you see what files will be deleted before you actually delete them. Better safe than sorry.

  7. #6
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    I think redhat70 is looking for something even simpler... How about this:

    ls -l core* |grep "Dec 26" | awk '{print $NF}' |xargs rm

    (I think redhat, by default, has rm aliased to rm -i, so you might have to use rm -f)

  8. #7
    Just Joined!
    Join Date
    Jul 2008
    Posts
    54
    Quote Originally Posted by abarclay View Post
    I think redhat70 is looking for something even simpler... How about this:

    ls -l core* |grep "Dec 26" | awk '{print $NF}' |xargs rm

    (I think redhat, by default, has rm aliased to rm -i, so you might have to use rm -f)
    You could be right, but the original poster did not indicate all core files were in the same directory, although the example he gave did seem to come from a single directory.

    Since core files can be scattered through a filesystem, depending on what program crashed, I think the use of the find command is more general purpose. However I always approve of learning more than one way to do something. Linux specializes in multiple ways to skin the cat.

  9. #8
    Just Joined!
    Join Date
    Jun 2008
    Posts
    9
    While I can appreciate that you are trying to help the poster find the answer himself, and that the answer is undoubtedly in the man pages, you forget that sometimes for a new user the man pages are intimidating and difficult to master. It is not a tutorial.

    Providing an answer and suggesting the man pages is helpful. Just pointing the user to the man pages is lazy and condescending. The user already knows to do that.

    Sometimes people consult a forum like this to have an easier time finding an answer.

    You need to use the correct number for n to find out how many days ago the 26th was. Today, that number is 5.
    Code:
    find . -mtime n -name "code*" -delete
    And as mentioned, it is a very good idea to find out that you have the answer you want before adding the delete option.
    Last edited by smilingfrog; 01-01-2013 at 12:27 AM.

Posting Permissions

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