Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I disable permanently/temporarily copying of files in background? Often while copying many files to usb drive, the message is displayed as 'copying finished'. But when I try to safely remove usb drive, a message pops up like saying 'finishing job... do not unplug usb drive'. And I have to keep looking at the circling animation waiting for it to finish. Some time it takes too long and it is difficult to know whether it hanged or actually doing job in background? Same-thing while copying in terminal too - no difference.
Its same in most of the linux distros I've tried. How do I solve this?
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
When you're copying files to a flash drive or other drive (including your hard drive), they're not actually copied directly to the device byte-by-byte: a buffer is filled and when that's full it's flushed to the device. You don't actually write right away, stuff can sit there in memory for some time -- memory is fast, devices are a lot slower.
Here's a trick: if you're doing a large amount of copying, open a terminal and simply type
Code:
sync;sync;sync
and hit the enter key.
That will flush the buffer to the device. You'll notice that there will be a delay while the buffer is written to the device (lights will flash, rain will fall, it'll snow) and, if you repeat the sync it will return almost immediately.
Slow devices (like flash drives) will take a while, a hard drive will take less time but there will be a noticeable delay in either case while the buffer(s) are being written.
When you're copying files to a flash drive or other drive (including your hard drive), they're not actually copied directly to the device byte-by-byte: a buffer is filled and when that's full it's flushed to the device. You don't actually write right away, stuff can sit there in memory for some time -- memory is fast, devices are a lot slower.
Here's a trick: if you're doing a large amount of copying, open a terminal and simply type
Code:
sync;sync;sync
and hit the enter key.
That will flush the buffer to the device. You'll notice that there will be a delay while the buffer is written to the device (lights will flash, rain will fall, it'll snow) and, if you repeat the sync it will return almost immediately.
Slow devices (like flash drives) will take a while, a hard drive will take less time but there will be a noticeable delay in either case while the buffer(s) are being written.
Hope this helps some.
Sync itself is only a suggestion... The kernel doesn't have to do anything in response.
The only way to ensure that buffers are written to a mounted device is to dismount it. That and that alone will ensure the buffers are on disk. If you are copying to a raw device, the only sure way to know if it is finished is if there is an indicator on the device itself.
Normal I/O to a device will be done in about a millisecond. Only if the system is really busy (or the device is slow and there is a lot of data) will writes take longer. That is why dismounting a filesystem is the only way to ensure the writes- a umount has to wait until the filesystem blocks are all updated before the filesystem can be marked as dismounted and removed from the table.
On one system (it wasn't linux though) sync itself did nothing except exit. Its use in scripts was to cause a minor timing delay (caused by loading and executing the code) which gave the system more time to flush buffers anyway, and it made script compatibility easier.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Well, a quick look at
Code:
info coreutils 'sync invocation'
indicates
Quote:
`sync' writes any data buffered in memory out to disk. This can
include (but is not limited to) modified superblocks, modified inodes,
and delayed reads and writes. This must be implemented by the kernel;
The `sync' program does nothing but exercise the `sync' system call.
The kernel keeps data in memory to avoid doing (relatively slow) disk
reads and writes. This improves performance, but if the computer
crashes, data may be lost or the file system corrupted as a result.
The `sync' command ensures everything in memory is written to disk.
Any arguments are ignored, except for a lone `--help' or `--version'
(*note Common options:.
An exit status of zero indicates success, and a nonzero value
indicates failure.
Unmounting will, of course, flush the buffers and update the file system. However, because the sync utility does what it does, execute the sync system call, it seems a little quicker and easier to use rather than unmounting and potentially remounting a device.
The `sync' command ensures everything in memory is written to disk.
Note it doesn't say immediately.
I always rely on umount.
When blktrace first became available (in beta) I had lots of fun playing with disk I/O - tools like this are quite educational. Fortunately as they develop, better add-ons arrive which make them easier to use.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.