Jump to content
xisto Community
BCD

Find And Delete Files In A Directory Not Existing In Master Directory (ubuntu)

Recommended Posts

I need a quick method of doing this job other than doing it manually. I have two folders, say "slave folder" (SF) and "master folder" (MF). Say MF contains 1000 files and SF contains 1300 files. I need to delete the extra 300 files in SF.I think I would need to write a script to do that, and by the way I am using Ubuntu. I was just browsing for a solution, can grep do that? If so, can someone help me in forming the grep expression. To make that easy, I have some details which I already know about and 100 percent sure, so no need to worry about these possibilities:1) SF surely contains all the files from MF.2) There are no folders present in either MF or SF, they only contain files.Thanks for any help.

Share this post


Link to post
Share on other sites

Is there a reason why you don't delete _everything_ in Slave folder and then copy _everything_ from MF to SF? You didn't mention if they were exact duplicates or the SF contained updated stuff.I've been trying to figure it out, but I'm a newbie with scripts myself. I'm thinking you might find the "uniq" command useful, I don't know much about it , but it looks promising. Another command is "diff". I'm back with another stupid suggestion, the file manager Midnight Commander has an option to compare folders (directories). It works well and easily at highlighting files that don't belong - which is what you want - but I don't know exactly what to do with the files once they are highlighted. I've only been using MC for a whole 15 seconds. It's kind of a strange beast to me.

Edited by rob86 (see edit history)

Share this post


Link to post
Share on other sites

I think I found something that looks very similar to what you need.

http://www.damonkohler.com/2009/10/finding-unique-files.html

This guy is comparing two folders and outptting the uniques. I don't think it would be too difficult to make a script to process this information. It might be a good idea to copy uniques to a FolderThree, and then you could erase SF and rename FolderThree to SF's name, unless there's a better way, I don't know.

Share this post


Link to post
Share on other sites

Is there a reason why you don't delete _everything_ in Slave folder and then copy _everything_ from MF to SF? You didn't mention if they were exact duplicates or the SF contained updated stuff.

We are dealing with around 600-700 GB currently and deleting and copying whole data doesn't seem to be efficient, as the process needs to repeated several times in a day. The new files in SF are small in number (few GB's) and can be quickly removed using script. Yes, the common files in SF and MF are exact duplicates (no modification although access dates may differ).

Thanks for the link, first I will try understanding that and later try modifying it. Midnight commander seems to solve the problem, if it highlights then its just a matter of hitting delete. After installing through synaptic where can I find MC, it doesnt appear in applications menu, Ubuntnu 9.04.

Thanks. Searching for rep button, is there any? :P
Edited by BCD (see edit history)

Share this post


Link to post
Share on other sites

Well that's the thing about MC, it's run in a terminal. You open up a terminal and type "mc". I don't know how to do all the basic stuff in mc, like selecting files. I never used it much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.