To copy files in Linux, you can use the cp
command. Here are the steps:
Open a terminal window.
Type
cp
followed by a space and the name of the file that you want to copy. For example, to copy a file calledfile1.txt
, type:
bashcp file1.txt
- Type a space and the name of the new file or directory that you want to create. For example, to create a copy of
file1.txt
calledfile2.txt
, type:
bashcp file1.txt file2.txt
Press Enter.
If the file copy is successful, the terminal will not display any output. To confirm that the file has been copied, you can use the
ls
command to list the files in the directory.If you want to copy a directory and its contents, you can use the
-r
option with thecp
command. For example, to copy a directory calledmydir
, type:
bashcp -r mydir newdir
- This will create a new directory called
newdir
with the contents ofmydir
inside it.
Note that Linux is case sensitive, so make sure that you type the file and directory names exactly as they appear, including any capitalization or punctuation. Also, if a file with the same name already exists in the destination directory, the cp
command will overwrite it without warning. To avoid accidentally overwriting files, you can use the -i
option to prompt before overwriting existing files:
bashcp -i file1.txt file2.txt
Comments
Post a Comment