How do I copy files under Linux operating systems?
You need to use the cp command to make copies of existing file. The syntax is as follows:
cp source.file destination.file
OR
cp /path/to/file1 /path/to/file2
For example, make a copy of /etc/passwd as /tmp/password.file, enter:
cp /etc/passwd /tmp/password.file cat /tmp/password.file
To copy file to another system, use scp command:
scp /path/to/file1 user@server1:/tmp
For example, copy /home/vivek/data.txt to server called server1 and into a directory called /home/sales, enter:
scp /home/vivek/data.txt roja@server1:/home/sales
You must know roja users’ password in order to copy a file.
Copy All Files
To copy all files from /data/sales/*.txt to /backup directory, enter:
cp -avr /data/sales/*.txt /backup
Where,
- -a : Archive mode and save file permission
- -v : Verbose mode (show progress)
- -r : Copy directories recursively
scp vs cp command
- The scp copies files between hosts on a network.
- The cp copies files between two directories on same host.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.
🐧 0 comments... add one ↓
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |