How to exclude all subdirectories when comparing the difference between two directories in Linux? - linux

I tried using
diff --exclude diff -- x but none of it is what I'm looking for.
Please help.

Related

How can I compare the directry lists inside directories?

I have 2 directories, A and B. In A, I have subdirectories 1, 2, 3, 4 while in B I have 1 and 3. How can I highlight 2 and 4 easily?
The contents of the subdirectories are the same, respectively, so I just want to compare the names.
Mark -> Compare Directories only compare files, but not directories.
I don't know whether you can use other tools, but there is another way to compare directories (unless you don't mind using a command line).
In macOS you can simply type this command in the terminal:
$ diff A/ B/
Common subdirectories: A/1 and B/1
Only in A/: 2
Common subdirectories: A/3 and B/3
Only in A/: 4
or
$ diff -rq A B
Only in A/: 2
Only in A/: 4
-r recursively compares any subdirectories
-q shows only differences without any details
For Windows
preinstalled comp command. Here is the link
preinstalled fc command. Here is the link
also you can download gnuwin32 which provides diff command and you can use it in almost the same way as described above.
Hope it helps somehow.

How do I get list of paths that exclude certain subdirectories

I want to copy all my projects to google drive using rclone, but I don't want to copy files in directories like node_modules,
Example:
root: project
subdirecotry: myBlog/node_modules/, myBlog/backend/node_modules.
I am an beginner in Linux so I don't know how to achieve it using find, grep, etc.
You are asking two questions.
How to list paths that exclude certain subdirectories
How to exclude certain subdirectories when using rclone
Listing
Use the find command. Here is an example directory with three subdirectories:
ls
one two three
To output a listing of only one and two, omitting three, use find like this:
find . -type d -not -path ./two
.
./one
./three
rclone
Use the --exclude switch, to exclude the contents of specific subdirectories - in this example, the subdirectory two (underneath stackoverflow), would be ommitted in the sync to destination:
rclone sync stackoverflow/ destination/ --exclude='two/**'
See the rclone documentation for further details.

Compare directories with ssh

I have a directory dirA on my laptop, and a directory dirB on a remote host to which I can ssh. Both directories include subdirectories.
I would like to compare the full content of the two subdirectories by using ssh. In particular, I want to know what file or subdirectory in dirA is not in dirB, and the other way around. The two directories are large enough that I do not want to transfer the full files through ssh, just compare their names and locations.
Do you know how to do this?
Thank you.
use rsync with the --dry-run option; something like:
rsync -ar --dry-run local-dir/ user#remote:remote-dir
This will output the list of files that would have been synchronized. So if there is no output; there is no difference.
edit : Two options you might consider:
--ignore-times : ignore the timestamp of the local and remote files when comparing the files.
--size-only : if you want to speedup the rsync command. rsync compares only the size of the files. Note that this is error prone (files with same size might differ)
--itemize-changes : show the changes between files
you may take a look at this anwser

difference between contents of two directories

I have find the difference in all the cpp, header and shell scripts files between
two directories which can have subdirectories as well.
You can use the recursive option of diff
diff -r old_dir new_dir

Find folders with specific name and no symlink pointing to them

I'm trying to write a shell script under linux, which lists all folders (recursively) with a certain name and no symlink pointing to it.
For example, I have:
/home/htdocs/cust1/typo3_src-4.2.11
/home/htdocs/cust2/typo3_src-4.2.12
/home/htdocs/cust3/typo3_src-4.2.12
Now I want to go through all subdirectories of /home/htdocs and find those folders typo3_*, that are not pointed to from somewhere.
Should be possible with a shellscript or a command, but I have no idea how.
Thanks for you help
Stefan
I think none of the common file systems store if there are symlinks pointing to this file in the file node, so you would have to scan all other files to see if it is a symlink to this one. If you don't limit your depth of search to a certain level, this might take a very long time. If you want to perform that search in /home/htdocs, for example, it would work something like this:
# find specified folders:
find /home/htdocs -name 'typo3_*' -type d | while read folder; do
# list all symlinks pointing to $folder
find -L /home/htdocs -samefile "$folder"|grep -v "$folder\$"
done

Resources