copy files
How to copy files with style.
Use tar¶
tar and pipes can copy file system trees directly, preserving permissions.
Use rsync¶
Note
Without a trailing slash on the source (sourcefolder), rsync copies the entire source directory, including its name, into the destination. The result is destinationfolder/sourcefolder.
With a trailing slash on the source (sourcefolder/), rsync copies the innards (content of the sourcefolder), into the destination. The result is destinationfolder/README.txt if there is sourcefolder/README.txt.
Use robocopy¶
Robust copy (robocopy) is a file-copying command-line tool baked in Windows 10+.
To see its commands
For instance, to mirror (/MIR) two folders with multithreading (/MT)
Copy a directory tree with exclusions¶
How to exclude some files/folders while copying a folder tree.
tar¶
A filter file .tarignore excludes stuff similar to .gitignore.12
The syntax is similar to .gitignore:
rsync¶
Use --exclude flag in rsync to exclude certain folder(s). 3
rsync -avh --progress sourcefolder /destinationfolder --exclude thefoldertoexclude --exclude anotherfoldertoexclude
Warning
The excluded directory paths are relative to the sourcefolder.
Copy files over SSH¶
How to copy files through the secure shell (SSH).
scp¶
scp works similar to the regular copy (cp) command.4
scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2
tar, pipe, and ssh commands¶
rsync¶
Use a ssh remote as a source or destination folder.
Secure FTP (SFTP)¶
Filezilla and WinSCP can access remote servers via the Secure FTP (SFTP) protocol.
Mount remote directory as a disk via sshfs¶
libfuse/sshfs mounts a remote machine's directory as a local disk.
To unmount the directory after file operations are done: