This discussion is archived
4 Replies Latest reply: Aug 29, 2012 9:14 AM by TommyReynolds RSS

Deleting multiple files!

446 Newbie
Currently Being Moderated
i need to delete multiple files at a time without using extension name in linux system,is there any option to delete the files according by the order(like first 5 or 10 files),as we are having different extension names.

Edited by: 446 on Aug 29, 2012 5:31 AM
  • 1. Re: Deleting multiple files!
    Dude! Guru
    Currently Being Moderated
    You can use the ls command to list files in various orders. What order are you are referring to?

    You might want to think about what defines the order and use the find command to delete files with a common search criteria. The following command, for example, deletes files in the current directory that where not modified for 7 days:

    <pre>
    find ./ -type f -mtime +7 -exec rm -f {} \;
    </pre>

    There are lots of other options. See the man page for find (man find) for more info.
  • 2. Re: Deleting multiple files!
    446 Newbie
    Currently Being Moderated
    thanks for ur response,suppose i have some 30 files having diff extensions and i need to delete the first 20 files alone ,how can i do it?
  • 3. Re: Deleting multiple files!
    Dude! Guru
    Currently Being Moderated
    I think I understood your questions, but it seems you did not understand my reply. There is no such thing like the first files let alone, and there is no parameter to the rm command to delete the "first" or "last" files.
  • 4. Re: Deleting multiple files!
    TommyReynolds Expert
    Currently Being Moderated
    It all depends on how to come up with the list of file names. Something like this:
    $ ls foo.* | head -n 5 | xargs rm -rf
    Just change the ls(1) command and the head count.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points