1

A couple of days back, I noticed that my server has a almost 1000 plus hidden directories and files that are exact replicas. Let me give you an example.

Level 1 Directory has the following sub-directories and files:

  • wp-content
  • wp-includes
  • index.php
  • wp-mail.php

Now, I notice that along with these 4, there are hidden files like these:

  • ._wp-content
  • ._wp-includes
  • ._index.php
  • ._wp-mail.php

Also, if these sub-directories too have further sub-directories (several levels deep), the same duplication has happened over there too. I'm not sure how did that happen (might have happened when I migrated from site from one server to another).

Anyways, my question is how do I delete all these duplicate and hidden files with prefixes "._" (ignore quotes) - including ones that are 3-4 sub-directories deep. Also such that .htaccess files or other important files/directories are not deleted.

Mine is a Wordpress site and I use Ubuntu 14.04 LTS.

ravichopra
  • 23
  • 4

1 Answers1

0

You can use the find utility:

find /path/to/search -name "._*" | xargs rm

or as an alternative

find /path/to/search -name "._*" -exec rm -r "{}" \;

where /path/to/search has to be replaced by the base location in your local file system that you want to start the search in.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • Does this mean something like this? ~/home/admin/web/abc.com/public_html/ Also, how can I ensure a simpler way to rollback this delete action in case something goes wrong? – ravichopra Feb 15 '16 at 09:30
  • And how do I delete it then? Because the find util will only display the list of files. Right? – ravichopra Feb 15 '16 at 09:33
  • First you can replace the `rm` by something like `ls` first for a test, second you also can use `mv` instead and move all that to some safe location, but most sense of all makes a simple reliable backup that you should have available at all times anyway. – arkascha Feb 15 '16 at 09:33
  • And no, the above commands will _not_ only list files, they will remove them. Please take a closer look. – arkascha Feb 15 '16 at 09:34
  • My bad... Missed the rm. So, I'm thinking of doing something like this.. What do you think? Will this work? `find ~/home/admin/web/abc.com/public_html/ -name "._*" | xargs mv -rp ~/home/admin/web/abcbackup` – ravichopra Feb 15 '16 at 09:40
  • Actually for a `mv` the second alternative is easier to handle if it comes to shell escaping: `find ~/home/admin/web/abc.com/public_html/ -name "*~" -exec mv -rp "{}" ~/home/admin/web/abcbackup \;` Though I am not aware of the flags `-rp` in a normal `mv` command... – arkascha Feb 15 '16 at 09:47