Site icon Technology and Trends

File Movement in Linux

CP utility is used to copy files and directories in Linux based Operating system. It needs two mandatory arguments along with any optional parameters. Those two arguments are the source and destination location. This command is used most frequently while automating a task using bash scripts.

Copying files from source to destination

Once this is completed, a copy of the file will be copied to the destination without deleting the original source.

~$cp <source> <Destination >:
<Source> can be file or a directory 
cp /home/user1/file1.txt /home/user2/

This will copy the file file1.txt from /home/user1/ location to /home/user2/ location

Moving/Renaming files from source to destination

If you want to move the whole file, you can use mv command. It cut and pastes the file.

~$mv <source> <Destination >:Cutting files from source to destination Or renaming a file or directory

mv /home/user1/file1.txt /home/user2/file2.txt

It will copy as well the rename the file that you want to copy.

Exit mobile version