4 Replies Latest reply on Aug 29, 2012 4:14 PM by TommyReynolds-Oracle

    Deleting multiple files!

      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!
          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:

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

          There are lots of other options. See the man page for find (man find) for more info.
          • 2. Re: Deleting multiple files!
            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!
              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!
                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.