This repository contains my final project for the “Sistemi Operativi” course. The project consists of a Bash script that implements a custom command called aggiorna
, which can be used to synchronize files from one folder to another based on specific conditions.
The aggiorna
command takes two parameters, both of which must be pathnames (either absolute or relative) of directories. The script performs a series of checks and, if all are satisfied, it selectively copies files from the first directory to the second.
-
The two directories:
- Must not be symbolic links.
- Must not contain each other (i.e., one cannot be a subdirectory of the other).
- Must be at the same depth in the filesystem hierarchy.
-
Once the initial checks pass, the script:
-
Iterates over all regular files in the first directory.
-
For each file:
-
If the file does not exist in the second directory, it is copied.
-
If the file does exist, the script compares modification times:
- If the file in the first directory is more recent, it is copied and overwrites the existing file in the second directory.
- Otherwise, the file is not copied.
-
-
Note: The copy operation is one-way only, from the first directory to the second. No changes are made in the opposite direction.
./aggiorna.sh <source_directory> <target_directory>
Example:
./aggiorna.sh ./dir1 ./dir2
If any of the input requirements are not met (e.g., symbolic links are provided, directories are nested, or at different levels), the script will display a clear error message and terminate without making any changes.