Copying and moving files on Windows is quite straightforward, but executing similar tasks on the Linux operating system is quite different. You will need to use commands. To move, copy, and delete files on Linux, you can use the corresponding commands: mv, cp, and rm.
Moving, Copying, and Deleting Files on Linux
1. Command 'mv': Move or Rename Files
The 'mv' command enables you to move files from one directory to another on Linux. Additionally, this command allows you to rename files (there isn't a separate rename command).
Basic command structure:
mv joe_expenses JOE1_expenses
In this scenario, if JOE1_expenses doesn't exist, it will be created with the exact content of joe_expenses, and joe_expenses will disappear.
If JOE1_expenses already exists, its content will be replaced with joe_expenses (joe_expenses will still disappear).
Additional Options
Options for mv include:
-i abbreviation for interactive, prompts you to confirm if an existing file needs to be overwritten.
-f abbreviation for force, overwrites all interactions and executes the mv command without providing any feedback.
-v abbreviation for verbose, displays the files being moved from this directory to another.
2. Command 'cp': Copying and Duplicating Files
Here's a basic example demonstrating the use of the 'cp' command to copy files on Linux (keeping the original files intact and creating duplicates):
cp joe_expenses cashflow
In this example, it copies the file joe_expenses into the cashflow directory within the login directory.
Additional Options
Additional options for the 'cp' command are akin to those of the 'mv' command:
-i stands for interactive, requiring confirmation if an existing file needs to be overwritten during the copy process.
-r stands for recursive, copying all subdirectories and files within a specified directory, preserving the tree structure.
-v stands for verbose, displaying the files being copied. For example:
The command cp joe_expenses cath expenses cashflow copies both files simultaneously.
3. Command 'rm': Deleting Files
To delete files on Linux, you use the 'rm (remove)' command:
rm joe_expenses will permanently remove the file joe_expenses.
The command above will permanently erase the joe_expenses file.
Additional options:
Additional options for the 'rm' command include i (interactive), -f (force), -v (verbose), and -r (recursive).
Similar to the other commands, you can use the 'rm' command to delete multiple files at once.
Use the following command to delete both files joe_expenses and cath_expenses simultaneously.
This command erases both files at once.
Employ the wildcard character: '*'.
The command: rm *_expenses
This will permanently delete files joe_expenses, cath_expenses, mike_expenses, and robin_expenses.
Similarly, if you want to wipe out everything you copied into the cashflow directory above, use the command:
rm -r cashflow
Cautionary Commands
When dealing with these commands, it is advisable to use the -i (interactive) option. This allows users to detect regrettable errors.
Similarly, exercise caution when using the -f (force) or -r (recursive) options, especially if employing wildcard characters like '*' to apply multiple commands at once.
Be wary of the -r option. Avoid using the command:
rm -r *
Executing the command will completely erase all your existing files and directories.
By using the move (mv), copy (cp), and remove (rm) commands to manipulate files on Linux, you can handle files and directories more quickly and efficiently. After learning how to manage files on Linux, you can explore how to share two files between a Windows and Linux computer to enhance your file management skills, sharing files, and using your Linux computer effectively. Wishing you all success.
