Find the answer to your Linux question:
Results 1 to 6 of 6
Hi folks, I'm a linux newbie and I was wondering if there's a command for what I'm wanting to do. I have a symlink in every folder on my server. ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    5

    Command to remove same file in all directories please

    Hi folks,

    I'm a linux newbie and I was wondering if there's a command for what I'm wanting to do.

    I have a symlink in every folder on my server. I want to remove these files using one command instead of having to manually go into every directory and remove them.

    Thanks for any help.

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    find /path/to/ -name 'myfilename.ext' -exec rm -f '{}' \;

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    5
    Thanks for the reply but that command didn't work.

    Someone else told me to use this command and that worked.
    Code:
    find . -name filename.ext -exec rm {} ';'

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Strange, it's exactly the same command (provided that the file names do not have a space in the middle, the only difference is the quoting/escaping methods), the only thing that could have gone wrong is if you didn't write the correct path.

    However, the important thing is that you solved it.

  5. #5
    Just Joined!
    Join Date
    Oct 2008
    Posts
    5
    I didn't actually write the path, I changed into the directory and typed with command without the path section, maybe that's why it didn't work. Gave an error something about the -exec section.

    I appreciate you taking time to reply, thank you.

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by glennybee View Post
    I didn't actually write the path, I changed into the directory and typed with command without the path section, maybe that's why it didn't work. Gave an error something about the -exec section.

    I appreciate you taking time to reply, thank you.
    You need to write the path, that's why it didn't work.

    On the other command you posted there's a path, and that's why it works. The "." (dot) in the middles is the path, it means "the current working directory".

Posting Permissions

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