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.
Related
I tried using
diff --exclude diff -- x but none of it is what I'm looking for.
Please help.
Trying to write a script to clean up environment files after a resource is deleted. The problem is all the script is given as input is the name of the resource (this cannot be changed) with zero identifying information beyond that. How can I find the path of the directory the resource is sitting in?
The directory is set up a bit like the following, although much more extensive. All of these are directories, not files. There can be as many as 40+ directories to search, but the desired one is generally not more than 2-3 directories deep.
foo
aaa
aaa_green
aaa_blue
bbb
ccc
ccc_green
bar
ddd
eee
eee_green
eee_blue
fff
fff_green
fff_blue
fff_pink
I might be handed input like aaa_green or just ddd.
As an example, given eee_blue as input, I need to know eee_blue's path from the working directory so I can cd there and delete the directory. IE, I would expect to return bar/eee/eee_blue/ or bar/eee/, either is acceptable.
The "best" option I can see currently is to cd into the lowest level of each directory via multiple greps, get each's contents and look for a match, and when it does (eventually) match save that cd'ing as the path. This frankly sounds awful and inefficient.
The only other alternative method I could think of was a straight recursive grep, but I tested it and at 8 minutes it still hadn't finished running.
This script needs to run on both mac and linux, although in a desperate pinch I could go linux only.
The standard Unix tool for doing this sort of task is the find command. The GNU version of find has more extensive options than the POSIX specification (by quite a margin). The version on macOS Sierra (and Mac OS X) is similar to the GNU version. I found an online manual for OS X 10.9 at Apple find, but there's probably a better location somewhere.
It looks like you might want to run:
find . -name 'eee_blue'
which will print the names of matching files or directories, or perhaps:
find . -name 'eee_blue' -exec rm -fr {} +
which will run the rm -fr command on each name. You can run a custom script you create in place of rm -fr if you prefer; if the logic is complex, it's what I do.
Be extremely cautious before using rm -fr automatically!
We're moving some utilities from an old project to a new to-be-version-controlled one (on the same disk, under different usernames), and I've been tasked with finding utilities that are part of the old account but not the new one, and to find files that are different between the two accounts. The new account has been active for about a year and people have made (small) changes to some files in the old one without making them in the new one.
These utilities are on a remote server that I only have read access to (except my own home folder).
The old account, call it user1, has all its utilities in the ~user1/bin/ folder, including source, executable, and script for each utility.
The new account, say user2, has been set up in a way that each 'executable/script' in the ~user2/bin/ folder is a symlink to the appropriate file in the subfolder ~user2/src/{utilityname}/, which also contains the source for that executable.
Is there an easier way to compare the two directories than
find ~user1/bin/ -maxdepth 1 -printf '%s, %p\n' | sort -k2 > user1.txt
find -L ~user2/bin/ -maxdepth 1 -printf '%s, %p\n' | sort -k2 > user2.txt
and comparing the results manually to see what's different / missing?
Also, the above commands will only let me compare executables/scripts in the ~user2/bin/ folder, which can be different even if the source code in ~user2/src/{utilityname}/ is the same between user1 and user2 (because of different paths in scripts, for example). Is it possible to search the folder in which a utility's symlink target resides for a source file with the same name, so that I can compare source files between user1 and user2 directly?
I would use a different approach: find files which have no duplicates. I suggest this thread, especially the part combining fdupes, find and grep:
fdupes -r backup/ documents/ > dup.txt
find backup/ -type f | grep -Fxvf dup.txt
Though, it may need some more adjustments to adapt it to your needs, for example the use of fdupes' "-s" option.
How can I get a set of the difference of files in folder A that are not in folder B, this should be output to folder C. I other words C would contain all the files that do not exist in B but exist in A? Is there a chain command in linux?
You might use the diff(1) command, perhaps as diff -Naur. BTW, patch(1) is handy too..
But you really want some version control system (a.k.a. revision control). Learn more about git. I strongly recommend you to use it, even for personal small projects.
Later, you might consider publishing some (perhaps most) of your code as free software, e.g. on github
May not be perfect. Try this:
(ls -1 A 2>/dev/null && ls -1 B 2>/dev/null) | sort | uniq -u | xargs -I REPLACE cp A/REPLACE C
Would the rsync command be useful? If you run it with
--dry-run
it would report how it would make one directory the same as the other, without actually changing anything.
I want to list all the files in a directory recursively. I am storing this output in a file that I will later iterate through and use each line as an argument in another command.
However all the commands I have tried have listed the directory name as one of the output lines followed by the files and directories contained in the directory.
I have tried the following:
tree -if --noreport . > files_names.txt
This has given me some success, but it still prints the directories. An example output is as follows:
/testdir
/testdir/rightfolder/
/testdir/rightfolder/file2.txt
/testdir/rightfolder/file3.txt
/testdir/wrongfolder/
/testdir/wrongfolder/file.txt
I have checked the man pages for tree and ls.
Is there a flag or another command that will give me the correct output. I have considered using a flag for tree to list the directories and then removing all those entries from the original list but this is not elegant at all.
You could use find(1) and filter by type:
find ./ -type f