hello guys welcome to the next video on Linux command line tutorial for beginners in this video we will see how we can use CP command in Linux CP command is used to copy files and directories in Linux so let's see how we can use it so just open your terminal by pressing ctrl alt T and let's see what are the options we have for CP command so for giving CP command you use CP and then options and then you can write the source so you just need to give the name of your source and then the destination ok so CP and then comes two options for example - i or - v or other options and then you give the name or location of your source file or directory and then you need to give the name of the destination where you want to copy the source right so let's get started first of all I will CD to my desktop and in here in the desktop you can already see that I have two directories and a file so for example I want to copy a file into a new file so what I can do is I can just write CP and then I can just write the name of my file 1 which I want to copy and then I want to copy this file into a new file called file - dot txt which doesn't really exist so what the CP command is going to do is if this file doesn't exist is going to create the new file and then copy the content of file 1 to file 2 so let's see what happens when we give this command so you can see the new file is created and the content of file 1 will be copied to file - so let's cat for example file 1 first and you can see the content of it then let's get the content of file - and you can see the same content right let me clear the terminal now the second thing we can do here is we can copy a file to a directory so for example I can just use CP and then I can just write the name of the file and for example I want to copy it to a directory one which is empty right now so let me show you first of all before giving this command the content of the directory 1 so I will just use LS and then directory name right and press enter and it shows nothing that means directory is empty right so now I will do CP and then the name of the file for example I want to copy file 1 and then the name of the directory which is my destination where I want to save my file right and I will press Enter and it's going to copy this file to direct you 1 and less to Alice directory 1 once again and you can see a file 1 is now existing inside directory 1 right so it has copied the file 1 into the directory 1 for example I want to copy a file to also into the directory - what I can do is I can just write file 1 which is already copied if you want to you know copy the multiple files you can just do it something like this so you can give the multiple sources here and then at the end you can give the name of the destination so this time I am going to give the directory to for example to copy to it so I will just press ENTER and then I will Alice to directory tools and you can see these two files are transferred to the directory - right now for example I want to transfer these two files to directory one but we already know that file 1 is already existing inside the directory 1 and for example we don't want to overwrite the file 1 which is inside directory 1 so this command is going to overwrite the file 1 because it's already existing in the you know directory 1 so to avoid the over writing what you can do is you can give this command or flag which is minus I which stands for interactive which ask before overwriting ok so when you press ENTER it says CP overwrite directive one file one dot text so it it will ask you the question and if you give Y here then it's going to overwrite your file 1 and if you give n here then it's going to not overwrite it right so we are going to give n so it's going to only copy file 2 and it's not going to overwrite file 1 ok so you can use I for the interactive interface right now for example you can you know give the absolute path here or the relative path right for example I will see D to my directory 1 here and see see D 2 D 1 and that's 2 LS here and for example we want to give the CP command from here so the file 2 and file 1 exist in the desktop not the directory 1 and right now we are in dir 1 directory so we can just go 1 you know step back or 1 folder above by using these do two dots as you already know and you can give the name of the file for example file 1 dot txt and then once again dot dot and then this time file 2 dot txt right and then for example you want to copy it in the current directory you are already in you can use this dot 2 show or indicate that this is our current directory or destination is our current directory so press ENTER and it's going to copy these two files to the directory one and we have not given - i flag here so it will overwrite these two files okay now this dot here means the current directory so whenever you do LS - a is going to show you dot and then dot dot and then file1 and file2 dot txt so this dot means the current directory so if you give this dot it means the current directory you can also give this command something like there one something like this but you are already in the directory right so you can give the absolute paths of the directories for example right so for example home and then your username and then the desktop which you are in so you are in the desktop directory here right and then dir one directory one okay so you can give this kind of absolute path also or dot also or this kind of relative path also to copy your files now there is one more interesting thing I want to show here and first let me clear the terminal and for example I want to copy the directory 1 to our directory 3 which doesn't really exist so what I can do here so I can do something like the CP and then dir 1 and let me go to the desktop first of all so I will just do CD dot dot so I will be in the desktop and then I will just to see P and then dir 1 and then I will give the name of my directory which doesn't really exist which is directory tree right and let's press ENTER and let's see happens and it's going to give error and it says omitting directory dir one and why it's doing this because this directory contains some files and then it's not able to copy this directory to directory tree so in order to copy our directory which contains a file or files you can give this command which is minus capital R or smaller I think both are same but mostly we use capital R which is for recursive copying so press Enter and then you can see dir 3 is created and we can list out the content of dir 3 and you can see the content of directory 1 is transferred to directory 3 now you may ask why this directive 1 is not inside directory tree right because CP command for example when you use for files it will transfer the file inside the directory 3 right so whenever you give some command something like this and if the destination doesn't exist then what is going to do is is going to transfer the content of the directory or source directory to the destination directory and create this directory first and then transfer the content now once again when you give the same command if the directory already exists ok so once this direct you already exist and you give the same command let's see what happens and I'm going to just give I not i but weak flag here for verbose and you already know what this means is and I'm going to press ENTER and you can see what happens here so what's happening here is is transferring directory 1 to directory 3 and then it's trying and transferring the file inside the directory 1 to directory 3 and we are going to give the same command LS directly three here and now you can see directed three is transferred inside the directory that if you one is transferred inside the directory three right so if the file already exists it's going to you know copy this directory one inside the die directly three if file doesn't exist or directory doesn't exist then it's going to just copy the content of the source to the destination okay so this is how you can use a CP command and for more detail you have this command man CP for seeing you know all the options which you can use with the CP command and when you press Q it's going to quit so I hope you've enjoyed this video please rate comment subscribe and bye for now
Video Description: Linux Command Line Tutorial For Beginners 8 - cp command for Software Development 2023 is part of Complete Linux Course: Become a Linux Professional preparation.
The notes and questions for Linux Command Line Tutorial For Beginners 8 - cp command have been prepared according to the Software Development exam syllabus.
Information about Linux Command Line Tutorial For Beginners 8 - cp command covers all important topics for Software Development 2023 Exam.
Find important definitions, questions, notes, meanings, examples, exercises and tests below for Linux Command Line Tutorial For Beginners 8 - cp command.
Video Lecture & Questions for Linux Command Line Tutorial For Beginners 8 - cp command Video Lecture | Complete Linux Course: Become a Linux Professional - Software Development - Software Development full syllabus preparation | Free video for Software Development exam to prepare for Complete Linux Course: Become a Linux Professional.
Information about Linux Command Line Tutorial For Beginners 8 - cp command
Here you can find the meaning of Linux Command Line Tutorial For Beginners 8 - cp command defined & explained in the simplest way possible.
Besides explaining types of Linux Command Line Tutorial For Beginners 8 - cp command theory, EduRev gives you an ample number of questions to practice Linux Command Line Tutorial For Beginners 8 - cp command tests,
examples and also practice Software Development tests.