File Transfer Commands
Local File Transfer Commands
cp (Copy)
The cp
command allows you to copy files and directories within the local file system.
## Copy a single file
cp source.txt destination.txt
## Copy a directory recursively
cp -r /source/directory /destination/directory
mv (Move/Rename)
The mv
command moves or renames files and directories.
## Rename a file
mv oldname.txt newname.txt
## Move a file to another directory
mv file.txt /path/to/destination/
Remote File Transfer Commands
scp (Secure Copy)
Securely transfer files between local and remote systems using SSH protocol.
## Copy local file to remote server
scp localfile.txt user@remotehost:/path/to/destination/
## Copy remote file to local system
scp user@remotehost:/path/to/remotefile.txt /local/destination/
rsync (Remote Synchronization)
Advanced file transfer and synchronization tool with efficient delta-transfer algorithm.
## Synchronize local directory to remote server
rsync -avz /local/directory/ user@remotehost:/remote/directory/
## Mirror remote directory locally
rsync -avz user@remotehost:/remote/directory/ /local/directory/
File Transfer Workflow
graph TD
A[Local File] --> |cp/mv| B[Local Destination]
A --> |scp| C[Remote Server]
C --> |scp| A
A --> |rsync| D[Synchronized Location]
Command Comparison
Command |
Scope |
Speed |
Security |
Use Case |
cp |
Local |
Fast |
Low |
Simple file copying |
mv |
Local |
Instant |
Low |
File relocation |
scp |
Remote |
Moderate |
High |
Secure file transfer |
rsync |
Local/Remote |
Efficient |
High |
Large data synchronization |
Advanced Transfer Options
scp Options
-P
: Specify custom SSH port
-r
: Recursive directory transfer
-p
: Preserve file attributes
rsync Options
-a
: Archive mode (preserves permissions, timestamps)
-z
: Compress during transfer
--delete
: Remove extraneous files
LabEx Recommendation
Practice these file transfer commands in LabEx's interactive Linux environments to gain hands-on experience with different transfer scenarios.