QueHow

A How-To and wiki Blog

  • Operating System
    • Windows
      • Windows 10
      • Windows 7
    • Linux
  • Software
    • Application Software
    • Microsoft Office
      • Outlook
      • Word
      • PowerPoint
  • Internet
    • Browsers
      • Mozilla Firefox
      • Google Chrome
    • CMS
    • Tips & Tricks
  • Website
    • ecommerce
    • Google
    • Social Networking
    • General Websites
  • Mobile
  • Email
    • Gmail
  • Wiki

How to Copy and Move Files & Directories in Ubuntu

By Neha T Leave a Comment

Have you ever wondered how cinched it can be to copy and move Files & Directories in Ubuntu? In this era of technology, people don’t want to write commands rather they prefer GUI for that. But, there are certain times when GUI fails to load. At that instant, if you know how to play with the command-line Interface, then it is fabulous.

Through this tutorial, you will learn to Copy and Move Files & Directories in Ubuntu by performing the steps as explained below.

Steps to Copy and Move Files & Directories in Ubuntu

To copy a file within the same Directory

Step 1: In order to copy a content of one file to another within a same directory, simply write “sudo cp filename1 filename2”, sudo is used to have root permissions.

For an example, If want to copy a filename project.txt to another one i.e. project2.txt. So, in this case, the command will be “sudo cp project.txt project2.txt”.

How-to-copy-and-move-files-and-directory-in-ubuntu-step1

Step 2: To list the changes use “ls” command and then press enter.

How-to-copy-and-move-files-and-directory-in-ubuntu-step2

Step 3: You may have noticed that there is no output shown using the above command. To know which file/directory is copied, use the command “vi” in which“v” shows the output and “i” is for the interactive view.

To copy a file from another directory to a directory in which you’re currently in, use “cp -vi ~/Desktop/hello.txt ~/hello2.txt”. Here, I have copied “hello.txt” file stored under the “Desktop” directory, to a home directory, that’s why used “~” sign before giving the file a new name.

How-to-copy-and-move-files-and-directory-in-ubuntu-step3

Step 4: As an output, the process is shown in the figure below.

How-to-copy-and-move-files-and-directory-in-ubuntu-step4

Step 5: Use “ls” again to check whether the file is copied or not.

It’s done, check out in the figure below.

How-to-copy-and-move-files-and-directory-in-ubuntu-step5

Step 6: Suppose, you had accidentally written a command, to copy the files and then you realized, no it’s not what you want to do. Therefore, to be on safer side, always use “-i”, which stands for interactive, that will ask you whether to overwrite the contents of the files or not.

Like, I wrote “cp -i project2.txt hello2.txt” and pressed enter.

How-to-copy-and-move-files-and-directory-in-ubuntu-step6

Step 7: See in the figure, the bash shell asking to overwrite the contents of hello2.txt. Type “y” or “n”.

I typed “n” for no, as in the previous command hello2.txt is already copied & I don’t want to overwrite it.

How-to-copy-and-move-files-and-directory-in-ubuntu-step7

To move a file:

Step 8: The “mv” command is used to move a file from a source to destination, whichever you specify. Meanwhile, used for renaming the file, if you have only mentioned a filename and, not a particular path. The shell will rename a file, in this case.

Let’s try it. Type “mv hello2.txt newhello.txt”. Hello2.txt file is already available in my home directory, that’s why tweaked with it. You can perform the same with the file you want.

To look at the changes, type“ls” command again. Now, you’ll see that “hello2.txt” is no more available,because it is now renamed as “newhello.txt”.

How-to-copy-and-move-files-and-directory-in-ubuntu-step8

Step 9: To change the directory name, for an example: if you need to change the Music directory with another name then type“mv Music/ MusicExamples/” where “/” is explicitly used to denote that it is a directory.

How-to-copy-and-move-files-and-directory-in-ubuntu-step9

Step 10: Always use “ls”command after performing a step for a clear view. You can see that the name changes to Music Examples.

How-to-copy-and-move-files-and-directory-in-ubuntu-step10

To copy the sub-directories as well:

Step 11: Actually “cp” command doesn’t copy the sub-directories of a directory, if exits. For copying the sub-directories, we use recursive flag, use “-r” with “cp” command that will copy (recursively) all the sub-directories to the desired place.For that type: “cp -r MusicExamples/ Music/” and press enter.

The same can be applied within the files as well.

How-to-copy-and-move-files-and-directory-in-ubuntu-step11

Step 12: To ensure both of the Directories, have the same content, in a single step. Execute the command “ls MusicExamples/ Music”, this command will show you the contents of both.

In this scenario, no file is shown as in my system there are no music files, within the directory.

How-to-copy-and-move-files-and-directory-in-ubuntu-step12

To copy a Directory:

Step 13: I have created a sample directory named “friends” under the list directory which is actually located in my home directory. I am going to show you how to copy a directory from one place to another with the same content.

For that type: “cp -r ~/lists/friends ~/Public”, this command will copy all the content of a friends directory without leaving a bit of data to the “Public” directory. To deal with the Directories in Linux, you must use “-r”, otherwise the shell will throw an error called omitting directory.

How-to-copy-and-move-files-and-directory-in-ubuntu-step13

Step 14: To check it out, type: “ls Public” command that will list the files and directories under the “Public”.

How-to-copy-and-move-files-and-directory-in-ubuntu-step14

These are all the tweaks, you can perform in your system as well, to have a hands-on experience with it. It’s better to learn things practically, as if you would mistakenly insert/left a single white space may cause an error in the output.

You Might Also Like:

how-to-hide-and-show-files-and-folders-in-ubuntuHow to Hide & Show Files and Folders in Ubuntu How we can Change the Directory in Ubuntu How to Create a Text File using Command Line in Ubuntu 14.04 ( 2 Methods) how-to-install-true-type-fonts-in-ubuntuHow to Install TrueType Fonts in Ubuntu How-to-install-oracle-java-in-ubuntuHow to Download and Install Oracle Java in Ubuntu Default ThumbnailHow to batch rename files in Ubuntu 14.04 How to create a zip file using terminal in Ubuntu 14.04 How to prevent others from accessing your home directory in Ubuntu 14.04

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Viewed

  • How to Install and Use TELNET in Ubuntu
  • How to install Hindi fonts in MS Word
  • How to Change a File Extension in Windows 10?
  • How to create a flipkart account in 3 simple steps
  • How to Change Monitor Refresh Rate in Windows 10?
  • How to install IIS on Windows 10
  • How to Insert Clickable Checkbox in MS Word 2016?
  • How to Set Auto Reply in Outlook 2016?
  • How to Login as Administrator in Windows 10?
  • How to Check RAM Size and System Type in Windows 10?

Recent Additions

  • How to Add Hyperlink to Another Sheet in Excel?
  • How to Add and Remove Watermark in Excel
  • How to use Relative and Absolute Cell Reference in Excel?
  • How to Enable and Disable Scroll Lock in Excel?
  • How to Use INDEX and MATCH Functions in Excel?
  • How to Make Bar Graph in Excel?
  • How to Count Duplicate Values in Excel?
  • How to Wrap Text in Excel?
  • How to Round off Numbers in Excel?
  • How to Create a Bell Curve in Excel?

Related Searches

  • How to use MS Office 2003 Menus in MS Office 2007
  • How to print multiple pages per sheet in adobe reader
  • How to recover your deleted gmail account
  • How to Install VMware Workstation in Windows 7 ?
  • How to change your password in Snapdeal

Copyright © 2023 · QueHow · Contact Us