symlink2file is a command-line tool designed for Unix-like operating systems.
Its primary function is to replace symbolic links (symlinks) in a specified directory
with the actual files they point to. This tool may be useful in scenarios where symlinks
need to be converted to regular files, such as for archival purposes,
simplifying file structures, or preparing data for environments that do not support symlinks.
- Symlink resolving: Recursively resolves symlinks (absolute and relative), including those pointing to other symlinks, to ensure the final result is a regular file;
- Backup: Provides an option to backup original symlinks before replacement;
- Subdirectory traversal (optional);
- Broken symlink handling: Offers configurable behavior for dealing with broken symlinks - either keep them as-is or delete them.
- Preservation of file attributes: Attempts to preserve the original file attributes (like creation time) where possible.
Basic usage:
./symlink2file [OPTIONS] <directory>Options:
--no-backup: Disable backup of original symlinks;--broken-symlinks=keep|delete: Define how to handle broken symlinks (default:keep);--no-recurse: Disable recursive traversal of subdirectories.
Example:
./symlink2file --no-backup --broken-symlinks delete ./path/to/directoryThis command will replace all symlinks in ./path/to/directory with their target files,
without creating backups,
and will delete any broken symlinks found.
symlink2file can be installed either by downloading a pre-compiled binary or by compiling the source code manually.
- Go to the Releases page;
- Download the binary;
- Make the binary executable:
chmod +x symlink2file- Ensure you have Go (
>=1.21) installed on your system; - Clone the repository and compile the source code:
git clone https://github.com/vmikk/symlink2file
cd symlink2file
go build -ldflags="-s -w" symlink2file.goThis will create an executable named symlink2file in the current directory.
For cross-platform compatibility, you can use the GOOS and GOARCH environment variables to specify the target platform. For example:
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" symlink2file.go -o symlink2file-linux-amd64
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" symlink2file.go -o symlink2file-linux-arm64
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" symlink2file.go -o symlink2file-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" symlink2file.go -o symlink2file-darwin-arm64Tests are written using Bats and can be run with the following commands:
# Pull bats submodules
git submodule update --init --recursive
# Run tests
./test/bats/bin/bats test/test.bats