How to compare the ls output of two folders to find a missing directory?Compare two folders for missing filesHow do you compare two folders and copy the difference to a third folder?given a file, find where within a subdirectory it was copied tomerge two image foldersFind differences of ownerships between two home folders?Streaming compare the contents in two directoryMove files that have the same case-insensitive filenameHow should I merge two folders on the same filesystem?Print Folders Missing .txt FiletypeCompare two directories for a certain extension and then move the missing ones to a new directoryCompare two folders for missing files
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
What happens to unproductive professors?
Why did Old English lose both thorn and eth?
Is it possible to see individual photons impressioning film?
Given a 32 bit number, what is an efficient way to scale each byte by a certain factor?
Integer Lists of Noah
Could you brine steak?
Why is the ladder of the LM always in the dark side of the LM?
Reverse dots and boxes
How do you move up one folder in Finder?
What is the right approach to quit a job during probation period for a competing offer?
Is there a nice way to implement a conditional type with default fail case?
Do I have to worry about delays in international trains? (UK, Belgium, Germany)
What happens when adult Billy Batson says "Shazam"?
How to drill holes in 3/8" steel plates?
Is that a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?
What are some further readings in Econometrics you recommend?
How effective would wooden scale armor be in a medieval setting?
Why did Harry Potter get a bedroom?
Did the Ottoman empire suppress the printing press?
Why is a mixture of two normally distributed variables only bimodal if their means differ by at least two times the common standard deviation?
When did "&" stop being taught alongside the alphabet?
Is there a method for differentiating informative comments from commented out code?
What are the original Russian words for a prostitute?
How to compare the ls output of two folders to find a missing directory?
Compare two folders for missing filesHow do you compare two folders and copy the difference to a third folder?given a file, find where within a subdirectory it was copied tomerge two image foldersFind differences of ownerships between two home folders?Streaming compare the contents in two directoryMove files that have the same case-insensitive filenameHow should I merge two folders on the same filesystem?Print Folders Missing .txt FiletypeCompare two directories for a certain extension and then move the missing ones to a new directoryCompare two folders for missing files
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.
I tried this:
diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt
But it's been like 6 hours yet and no output. ls
in the folders is nearly instant so is there a faster approach than diff?
files
add a comment |
I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.
I tried this:
diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt
But it's been like 6 hours yet and no output. ls
in the folders is nearly instant so is there a faster approach than diff?
files
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago
add a comment |
I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.
I tried this:
diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt
But it's been like 6 hours yet and no output. ls
in the folders is nearly instant so is there a faster approach than diff?
files
I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.
I tried this:
diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt
But it's been like 6 hours yet and no output. ls
in the folders is nearly instant so is there a faster approach than diff?
files
files
asked 8 hours ago
FreedoFreedo
4826 silver badges24 bronze badges
4826 silver badges24 bronze badges
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago
add a comment |
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago
add a comment |
3 Answers
3
active
oldest
votes
This is a fairly simple task for rsync
.
rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
This does a dry run of rsync
ing dir1
's contents into dir2
, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.
Here's a simple test/demo:
$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/
real 0m0.038s
user 0m0.001s
sys 0m0.041s
If you would like to adapt this technique to also check for folders missing from dir1
but present in dir2
, use rsync
's --delete
option:
$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/
The deleting ...
line tells you that dir-0479
is absent from dir1
but present in dir2
.
add a comment |
Try eitherls dir1 > file1; ls dir2 > file2; diff file1 file2
or if you have vimdiff and tree which is the most useful way with sub directories, you could use
tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2
Though, running ls is much faster than tree which is what you are after.
If the difference is in a sub-directory in dir1
eg.
dir1
- dir2
- dir3
- dir4
vs
dir2
- dir2
- dir3
You would need to do
ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2
New contributor
add a comment |
diff -u <(ls dir1) <(ls dir2)
This will make sure diff
does not look inside the subdirs.
Or try this if you are brave ;)
diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?
– Hannu
8 hours ago
1
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too
– Freedo
7 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f528988%2fhow-to-compare-the-ls-output-of-two-folders-to-find-a-missing-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a fairly simple task for rsync
.
rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
This does a dry run of rsync
ing dir1
's contents into dir2
, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.
Here's a simple test/demo:
$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/
real 0m0.038s
user 0m0.001s
sys 0m0.041s
If you would like to adapt this technique to also check for folders missing from dir1
but present in dir2
, use rsync
's --delete
option:
$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/
The deleting ...
line tells you that dir-0479
is absent from dir1
but present in dir2
.
add a comment |
This is a fairly simple task for rsync
.
rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
This does a dry run of rsync
ing dir1
's contents into dir2
, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.
Here's a simple test/demo:
$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/
real 0m0.038s
user 0m0.001s
sys 0m0.041s
If you would like to adapt this technique to also check for folders missing from dir1
but present in dir2
, use rsync
's --delete
option:
$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/
The deleting ...
line tells you that dir-0479
is absent from dir1
but present in dir2
.
add a comment |
This is a fairly simple task for rsync
.
rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
This does a dry run of rsync
ing dir1
's contents into dir2
, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.
Here's a simple test/demo:
$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/
real 0m0.038s
user 0m0.001s
sys 0m0.041s
If you would like to adapt this technique to also check for folders missing from dir1
but present in dir2
, use rsync
's --delete
option:
$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/
The deleting ...
line tells you that dir-0479
is absent from dir1
but present in dir2
.
This is a fairly simple task for rsync
.
rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
This does a dry run of rsync
ing dir1
's contents into dir2
, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.
Here's a simple test/demo:
$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/
real 0m0.038s
user 0m0.001s
sys 0m0.041s
If you would like to adapt this technique to also check for folders missing from dir1
but present in dir2
, use rsync
's --delete
option:
$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/
The deleting ...
line tells you that dir-0479
is absent from dir1
but present in dir2
.
answered 6 hours ago
Jim L.Jim L.
8262 silver badges5 bronze badges
8262 silver badges5 bronze badges
add a comment |
add a comment |
Try eitherls dir1 > file1; ls dir2 > file2; diff file1 file2
or if you have vimdiff and tree which is the most useful way with sub directories, you could use
tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2
Though, running ls is much faster than tree which is what you are after.
If the difference is in a sub-directory in dir1
eg.
dir1
- dir2
- dir3
- dir4
vs
dir2
- dir2
- dir3
You would need to do
ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2
New contributor
add a comment |
Try eitherls dir1 > file1; ls dir2 > file2; diff file1 file2
or if you have vimdiff and tree which is the most useful way with sub directories, you could use
tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2
Though, running ls is much faster than tree which is what you are after.
If the difference is in a sub-directory in dir1
eg.
dir1
- dir2
- dir3
- dir4
vs
dir2
- dir2
- dir3
You would need to do
ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2
New contributor
add a comment |
Try eitherls dir1 > file1; ls dir2 > file2; diff file1 file2
or if you have vimdiff and tree which is the most useful way with sub directories, you could use
tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2
Though, running ls is much faster than tree which is what you are after.
If the difference is in a sub-directory in dir1
eg.
dir1
- dir2
- dir3
- dir4
vs
dir2
- dir2
- dir3
You would need to do
ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2
New contributor
Try eitherls dir1 > file1; ls dir2 > file2; diff file1 file2
or if you have vimdiff and tree which is the most useful way with sub directories, you could use
tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2
Though, running ls is much faster than tree which is what you are after.
If the difference is in a sub-directory in dir1
eg.
dir1
- dir2
- dir3
- dir4
vs
dir2
- dir2
- dir3
You would need to do
ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2
New contributor
edited 8 hours ago
New contributor
answered 8 hours ago
T. RocheT. Roche
112 bronze badges
112 bronze badges
New contributor
New contributor
add a comment |
add a comment |
diff -u <(ls dir1) <(ls dir2)
This will make sure diff
does not look inside the subdirs.
Or try this if you are brave ;)
diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?
– Hannu
8 hours ago
1
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too
– Freedo
7 hours ago
add a comment |
diff -u <(ls dir1) <(ls dir2)
This will make sure diff
does not look inside the subdirs.
Or try this if you are brave ;)
diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?
– Hannu
8 hours ago
1
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too
– Freedo
7 hours ago
add a comment |
diff -u <(ls dir1) <(ls dir2)
This will make sure diff
does not look inside the subdirs.
Or try this if you are brave ;)
diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)
diff -u <(ls dir1) <(ls dir2)
This will make sure diff
does not look inside the subdirs.
Or try this if you are brave ;)
diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)
edited 8 hours ago
answered 8 hours ago
GMasterGMaster
1,9451 gold badge13 silver badges21 bronze badges
1,9451 gold badge13 silver badges21 bronze badges
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?
– Hannu
8 hours ago
1
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too
– Freedo
7 hours ago
add a comment |
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?
– Hannu
8 hours ago
1
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too
– Freedo
7 hours ago
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?– Hannu
8 hours ago
diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort)
?– Hannu
8 hours ago
1
1
=) ............
– Hannu
8 hours ago
=) ............
– Hannu
8 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too– Freedo
7 hours ago
comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort)
also worked for me and was very fast too– Freedo
7 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f528988%2fhow-to-compare-the-ls-output-of-two-folders-to-find-a-missing-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Answered in stackoverflow.com/questions/4997693/…
– GMaster
8 hours ago
@GMaster I'm asking for a faster approach
– Freedo
8 hours ago
Sounds similar to unix.stackexchange.com/q/524074/117549
– Jeff Schaller♦
7 hours ago