When using the diff -r command to compare two directories, it handles new files by reporting them as additions in the output. Specifically, if a file exists in one directory but not in the other, diff will indicate that the file is present in one directory and missing in the other.
Output for New Files:
- If a file is present in the first directory but not in the second,
diffwill output a message indicating that the file is only in the first directory. - Conversely, if a file is present in the second directory but not in the first, it will indicate that the file is only in the second directory.
Example:
Assuming you have the following directories:
-
dir1/contains:- file1.txt
- file2.txt
-
dir2/contains:- file2.txt
- file3.txt
Running the command:
diff -r dir1/ dir2/
The output might look like this:
Only in dir1: file1.txt
Only in dir2: file3.txt
This output shows that file1.txt is new in dir1, and file3.txt is new in dir2.
