# Comparer 2 fichiers:



### diff:

Voir les différences:

```bash
$ diff php73.ini php74.ini

11a12
> upload_max_filesize = 32M
16c17
< extension_dir = /usr/local/lib/php73/modules
---
> extension_dir = /usr/local/lib/php74/modules
38c39
< upload_max_filesize = 32M
---
```



Comparaison côte à côte:

```bash
$ diff -y php73.ini php74.ini

[core]																						[core]
sendmail_path = /usr/bin/ssmtp -t									sendmail_path = /usr/bin/ssmtp -t
ignore_repeated_source = 0												ignore_repeated_source = 0
xmlrpc_error_number = 0														xmlrpc_error_number = 0
memory_limit = 128M																memory_limit = 128M
output_buffering = 4096														output_buffering = 4096
auto_globals_jit = 1															auto_globals_jit = 1
include_path = .:/usr/share/pear									include_path = .:/usr/share/pear
log_errors = On																		log_errors = On
allow_url_fopen = 1																allow_url_fopen = 1
enable_dl = Off																		enable_dl = Off
							      														>	upload_max_filesize = 32M
enable_post_data_reading = 1											enable_post_data_reading = 1
ignore_user_abort = 0															ignore_user_abort = 0
display_startup_errors = 0												display_startup_errors = 0
sys_temp_dir = /var/services/tmp									sys_temp_dir = /var/services/tmp
extension_dir = /usr/local/lib/php73/modules		|	extension_dir = /usr/local/lib/php74/modules
```



Comparaison côte à côte (largeur limitée à 70 colonnes):

```bash
$ diff -y -W 70 php73.ini php74.ini
[core]														[core]
sendmail_path = /usr/bin/ssmtp		sendmail_path = /usr/bin/ssmtp
ignore_repeated_source = 0				ignore_repeated_source = 0
xmlrpc_error_number = 0						xmlrpc_error_number = 0
memory_limit = 128M								memory_limit = 128M
output_buffering = 4096						output_buffering = 4096
auto_globals_jit = 1							auto_globals_jit = 1
include_path = .:/usr/share/pe		include_path = .:/usr/share/pe
log_errors = On										log_errors = On
allow_url_fopen = 1								allow_url_fopen = 1
enable_dl = Off										enable_dl = Off
				  											>	upload_max_filesize = 32M
enable_post_data_reading = 1			enable_post_data_reading = 1
```



Juste savoir si les 2 fichiers diffèrent:

```bash
$ diff -q php73.ini php74.ini
Files php73.ini and php74.ini differ
```



On peut supprimer les lignes identiques (`--suppress-common-lines`):

```bash
$ diff -y -W 70 --suppress-common-lines php73.ini php74.ini
				  												>	upload_max_filesize = 32M
extension_dir = /usr/local/lib	  |	extension_dir = /usr/local/lib
upload_max_filesize = 32M	  			|	unserialize_max_depth = 4096
				  												>	zend.exception_ignore_args = 0
				  												>	[gd]
				 												  >	gd.jpeg_ignore_warning = 1
				  												>
[gd]				  										|	[session]
gd.jpeg_ignore_warning = 1	  		|	session.cookie_samesite =
```



##### Comparer un fichier local et un fichier distant:

```bash
$ ssh bruno@212.227.191.167 "cat upgrade_nextcloud.sh" | diff - /Users/bruno/Documents/Scripts/bash/upgrade_nextcloud.sh | colordiff
35c35
< 		php_version=7.4
---
> 		php_version=8.0

```

##### Comparer 2 fichiers distants sur 2 serveurs différents:

```bash
$ diff <(ssh user@remote-host1 'cat /path/to/file1') <(ssh user@remote-host2 'cat /path/to/file2')
```



Colordiff peut comparer 2 dossiers:

```bash
$ diff -rq photonix photoprism
Only in photonix: .DS_Store
Only in photonix: data
Files photonix/docker-compose.yml and photoprism/docker-compose.yml differ
```



### colordiff:



### diffmerge (GUI):

```bash
$ diffmerge config.json config.json.bak
```



### Comparer 2 dossiers:

```bash
$ diff --brief --recursive bootstrap_darkroom/ s
```

