{"id":18875257,"url":"https://github.com/doppelar0n/diffdir","last_synced_at":"2026-02-13T20:13:05.041Z","repository":{"id":261333798,"uuid":"869656616","full_name":"doppelar0n/diffdir","owner":"doppelar0n","description":"A Bash script to compare files in two directories","archived":false,"fork":false,"pushed_at":"2025-01-11T21:42:51.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T22:30:14.485Z","etag":null,"topics":["automation","bash","bash-script","cli-tool","diff","dir-compare","directory","directory-comparison","directory-comparison-tool","file-compression","file-diff","open-source","regex","rsync","scripting","shell","shell-script"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doppelar0n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-08T16:58:56.000Z","updated_at":"2025-01-11T21:42:54.000Z","dependencies_parsed_at":"2024-11-06T01:41:36.358Z","dependency_job_id":"b8c71196-68b9-4853-8e51-463dd96155b6","html_url":"https://github.com/doppelar0n/diffdir","commit_stats":null,"previous_names":["doppelar0n/diffdir"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doppelar0n%2Fdiffdir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doppelar0n%2Fdiffdir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doppelar0n%2Fdiffdir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doppelar0n%2Fdiffdir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doppelar0n","download_url":"https://codeload.github.com/doppelar0n/diffdir/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239828864,"owners_count":19703961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash","bash-script","cli-tool","diff","dir-compare","directory","directory-comparison","directory-comparison-tool","file-compression","file-diff","open-source","regex","rsync","scripting","shell","shell-script"],"created_at":"2024-11-08T06:06:43.484Z","updated_at":"2026-02-13T20:13:00.006Z","avatar_url":"https://github.com/doppelar0n.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# diffdir\n\n`diffdir` is a Bash script for comparing files in two directories. It helps identify differences between the contents of two directories, including all files and subdirectories.\n\n## Why?\n\nIf you want to compare two directories, you can use:\n\n```bash\ndiff -r \u003csource_directory\u003e \u003cdestination_directory\u003e\n```\n\nThat's fine, but what if you want to ignore a `.env.local` file and a `local.json` file in the destination directory?\n\n```bash\ndiff -r \u003csource_directory\u003e \u003cdestination_directory\u003e | grep -v -E \"\\.env\\.local$|local\\.json$\"\n```\n\nThe problem with this approach is that if there are no .env.local or local.json files, you'll get an exit code 1 because grep can't find them. If there are such files, the exit code will be 0, even if the directories are completely different. In many scripting scenarios, the exit code is essential for determining whether the directories differ.\n\nAlternatively, you can use rsync, but it also has an exit code issue. rsync will always return exit code 0:\n\n```bash\nrsync -n -r -v --exclude='*.env.local'  \u003csource_directory\u003e \u003cdestination_directory\u003e\n```\n\nIn both cases (diff+grep and rsync), you could theoretically count lines with `| wc -l`, but that’s not a clean solution.\n\nWith `diffdir`, you can simply do this:\n```bash\ndiffdir \u003csource_directory\u003e \u003cdestination_directory\u003e --ignore-files \"^/\\.env\\.local$|^/local\\.json$\"\n```\n...and you'll get the expected exit code!\n\nYou face the same problem with the exit code when you want to ignore extra files and directories in the destination directory. See more [Examples](#example).\n\n## Installation\n\nClone the repository from GitHub:\n\n```bash\ngit clone https://github.com/doppelar0n/diffdir.git\ncd diffdir\n```\n\nCopy the program to /usr/local/bin/ to make it globally available:\n\n```bash\nsudo cp diffdir /usr/local/bin/\n```\n\n## Usage\n\nRun the script with the following parameters:\n\n```bash\n./diffdir \u003csource_directory\u003e \u003cdestination_directory\u003e [OPTIONS]\n```\n\n### Options\n\n- `--fast-fail`: Enable fast fail. If a difference is found, the script exits immediately. Helpful for scripts.\n- `--find-type \u003cstring\u003e`: Specify the types to find in the directory. The default is `fd` (files and directories).\n- `--ignore-dest-extras`: Ignore extra files or subdirectories in the destination directory.\n- `--ignore-files \u003cregex\u003e`: Ignore files or paths matching this regex pattern.\n- `-h`, `--help`: Display help message.\n\n### Example\n\nTo compare the contents of two directories:\n\n```bash\n./diffdir /path/to/source_directory /path/to/destination_directory\n```\n\nIgnore all `.img` files:\n```bash\n./diffdir /path/to/source_directory /path/to/destination_directory --ignore-files \"\\.img$\"\n```\n\nIgnore all `.png` and `.jpeg` files:\n```bash\n./diffdir /path/to/source_directory /path/to/destination_directory --ignore-files \"\\.png$|\\.jpeg$\"\n```\n\nIgnore all `.env.local` and `local.json` files in root directory:\n```bash\ndiffdir \u003csource_directory\u003e \u003cdestination_directory\u003e --ignore-files \"^/\\.env\\.local$|^/local\\.json$\"\n```\n\nIgnore all `.env.local` and `local.json` files in all sub directory:\n```bash\ndiffdir \u003csource_directory\u003e \u003cdestination_directory\u003e --ignore-files \"/\\.env\\.local$|/local\\.json$\"\n```\n\nIgnore all files that ends with `.env.local` or `local.json` in all sub directory:\n```bash\ndiffdir \u003csource_directory\u003e \u003cdestination_directory\u003e --ignore-files \"\\.env\\.local$|local\\.json$\"\n```\n\nIgnore any path containing `abc`. This will ignore `abc` in both source and destination directories, but only in sub-paths:\n```bash\n./diffdir /abc/path/to/source_directory /abc/path/to/destination_directory --ignore-files \".*abc.*\"\n```\n\nIgnore all files and subdirectories that exist only in the destination directory:\n```bash\n./diffdir /path/to/source_directory /path/to/destination_directory --ignore-dest-extras\n```\n\n`diffdir` uses the `find` command to locate all files and directories. If you want to ignore all empty directories, you can specify the find type to only include files (f), thus ignoring empty folders:\n```bash\n./diffdir /path/to/source_directory /path/to/destination_directory --find-type f\n```\n\n### Error Handling\n\nIf differences between files or directories are found, the script outputs a corresponding message and exits with a non-zero exit code.\n\n### Test\n\nRun test with:\n```bash\ndocker run -it -v \"$PWD:/code\" bats/bats:latest /code/test\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request with any enhancements or bug fixes.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoppelar0n%2Fdiffdir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoppelar0n%2Fdiffdir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoppelar0n%2Fdiffdir/lists"}