LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-01-2014, 03:44 PM   #1
MirceaKitsune
Member
 
Registered: May 2009
Distribution: Manjaro
Posts: 156

Rep: Reputation: 1
Delete everything in one directory not present in another


A little something slightly outside my bash scripting skills; I want to make a script which deletes everything in one path not present in another path. It must be fully recursive, so it applies to all files / folders / subfolders inside the two paths. For example, if I have:

/foo1/bar1.txt
/foo2/bar1.txt
/foo2/bar2.txt

The command would delete /foo2/bar2.txt because the file isn't also present in /foo1, but keep /foo2/bar1.txt because it is. Does anyone know of a shell script that takes both base folders as arguments and does this?
 
Old 06-01-2014, 05:09 PM   #2
potato_farmer
Member
 
Registered: May 2014
Posts: 55

Rep: Reputation: Disabled
Is the data in /foo2/ a copy of the date in /foo1/? If so, you can use rsync with the "delete from target" option. This will sync /foo1 content over to /foo2 and remove any content that is not found in /foo2/ that exists in /foo1.

If the data in the two directories is different, you can write a script to run a find command on /foo2/ and check if the the file or directory exists in /foo1, if not, you can delete it from /foo2.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to delete directory in a existing directory with single command Tauatioti Linux - Newbie 1 11-30-2013 04:04 AM
present working directory problem. Ribo01 Linux - Newbie 1 11-19-2010 11:57 AM
C++: Determining present working directory harshnoise Programming 4 09-16-2005 09:28 AM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration