bash-tutorial/tutorial/diff.org

42 lines
1.0 KiB
Org Mode
Raw Permalink Normal View History

2022-09-24 19:34:31 +02:00
#+options: toc:nil num:nil
2023-06-26 14:12:16 +02:00
#+date: 2022-09-24
2022-09-24 19:34:31 +02:00
* Comparing the content of two files or directories
~diff~ is a command line utility used to compare two files or directories
** Compare files
To compare the content of two files use something like
#+begin_example bash
2023-06-26 14:12:16 +02:00
diff file1.txt file2.txt
2022-09-24 19:34:31 +02:00
#+end_example
You can redirect the output to a file and make a patch: a file containing the differences between both files
#+begin_example bash
2023-06-26 14:12:16 +02:00
diff file1.txt file2.txt > patch.txt
2022-09-24 19:34:31 +02:00
#+end_example
** Comparing directories
2023-07-04 15:23:52 +02:00
Some arguments may be hepful to have an output showing the differences between
two directories:
* ~--brief~ (show only the differences) and
* ~-r~ (compare the directories that are located within the main directory also)
2022-09-24 19:34:31 +02:00
#+begin_example bash
diff --brief -r directory1 directory2
#+end_example
2023-06-26 14:12:16 +02:00
Another approach to compare all the files within each directory is to use:
2022-09-24 19:34:31 +02:00
2023-07-04 15:23:52 +02:00
* ~q~ : Shows only differences
* ~r~ : Run the command recursively
2023-06-26 14:12:16 +02:00
#+begin_example bash
diff -qr directory1 directory2
#+end_example