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 07-19-2021, 03:12 PM   #1
mattdawolf
Member
 
Registered: Aug 2018
Posts: 34

Rep: Reputation: Disabled
script to find files that are present in a destination directory


What would be a good way to find out if filenames in Source_dirX are present in Destination_dirY, accounting for subdirectories? and options to list or delete the files from the source?
 
Old 07-19-2021, 05:36 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
There are any number of duplicate detection tools for linux - even some GUI ones (which I've never tried). Have a search here on LQ. All will offer to do deletion based on various criteria - personally I only use tools that give a list I can eye-ball before I stuff the list into a script. fdupes is a CLI example.
 
Old 07-19-2021, 05:40 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,105
Blog Entries: 6

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
Look at:
man diff
Code:
diff -ur dir1 dir2
man find
Files that are in both Dir1 and Dir2:
Code:
find "$Dir1/" "$Dir2/" -printf '%P\n' | sort | uniq -d
Files that are in Dir1 but not in Dir2:
Code:
find "$Dir1/" "$Dir2/" "$Dir2/" -printf '%P\n' | sort | uniq -u
man comm
Code:
comm -12 <(ls -F $1) <(ls -F $2)
Or just bash
Code:
name1=${file1##*/}
name2=${file2##*/}
if [[ $name1 == $name2 ]]; then
    echo ""$name1" exists in both directories"
fi
Etc.
 
  


Reply

Tags
automation, script


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
Bind mount (script) of various files within a directory pointing to a unified destination fnords Linux - General 1 12-24-2015 11:57 AM
[SOLVED] match source pattern in destination and substitute in destination usin AWK 123raajesh Linux - Software 7 11-13-2013 04:22 AM
echo "blabla" in a script present present in /etc/rc.d/rc5.d/S96dinesh murugesan Linux - Newbie 3 04-14-2009 10:53 PM
destination unavailable W/ vpn. All other net destination o.k. MikeOfAustin Linux - Networking 1 04-07-2007 04:42 PM
ndiswrapper - driver present:harware present but no connection esteeven Linux - Wireless Networking 2 12-26-2004 04:06 PM

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

All times are GMT -5. The time now is 10:36 AM.

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