diff -rq /path1 /path2 | grep "^Only in /path1"
This command will recursively compare the directories and print differences.
rsync --dry-run --itemize-changes /path1/ /path2/ | grep '^<'
This command simulates an rsync operation in dry run mode and lists the changes that would be made.
join -v 1 <(ls /path1 | sort) <(ls /path2 | sort)
Using awk.
'
#python
import os
path1_files = set(os.listdir('/path1'))
path2_files = set(os.listdir('/path2'))
missing_files = path1_files - path2_files
for file in sorted(missing_files):
print(file)
'
'
#perl
opendir(DIR1, "/path1");
@files1 = readdir(DIR1);
closedir(DIR1);
opendir(DIR2, "/path2");
@files2 = readdir(DIR2);
closedir(DIR2);
%hash = map { $_ => 1 } @files2;
@missing = grep { !$hash{$_} } @files1;
print join("\n", @missing), "\n";
'
'
#ruby
path1_files = Dir.entries("/path1") - [".", ".."]
path2_files = Dir.entries("/path2") - [".", ".."]
missing_files = path1_files - path2_files
puts missing_files
'
'
#go
package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
files1, _ := ioutil.ReadDir("/path1")
files2, _ := ioutil.ReadDir("/path2")
path2Map := make(map[string]bool)
for _, file := range files2 {
path2Map[file.Name()] = true
}
for _, file := range files1 {
if _, exists := path2Map[file.Name()]; !exists {
fmt.Println(file.Name())
}
}
}
'
'
#rust
use std::fs;
fn main() {
let path1_files: Vec<_> = fs::read_dir("/path1").unwrap().map(|res| res.unwrap().path().file_name().unwrap().to_string_lossy().into_owned()).collect();
let path2_files: Vec<_> = fs::read_dir("/path2").unwrap().map(|res| res.unwrap().path().file_name().unwrap().to_string_lossy().into_owned()).collect();
for file in &path1_files {
if !path2_files.contains(file) {
println!("{}", file);
}
}
}
'
'
#powershell
$path1Files = Get-ChildItem -Path C:\path1 | Where-Object { $_.Attributes -eq 'Normal' } | ForEach-Object { $_.Name }
$path2Files = Get-ChildItem -Path C:\path2 | Where-Object { $_.Attributes -eq 'Normal' } | ForEach-Object { $_.Name }
Compare-Object $path1Files $path2Files | Where-Object { $_.SideIndicator -eq '<=' } | ForEach-Object { $_.InputObject }
'