LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2020, 08:25 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
copy files to USB media...


Hello All

I copied one .iso file of size 5 GiB to Pen drive, and after the process completed, I entered the 'sync' command. It took several more minutes to finish the sync.

If I hadn't known about the sync command and had I pulled the USB pen drive, I would have lost the data.

So, is there a way to copy a file to USB or anywhere without using a cache buffer?

Thanks
 
Old 10-20-2020, 08:37 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by ddenial View Post
Hello All
I copied one .iso file of size 5 GiB to Pen drive, and after the process completed, I entered the 'sync' command. It took several more minutes to finish the sync. If I hadn't known about the sync command and had I pulled the USB pen drive, I would have lost the data. So, is there a way to copy a file to USB or anywhere without using a cache buffer?
Just doing a standard "Eject USB" does the same thing, so even if you didn't know about sync you would have been fine, providing you didn't just yank the drive out. And no, there isn't.
 
1 members found this post helpful.
Old 10-20-2020, 08:42 AM   #3
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by TB0ne View Post
Just doing a standard "Eject USB" does the same thing, so even if you didn't know about sync you would have been fine, providing you didn't just yank the drive out. And no, there isn't.
Sorry, I forgot to mention the copy process was in the terminal with the 'cp' command. No GUI, and was hoping for a solution in the terminal.
 
Old 10-20-2020, 09:08 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,597

Rep: Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545

The command to safely remove media is umount - it will (afaik) perform equivalent action to sync.

Note that it's umount - not unmount. Some distros do provide an unmount command, but it's not standard.

I don't know of a specific "copy then safely remove" option, but no doubt someone somewhere has created a wrapper to do that.

 
Old 10-20-2020, 09:16 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by ddenial View Post
Sorry, I forgot to mention the copy process was in the terminal with the 'cp' command. No GUI, and was hoping for a solution in the terminal.
Again, if you just yank the drive out it'll lose data. Again, there is no way to 'write' without that buffer...I'll leave it to you to consider why, and point out the difference in speeds between USB, SSD's/HDD's, etc.

As boughtonp said, umount does the sync for you...same as if you click "Eject Media" (or whatever it is on your GUI).
 
Old 10-20-2020, 07:59 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,314
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
Many, if not all, GUI file managers also include a right-click menu item to "safely remove" a removable device. If it's not safe to remove yet, the file manager normally will not allow removal.
 
Old 10-22-2020, 05:43 PM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by ddenial View Post
Hello All

If I hadn't known about the sync command and had I pulled the USB pen drive, I would have lost the data.

So, is there a way to copy a file to USB or anywhere without using a cache buffer?

Thanks
Simple answer -- No!
All writes to any device are cached and the cache is cleared when the write is complete. Reading is faster than writing so the system always uses a cache during write operations. It takes time to write large quantities of data to a flash drive and it must be complete before the drive is pulled or data corruption will occur.

Using the command "sync" will force the write to complete and the cache to clear but you have to wait for the command prompt to return which indicates the cache is clear.
The "eject" command works similarly but again you must wait for the command prompt to return.

@frankbell gives the info about the gui method. I will note that the later versions of the nautilus file manager put a progress "pie" in the upper right of the window label bar near the minimize, maximize, and close buttons that fills with color as the write proceeds and disappears when done. I believe closing the file manager which started the write/copy before it completes may also interrupt the write but have not tested that myself.
 
Old 10-22-2020, 06:49 PM   #8
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
For that reason, I have started to use rsync with --progress. Yes, to copy files to and from USB / pen drive to local drive.

Code:
rsync -av --progress <source> <destination>
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Copy files to a usb stick and automatically encrypt or encrypt files/folders and copy them to usb bmxakias Programming 8 03-14-2020 06:44 PM
[SOLVED] usb mount point used to be /media/$USER/$LABEL, now /media/usb kaz2100 Debian 2 06-29-2016 07:41 PM
Want to change how pasted files are named "(copy)," "(another copy)," "(3rd copy)" L a r r y Linux - Desktop 3 08-24-2013 03:39 PM
[SOLVED] Why does /media/cdrecorder pop up with "cd /media/ + tab" when I have /media/usb too? SharpyWarpy Fedora 6 11-22-2012 01:05 AM
Media, media, and oh yeah......media. Morbid SUSE / openSUSE 2 03-11-2007 08:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration