Basic File Movement Commands and Syntax
In this section, we will explore the fundamental commands and syntax for moving files and directories on a Linux system.
The mv
Command
The mv
command is used to move or rename files and directories. The basic syntax is:
mv [options] source destination
Here, source
is the file or directory you want to move, and destination
is the new location or new name for the file or directory.
For example, to move a file named file.txt
from the current directory to the documents
directory, you would use the command:
mv file.txt /home/user/documents/
To rename a file, you can use the same command, but specify a new name as the destination:
mv file.txt renamed_file.txt
The cp
Command
The cp
command is used to copy files and directories. The basic syntax is:
cp [options] source destination
Here, source
is the file or directory you want to copy, and destination
is the new location for the copy.
For example, to copy a file named file.txt
from the current directory to the documents
directory, you would use the command:
cp file.txt /home/user/documents/
To create a copy of a file with a different name, you can use the same command, but specify a new name as the destination:
cp file.txt copy_of_file.txt
The rm
Command
The rm
command is used to remove files and directories. The basic syntax is:
rm [options] file(s)
Here, file(s)
is the file or directory you want to remove.
For example, to remove a file named file.txt
from the current directory, you would use the command:
rm file.txt
To remove a directory and its contents, you can use the -r
(recursive) option:
rm -r directory/
By understanding these basic file movement commands and their syntax, you will be able to effectively manage files and directories on your Linux system.