Linux allows you to work with CD/DVDs to consume content as well as install applications on your system. But sometimes you may need to simply copy files & folders to your CD/DVD. In this article, we will learn how to copy files to CD in Linux.
How to Copy Files to CD in Linux
Here are the steps to copy files to CD in Linux. Basically, we need to mount the CD/DVD on our system. Thereafter you can easily copy files & folders to and from your CD/DVD using cp command.
1. Create Folder for CD
First we need to create a folder cdrom on our system where we will mount the CD/DVD. You can use a different folder name if you want. Login as root or user with sudo privileges. Open terminal and run the following command to create directory cdrom, where we will mount the CD/DVD. If any of the following commands don’t work for you, add sudo keyword at its beginning and run it again.
$ mkdir cdrom
2. Change Folder Permissions
Next, we will change folder permissions of this folder to be able to mount our device here.
$ chmod 777 /cdrom
3. Mount CD/DVD
Run the following command to mount CD to /cdrom folder. If your CD is located at location other than /dev/cd0 then replace it in the command below.
$ mount /dev/cd0 /cdrom
4. Copy Files to CD
Let us say you want to copy file data.pdf from /home/ubuntu/projects to your CD. In this case, you can do this with cp command as shown below.
$ cp /home/ubuntu/data.pdf /cdrom
If you want to transfer multiple files, you can do so with the following command.
$ cp /home/ubuntu/data1.pdf /home/ubuntu/data1.pdf /cdrom
You can also use wildcard characters to transfer files. Here is an example to transfer all .pdf files to /cdrom.
$ cp /home/ubuntu/*.pdf /cdrom
You can also copy folders to CD. Here is an example to copy /home/ubuntu/users to your CD.
$ cp /home/ubuntu/users /cdrom
Basically, once you have mounted your CD you can treat it as another folder. Thereafter, copying files & folders to CD becomes like copying files & folders to another folder on your system.
5. Copy Files & Folders from CD
Similarly, if you want to copy files & folders from CD, you can do so using cp command. In this case, the source location will be the file location on our cd and your destination is your local system. Here is an example to transfer file data.txt from your CD to your present working directory.
$ cp /cdrom/data.txt .
Here is a command to transfer folder /data to your present working directory.
$ cp /cdrom/data .
In the above command, /cdrom is the root location of your CD. If you want to cp a file user.txt located in data folder in CD, to your present location, use the following command.
$ cp /cdrom/data/user.txt .
In fact, once you mount your CD, you can also use other file transfer command such as mv, rsync, etc the same way as we used cp. In short, the mount folder become like an alias for your CD’s root location.
6. Unmount CD
Once you have done copying files & folders to & from your CD, remember to unmount it using following command.
$ umount /cdrom
If you want to copy files & folders after you unmount your CD, you will need to mount your device once again using step #3 above.
Also read:
How to Merge Folders & Directories in Python
How to Merge Folders & Directories in Linux
How to Split Folder into Subfolders in Linux
How to Split Large File into Smaller Files
How to Sort Files into Folders in Linux
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.