How to Copy Files to USB Using Terminal

Last updated: September 23, 2022

Linux users feel empowered while performing tasks using the terminal application. So why leave the terminal when you can copy files to USB from the terminal app instead of a file explorer. This guide shows how to copy files and directories from a Linux system to a USB stick.

1. Know Where USB Mounted

Just before we begin, I am using Ubuntu 22.04 but the approach will mostly remain the same for any version and distribution.

Before we copy files, the USB stick needs to be mounted to your machine (laptop, PC, etc). Most Linux distributions mount the USB flash drive automatically to the system under the /media directory.

Insert the USB flash drive into your system. And let us find out the name of your USB drive using the fdisk command. Fdisk is used to manage hard drive and partitions in Linux.

sudo fdisk -l
show usb device name using fdisk

It will display many disks but at the last, you will find the external disks. In the above image, you can see I have a 4 GB pen drive attached to my laptop. The /dev/sdb is the name of your USB. For you, the name may be different but mostly always named as sdc, sda, etc

If there is no output of your USB flash drive try using the following command :

lsusb
show devices connected to usb buses

lusb is used to display all the connected and new devices on usb buses. As you can see in the above example I have a Transcend company's pen drive connected to the available USB port. If you see the output here and not in fdisk try reattaching or formatting your USB device using tools like Gparted.

Using lsblk command you can check the device name and its mount points. Here you can see sda mounted to /media folder.

show all devices and its mount points

2. Change to USB Mounted directory

Change the directory with the following command

cd /media
change to USB mounted directory

3. List Content Inside USB

Let's see what we have inside our Pendrive. Using the list directory command :

ls
listing contents of USB

4. Copy files to USB

Now launch a new Linux terminal and navigate to the folder you to copy files from. Linux cp command is used to transfer files from one folder to another.

I want to copy files from my home directory to the USB flash drive.

Copy single file:

sudo cp filename /media
copying a file to USB

To copy multiple files :

sudo cp -r filename1 filename2 filename /media

-r parameter is used to recursively copy content.

copying multiple files to USB

To copy a folder:

sudo cp -r foldername /media
copying a folder to USB

To copy multiple folders:

sudo cp -r folder1 folder2 foldern /media
copying multiple directories to USB

6. Verify

You can always verify that the files/folders have been copied using the ls command :

ls /media

You may also verify by its size as follows:

check USB size

I have a 4 GB USB flash drive.

Conclusion

Unlike graphical mode where you can copy and paste files, using a terminal we need to use the copy command to transfer files to a mounted USB device. Once we identified the mounted USB directory, we can easily copy the files. As mentioned all modern Linux automatically mounts the USB devices that part is also easy.

Thanks for reading, please leave your suggestions and feedback in the below comment section.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin started his career in IT in the year 2000 as a computer science instructor and worked as a Linux system engineer and senior analyst roles. Currently working in DevOps environments to increase efficiency and improve delivery time in AWS Cloud infrastructure. He is certified in RHEL, CCNA, and MCP and holds a Masters's in computer science. When in his free time love playing cricket, blogging, and listening to music.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment