Copying and Moving Files - Command Line Tutorial
Introduction
Welcome to the tutorial on copying and moving files using the command line. This guide will help you understand the basic commands needed to manage files effectively. By the end of this tutorial, you will be able to copy and move files and directories with ease.
Copying Files
To copy files in the command line, you can use the cp command. The syntax for the cp command is as follows:
Here, [source] is the file you want to copy, and [destination] is the location where you want to copy the file.
Example
Copying a file named file1.txt to a directory named backup:
This command copies file1.txt into the backup directory.
Copying Directories
To copy a directory and its contents, you need to use the -r (recursive) option with the cp command:
Example
Copying a directory named docs to a directory named backup:
This command copies the docs directory and all its contents into the backup directory.
Moving Files
To move files, you use the mv command. The syntax for the mv command is similar to cp:
Here, [source] is the file you want to move, and [destination] is the location where you want to move the file.
Example
Moving a file named file1.txt to a directory named backup:
This command moves file1.txt into the backup directory.
Moving Directories
The mv command can also be used to move directories. The syntax remains the same:
Example
Moving a directory named docs to a directory named backup:
This command moves the docs directory and all its contents into the backup directory.
Renaming Files and Directories
The mv command can also be used to rename files and directories. The syntax is:
Example
Renaming a file from oldname.txt to newname.txt:
This command renames oldname.txt to newname.txt.
Summary
In this tutorial, we covered the basic commands for copying and moving files and directories using the command line. The cp command is used for copying files and directories, while the mv command is used for moving and renaming them. Practice these commands to enhance your command line proficiency.