Ubuntu Copy File Command

I‘m a new Ubuntu Linux user. This seems like a newbie question, but I can not seem to find examples to copy files on Ubuntu. How do I copy file to another directory on Ubuntu Linux using command line terminal application? How can I copy files via terminal on Ubuntu Linux desktop?

You need to use cp command to copy file to another directory or external usb disk. The command line syntax is as follows to copy files via terminal:[donotprint]
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 10m

cp old_name new_name


cp [options] old_name new_name


cp source dest


cp /path/to/source /path/to/dest/directory/

Examples: Copy file1.txt to /tmp directory

Open the Terminal and type the following command in the current directory to copy a file called file1.txt with the same name into /tmp/ directory:

cp file1.txt /tmp/

Use ls command to verify new files:

ls /tmp/
ls -l /tmp/
ls -l /tmp/file1.txt

You can copy multiple files into another directory. In this example, copy the files called foo.txt, bar.doc, resume.pdf into a directory called /media/backup/

cp  foo.txt bar.doc resume.pdf /media/backup/

Cp command can explain what is being done with -v option:

cp  -v foo.txt bar.doc resume.pdf /media/backup/

Sample session from all cp commands featured in this tutorials:

Animated gif: Ubuntu Linux copy files via terminal using cp command demo

Ubuntu make a backup of each existing destination file

In this example, copy file named birthday_party.avi to /media/usbpen/ and make a backup of each existing destination file:

cp -b birthday_party.avi /media/usbpen/

Copy ~/Documents/ folder to /media/usbpen/

Pass the -r (recursive) option to cp command. In this example, make a copy of an existing directory called ~/Documents/, inclusive of all it contents (i.e., files, subdirectories, their subdirectories, etc.), to directory called /media/usbpen/:

cp -r ~/Documents/ /media/usbpen/

Copy files interactively

Pass the -i optipn to cp command to prompts the user to the screen before copying a file that would overwrite an existing file:

cp -i file1.txt /tmp/

If you do not wish to overwrite an existing file i.e. overrides a previous -i option, try:

cp -n file1.txt /tmp/

Copy all files in a directory to another directory by using the star wildcard

To copy all files from ~/Pictures/ to /nfs/backups/pics/ directory, enter:

cp ~/Pictures/* /nfs/backups/pics/

In this example, copy all of the files in the current directory that have the filename extension .py into another existing directory called /nfs/backups/python/:

cp *.py /nfs/backups/python

Dealing with permission denied error

If you try to copy files to /root/ or any other system areas, you will see an error that read as follows:

cp backdoor3.c /usr/
cp: /usr/backdoor3.c: Permission denied

Use the sudo command to copy files when you need superuser privileges on Ubuntu Linux:

sudo cp backdoor3.c /usr/

Tip: Searching for commands without knowing their exact names

You can use apropos command to displays a list of all topics in the built-in user manual that are related to the subject. The syntax is:

apropos query
apropos query | less
apropos keywords | grep 'something'

In this example, get the list of editing programs/commands that are available on a system:

apropos editor
apropos editor | less

Sample outputs:

ed                   (1)  - text editor
ex                   (1p)  - text editor
mcedit               (1)  - Internal file editor of GNU Midnight Commander
nano                 (1)  - Nano's ANOther editor, an enhanced free Pico clone
psed                 (1)  - a stream editor
sed                  (1p)  - stream editor
sed                  (1)  - stream editor for filtering and transforming text
vi                   (1p)  - screen-oriented (visual) display editor
vim                  (1)  - Vi IMproved, a programmers text editor

Finally, use whatis and man command to obtain information about the mcedit or vi command that apropos provides:

whatis mcedit
whatis vi
man vi
man mcedit

And there you have it, cp command that copies files and directories on Ubuntu based systems. I strongly suggest that your read cp command man page or see our cp command examples page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 14 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
14 comments… add one
  • Sri Feb 19, 2014 @ 17:44

    No offense, but this is so noobish information. It is like posting instructions on how to walk. Only post advanced stuff, or I am going to remove your rss from my daily reads.

    • Jim Brashear Oct 1, 2014 @ 1:38

      It was rather helpful to some of us with less knowledge of Linux terminal than yourself sir.

    • Mike Nov 5, 2015 @ 17:46

      Linux and Unix tutorials for NEW and seasoned sysadmin.

  • julian67 Feb 19, 2014 @ 18:39

    I think noobie questions are OK. Everyone has to start somewhere and even experienced users can have surprising gaps in their knowledge – probably not many who don’t know cp inside out though :-)

    Anyway imo a better answer to such a noob question might be to describe the command `apropos`, and show a small section of a sample output:

    $ apropos copy
    Clone (3pm) – recursively copy Perl datatypes
    asn1_copy_node (3) – API function
    bcopy (3) – copy byte sequence
    copysign (3) – copy sign of a number
    copysignf (3) – copy sign of a number
    copysignl (3) – copy sign of a number
    cow-shell (1) – Start a copy-on-write session and invoke a shell.
    cp (1) – copy files and directories
    cpgr (8) – copy with locking the given file to the password or group file
    cpio (1) – copy files to and from archives
    cppw (8) – copy with locking the given file to the password or group file

    etc etc…

    apropos is a great discovery tool for people new to a unix-like OS or new to the command line and is also useful for experienced users. It doesn’t get mentioned very often but in conjunction with man and info pages and a little curiosity it is a great tool for exploring what your system contains and can offer you.

    • 🐧 Nix Craft Feb 19, 2014 @ 18:52

      Excellent suggestion. The faq has been updated to include your tip. I appreciate your feedback and post.

  • T.Mini Feb 19, 2014 @ 18:58

    @julian67: Yup, give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.

    @Sri: Please unsubscribe. You are not adding anything to the discussion by behaving like this.

  • julian67 Feb 19, 2014 @ 19:19

    …and if you’re really sharp you can then direct him to a fishing tackle retailer and take commission on the sales :-)

  • Justin Feb 20, 2014 @ 12:02

    How did you create the animated gif?

  • ae Apr 3, 2014 @ 16:43

    good info., the -r was a lifesaver for me.

  • Lee Erickson May 22, 2014 @ 17:12

    Thanks for the introductory information. I need a little more.
    Regarding, “to copy file to another directory or external usb disk”
    It is copying to the USB disk that is opaque to me. I can understand how to copy a file from a terminal prompt it is learning the name of the USB disk that I cannot overcome.
    I cannot figure out what the “new_name” would be for the USB disk.

    From the Ubuntu GUI file manager I can try to drag and drop but get an error which when expanded says permission denied. So I need a way to give the GUI file manager “sudo” and my PW but see no way to do so.

    • Lee Erickson May 22, 2014 @ 17:32

      While I was not able to overcome my problem with the GUI drag and drop. I copied from the terminal. First to find the USB drive navigate to /media and then do ls.
      The result was a long or very long human unfriendly string which even with paper and pen I doubt I could write and then type with out several tries. Lets prentend the first few letters of which were “foo….”
      But I typed “sudo cp source_file /media.foo” and pressed the tab key to auto fill.
      Then press enter and gave it my PW and success.

      It was figuring out that a USB disk is “media” and not a “dev” that I had to overcome.

      Would still love to know how to do this with the GUI file manager.

  • Mamoun Dec 24, 2014 @ 17:51

    Thanks for information
    I am wondering if there is a command to make a backup of my software.
    On Linux or unixs systems
    I have MRI scanner and I want make backup software on mod disk

  • Michelle Jul 22, 2016 @ 23:02

    How can I copy a file to “here”
    cp source here
    I am currently in my destination directory

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum