When it comes to transferring files on Linux, it's important to know how to copy files efficiently and avoid overwriting any existing files. This guide will walk you through the process of copying all files except those that are already present on your Linux system.
Step 1: Open the Terminal
To begin, open the terminal on your Linux system. You can usually find it by searching for "Terminal" in the applications menu or by using the shortcut Ctrl + Alt + T.
Step 2: Navigate to the Source Directory
Once the terminal is open, navigate to the directory where your source files are located. You can use the cd command followed by the directory path to move to the desired location. For example, if your files are in the /home/user/documents directory, you would enter the following command:
cd /home/user/documents
Step 3: Copy Files to the Destination Directory
Next, you'll need to specify the destination directory where you want to copy the files. You can use the cp command followed by the source and destination directories. However, to exclude the files that already exist in the destination directory, you'll need to use the --update or -u flag. This flag ensures that only new or modified files are copied.
Here's an example of how to copy all files from the source directory to the destination directory:
cp -ru /home/user/documents /home/user/backup
Step 4: Confirm the Copy
After executing the copy command, you should see a list of files being copied. The terminal will display the names of the files as they are transferred. If a file already exists in the destination directory, it will be skipped.
Step 5: Verify the Copy
Once the copy process is complete, you can navigate to the destination directory and verify that the files have been successfully copied. You can use the ls command to list the files in the directory.
ls /home/user/backup
Congratulations! You have successfully copied all files from the source directory to the destination directory, excluding any files that were already present.
Remember, the cp command with the -u flag is a powerful tool for file transfer on Linux. It allows you to efficiently update your files without overwriting existing data.
| Command | Description |
|---|---|
cd [directory] |
Change directory to the specified path. |
cp -ru [source] [destination] |
Copy files from the source directory to the destination directory, excluding existing files. |
ls [directory] |
List files in the specified directory. |