Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I would like to know if 'rm' command can be used to remove particular type of files recursively from a directory or partition? The reason I'm asking is that ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Location
    Bangalore, India
    Posts
    27

    rm to work on particular type of files recursively on a directory/partition

    Hi,
    I would like to know if 'rm' command can be used to remove particular type of files recursively from a directory or partition?

    The reason I'm asking is that my pen drive is infected by a virus. I call it 'folder' virus. The virus creates an 'exe' file by the name of the folder/directory. The more folders you have the more trouble you are in. Of course I can use an anti-virus on windows, but I want to delete them from command line in linux.

    Code:
    ls /media/SV | grep exe
    lists all those exe files in my pendrive. But I'm not able to delete them with same ease. I did,
    Code:
    rm -r /media/SV/*.exe
    and expected that all the files with extension 'exe' will get deleted. It asked for confirmation once and I don't know what I typed. It gave an error "cannot delete /media/SV..." and came to prompt. Only then I realized that everything in my pendrive is deleted. Thankfully I had backed up the content on my hd.

    I think 'rm' interpreted it as to remove the directory /media/SV instead of the 'filter' I set.

    What is the correct format to do what I want to do?

    Regards,
    SV

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    there is no problem with the command you ran( even though you dont need the -r here given that you are deleting only files).
    if you want it to delete without confirmation you just do
    Code:
    rm -f /media/SV/*.exe
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Location
    Bangalore, India
    Posts
    27
    Then why did my whole pen drive got wiped out. I don't remember typing anything extra...

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    its not easy to tell you why that happened without having seen all that went on. maybe you can browse your history and see what you really did
    Linux and me it's a love story

  5. #5
    Just Joined!
    Join Date
    Nov 2007
    Location
    Bangalore, India
    Posts
    27
    ok. may be i can try the same command on a test directory... some also instructed me to try out 'find, exec, xargs' options. will go thru man pages for them too.

    thanks a lot buddy...

  6. #6
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    yeah find is safer given that you can run find to see if the result is what you want then you add -exec rm to remove them.
    its a good idea going through the man pages.
    Linux and me it's a love story

Posting Permissions

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