In Linux, the command line tool for copying files is cp
, and the command line tool for moving (or renaming) files is mv
.
To copy a file, you use the following syntax:
cp [source file] [destination]
For example, to copy a file named “file.txt” from the current directory to a directory named “documents”, you would use the following command:
cp file.txt documents/
To move a file, you use the following syntax:
mv [source file] [destination]
For example, to move a file named “file.txt” from the current directory to a directory named “documents”, you would use the following command:
mv file.txt documents/
If you want to rename the file you can use the same command but with different destination file name.
mv file.txt new_file.txt
Please note that the mv
command can also be used to move a file or a directory across different file systems or partitions.
Additionally, you can use the -r or -R option with cp
command to copy the entire folder and its content instead of just the file in it.
cp -r folder_to_copy destination
And with mv
command you can use the -t option to specify the destination folder
mv file_to_move -t destination_folder
It is a good practice to always check the destination folder and file name before executing the command to avoid any accidental deletion or overwriting of files.