Copy files
syq cp copies files locally, to and from SSH servers, and to and from S3
buckets. This page covers the choices you make in a copy: what to copy, where
it lands, and what happens to files already there.
syq cp project --into backup
This copies project to backup/project. Files already in the destination
are updated when their contents differ, and files the copy doesn’t include
are left alone.
See syq cp for every option, or run syq cp --help.
See where files go
Naming a directory copies the directory itself, so its name appears in the
destination. --srcs-in copies only its contents, and --as gives the copy a
name you choose.
syq cp project --to server --into /backup
Copies project into /backup/project on server. Existing files outside that directory stay.
Each example starts from the same files shown under Before.
Your machine
project/
├── index.html
└── images/
└── logo.svg
Server · Before
/backup/ ├── index.html (old) └── notes.txt
Server · After
/backup/
├── index.html (kept)
├── notes.txt (kept)
└── project/ (new)
├── index.html
└── images/
└── logo.svg
Note to rsync users: trailing slashes don’t matter in syq cp. syq rsync
keeps rsync’s slash rules.
Copy over the network
Use --to to send files, or --from to fetch them:
# Copy project to /backup/project on server.
syq cp project --to server --into /backup
# Fetch /data/a and /data/b from server into ./data/a and ./data/b here.
syq cp --from server -C /data --src a --src b --into ./data
-C DIR (--cwd DIR) says where to find the sources: in the second example,
/data on the server. Without --into or --as, --to server puts files in
your home directory there, and --from server puts them in your current
directory.
Write a server as [USER@]HOST[:PORT], for example alice@server:2222 or
alice@[2001:db8::1]:2222. Unlike in scp, a colon in a path is just part of
the path. Syq sends file data over its own encrypted TCP connection when it
can; if copies fall back to SSH, see
TCP access.
Other routes use the same options:
--to @NAMEsends files to your laptop from a server’s shell, and--from @NAMEcopies files from it; without the@,laptopnames an SSH server. See Use your laptop from a server.--from s3://BUCKETand--to s3://BUCKETcopy to and from S3, including directly between a server and a bucket. See Use S3 storage.--fromand--towith two servers copy directly between them. See Copy between servers.
Copies to and from servers compress data in transit. Use --no-compress to
compare its effect on CPU use and copy speed.
Progress
In a terminal, syq shows a progress bar with speed and an estimated finish
time. When the copy ends, it prints a summary of copied and skipped files and
any errors, and a timing line that splits the total into setup, planning,
transfer, and finalization. Add -v to list the copied paths, or
--no-progress to hide the bar. When output is redirected, --progress shows
the bar and the timing line, and --stats prints the timing line. See
Speed to investigate a slow copy.
Choose a destination
| Option | Meaning |
|---|---|
--into DIR | Put the selected names inside DIR, creating it if needed |
--as PATH | Give one source this exact destination name |
--into-new DIR, --as-new PATH | Also require the destination not to exist |
--into-existing DIR, --as-existing PATH | Also require it to exist |
# Rename the copy and refuse to overwrite an existing entry.
syq cp report.txt --as-new reports/final.txt
--as can rename a directory too. To rename several sources, use
mappings.
Syq refuses to replace a directory with a file, or a file with a directory. See filename and type conflicts when copying between filesystems with different naming rules.
As a destination, an rclone mount needs rclone’s --vfs-cache-mode writes or
full; otherwise most copies fail. See
rclone’s file caching.
Choose which existing files to update
By default, syq copies missing files and updates existing files whose contents
differ. Existing directories remain containers. To protect existing files, or
update only older ones, choose another policy with --if-exists:
| Value | Existing files |
|---|---|
error-if-different | Accept matching contents; reject differences |
error | Reject every existing file, including identical files |
keep | Leave contents and metadata alone |
update (default) | Update differing contents and apply requested metadata |
update-if-older | Keep newer destinations; otherwise update differing contents |
A file counts as unchanged when its size and modification time match, unless
you add --hash. error-if-different compares
contents before rejecting a file whose time differs, so it accepts identical
files, except between S3 buckets (see
Copies between S3 buckets).
--as-new and --into-new check only the destination you name; --if-exists
applies to every entry the copy writes.
keep, error, error-if-different and --as-new also keep a file that
another program creates at the same name during the copy. A file created just
before syq moves its copy into place can still be replaced under keep on
filesystems without an atomic no-replace rename, such as NFS, and under all of
them on FAT and exFAT on macOS and on rclone mounts.
See Update policies for supported combinations.
Choose a transfer strategy
You rarely need this option. By default, a copy between machines compares each file it replaces with the old destination file and sends only the blocks that differ, as rsync does, at the cost of reading the old file. Unlike rsync, it matches blocks only at the same offset: data appended to a file is cheap to send, but data inserted near its start is not. A copy within one machine, including to a mounted network filesystem, copies whole files.
--transfer-strategy changes this:
| Strategy | Behavior |
|---|---|
whole-file | Copy each file in full, without looking at the old destination file |
aligned-block | Send only the blocks that differ from the old destination file, matching blocks at the same offset |
locality (default) | whole-file within one machine, aligned-block between machines |
syq cp --srcs-in source --to server --into destination \
--transfer-strategy whole-file
In syq rsync, -W (--whole-file) selects whole-file and --no-W
selects aligned-block. S3 and descriptor copies don’t accept the option. See
comparison tuning for
block size and controlled comparisons.
Preview changes
Add --dry-run -v to list planned changes without copying or deleting files.
Include --hash to compare file contents during the preview:
syq cp --dry-run -v --srcs-in project --into backup
A dry run can still install syq on the server; see Automatic installation on SSH servers.
Mirror a directory
Use --prune to remove destination entries that are absent from the source:
syq cp --prune --max-delete 100 --srcs-in build --into-existing deploy
This makes the contents of deploy match build: it copies changes, then
removes extras. Preview with --dry-run -v first. If more than 100 removals
are planned, or reading the source or copying fails, syq deletes nothing.
Ignored paths are kept.
Placement decides where pruning happens. Compare:
# Mirror build inside backup/build; leave the rest of backup alone.
syq cp --prune build --into backup
# Mirror build directly inside backup; remove extras throughout backup.
syq cp --prune --srcs-in build --into backup
To free space first, use --prune-before. It removes extras after syq has
listed the source but before copying. If the copy then fails, the extras stay
deleted. --max-delete applies as with --prune. See
Pruning for restrictions and files kept for
recovery.
Select files by metadata
Use --where to select source entries, and --copy-if to decide, for each
entry, whether the copy may create or update its destination:
syq cp --srcs-in project --into backup \
--where 'src.kind = "file" and src.size >= 1MiB' \
--copy-if 'not dst.exists or src.mtime > dst.mtime'
Excluded source entries protect their destination counterparts from pruning. See expressions for fields and operators.
Ignoring paths
# Use the project's existing ignore rules.
syq cp --ignore-from .gitignore --srcs-in project --into backup
# Skip node_modules and object files.
syq cp --ignore node_modules --ignore '*.o' --srcs-in project --into backup
Patterns use gitignore syntax and match paths relative to each selected source
directory, in filesystem and S3 copies alike. For example, /build/ excludes
the top-level build directory inside every selected source, but not a
selected directory named build. Rules apply in command-line order, the last
match wins, and ! re-includes a path. syq rsync uses the same rules with
--syq-ignore and --syq-ignore-from.
| Pattern | Matches |
|---|---|
foo | A file or directory named foo at any depth |
/foo | foo at the source root |
foo/ | Directories named foo |
* | Within one path component |
** | Across path components |
Ignored directories are not scanned. To keep part of one, include the parent:
# Skip other logs, but copy logs/keep and its contents.
syq cp --ignore 'logs/*' --ignore '!logs/keep/' --srcs-in project --into backup
Resume an interrupted copy
Rerun the same command. Syq reuses completed files and, where it kept them, the matching parts of interrupted ones.
The rerun applies the same placement and --if-exists checks, so a -new
placement or --if-exists=error refuses entries the first run created, and
error-if-different refuses files that differ, because it can’t tell a partly
written file from one it must leave alone. To finish such a copy, rerun with
--if-exists=update, which also updates every other differing file the first
policy protected, or, for a -new placement, with --into or --as. To
give directories the first run created their source permissions, add
--copy-metadata=permissions,mtime to the rerun.
When a rerun finishes a file, it also removes the partial files that earlier copies left for it, as long as no other program has them open for writing. Where another copy may still be writing them, or where syq can’t tell, such as on macOS or a network filesystem, it leaves them and says how many files have them. To remove leftovers:
syq clean-partials --dry-run -v backup
syq clean-partials backup
See syq clean-partials for when a rerun can
remove them, remote cleanup, and recovery entries that need inspection before
removal.
Check file contents
By default, syq skips files whose size and modification time match. If a file
could change without changing either, use --hash to compare contents
instead; a file whose contents already match is left alone:
syq cp --hash --srcs-in project --into backup
--hash-or-copy also rechecks those files, but compares contents only where
the transfer strategy compares blocks, and
recopies other files whole. With the default strategy, it recopies every file
in a copy within one machine.
To require known contents, give expected hashes in a mapping. See Integrity checking for timestamp precision and the algorithms. For consistent source data, stop other writers or copy a snapshot.
In-place writes
Syq normally writes each file under a temporary name and renames it into place
when it’s complete. Replacing a file this way needs write permission on its
directory and room for a second copy. Use --in-place when that cost matters:
--in-place=newwrites new files directly at their final names, which saves a temporary name and a rename for each one; existing files are still replaced as usual. Readers can see a file before it’s complete, and an interruption leaves it incomplete until a rerun finishes it.--in-place=updatealso updates existing files where they are, writing only the changed parts, so a small change to a large file needs no second copy. Anyone who has the file open, or opens it during the copy, can read the new contents, and an interruption leaves a mix of old and new contents until a rerun finishes it. Nothing else should write to the file during the copy.syq rsync --inplacedoes the same.
syq cp --in-place=update disk.img --to server --into /vm
Syq writes into an existing file only when doing so gives nobody access to
the new contents that an ordinary copy wouldn’t. It replaces other files as
usual, such as a file with other hard links or another owner, or one on a
filesystem
where syq can’t tell whether it has other names;
the summary says how many and why. Until the copy succeeds, files written in
place stay writable by their owner, and some are readable only by their
owner; an interrupted copy can leave them that way, and a rerun fixes this
only with --copy-metadata=permissions. See
Update policies before combining in-place
writes with other policies.
Copy metadata
By default, new and updated files get the source’s modification time. New
files also get the source’s read, write and execute permissions, limited by
the umask or the directory’s default ACL; existing files and directories keep
theirs. Files whose contents already match keep all their metadata, so if
their times differ, they can be read again on every run; add
--copy-metadata=mtime (alias times) to make the times match.
To preserve more, choose what to copy, as with rsync’s options:
syq cp --copy-metadata=permissions,ownership project --into backup
| Syq option | Corresponding rsync option |
|---|---|
--copy-metadata=permissions | -p |
--copy-metadata=ownership | -o -g --numeric-ids |
--copy-metadata=specials | -D (devices and special files) |
--copy-metadata=hardlinks | -H (regular files) |
--copy-metadata=acls | -A (native ACLs; implies permissions) |
--copy-metadata=xattrs | -X (extended attributes) |
--copy-metadata=atimes | -U (access times; on Linux, kernel 5.8 or later) |
--copy-metadata=crtimes | -N (birth times; macOS destination) |
--open-noatime | --open-noatime (reading doesn’t update source access times); rsync’s -UU selects both this and -U |
Setting ownership needs suitable privileges on the destination. Hard links,
ACLs, xattrs, access times and birth times are not part of syq rsync -a, and
descriptor, stream-mapping and S3 copies reject them. No option preserves
filesystem flags such as immutable, or restores ctime or inode numbers. See
metadata details, and
Copies between S3 buckets for
S3 headers, tags and storage class.
--sparse (rsync -S) turns runs of zeros into holes in local and SSH
copies. The destination filesystem must support holes, or the copy fails. It
isn’t part of -a.
Hard links, ACLs, and extended attributes
For archival copies on Linux or macOS:
syq cp --copy-metadata=permissions,ownership,specials,hardlinks,acls,xattrs --srcs-in source --into backup
# The rsync-compatible spelling:
syq rsync -aHAX --numeric-ids source/ backup/
With hardlinks, selected names for the same file share one destination file
in local and SSH copies; links to files outside the selection are not
reconstructed. A large tree takes longer to start copying. On a filesystem
without hard links, such as FAT, exFAT or an rclone mount, syq copies one name
of each group and reports the others as failed.
acls copies ACLs along with permissions, and xattrs copies extended
attributes; see
ACLs and extended attributes
for which ones, between which systems, and what happens to the destination’s
own.
If destination files have other hard links or another owner, a directory’s permissions block a change, or updating only metadata is unexpectedly slow, see How syq changes existing files and directories.
Symlinks
Syq copies the symlinks inside a directory as links. A symlink you name as a
source stops the copy: pass --follow-src to copy what it points to, or name
it with --src-non-dir to copy the link itself. If a shell glob such as
project/* names links, --srcs-in project copies the directory’s contents
instead and keeps its links as links. A symlink elsewhere in a path
you supply also stops the copy unless you pass --follow-src for source paths
or --follow-dst for destination paths. --follow does both, and also
follows paths given to options such as --ignore-from. None of them follows a
link another user made in a shared sticky directory such as /tmp; see
Which symlinks are followed?.
# Copy the directory current-project points to as backup/current-project.
syq cp --follow-src current-project --into backup
# Copy the link current-project itself.
syq cp --src-non-dir current-project --into backup
# Put project inside the directory that backup points to.
syq cp project --follow-dst --into backup
--as PATH names the entry to replace, so --follow-dst only applies to its
parent directories: syq cp report.txt --as latest --follow-dst replaces a
symlink named latest, leaving its target unchanged. See
Filesystem attacks for the security details.
Choose a source directory
Use -C DIR (or --cwd DIR) to resolve source paths from another directory:
syq cp -C /srv/data reports photos --into backup
This copies /srv/data/reports and /srv/data/photos into backup. -C
applies on the machine selected by --from, and doesn’t change where relative
destination paths start.
Use --root DIR instead when selections must stay inside that directory.
Sources must then be relative: ../private is refused, and even with
--follow-src, symlinks can’t lead outside the root.
One copy accepts up to 1,024 named sources, such as a shell glob’s expansion.
For more, select their parent directory with --srcs-in and leave out what
you don’t want with --ignore or --where, or split the copy.
Shell pipelines and file descriptors
Use --src-fd 0 to read bytes from standard input, or --as-fd 1
to send a file’s contents to another program:
# Save generated data directly on the server.
python make_report.py | syq cp --src-fd 0 --to server --as report.csv
# Feed a remote file to a local program.
syq cp --from server report.csv --as-fd 1 | python analyze_report.py
The same options work with local files and S3 objects. Check the whole pipeline’s status: a failed producer can leave syq with an incomplete stream that ends normally. See file descriptors for process substitution, named pipes, and failure handling.
For environment overrides and cache locations, see Environment and local files.