A little quickie here. One fine day, the Foundation Website features a tip of the day that says "sudo sync".
Well, that's strange. sync command does not require sudo, does it? And it does not. In fact, if you run it as sudo, not only the OS will login as super user before executing the command, it will also write to a log file after executing the command, hence, invalidating the write buffer. So, when you use a sync command, just type sync. Don't use sudo in front of it.
Another thing to worry about is whether or not it's safe to pull the card immediately after you issue the sync command. Turns out, it used to be not. An old version was set up as asynchronous, which is a fancy way to say that it runs as a background task. Therefore, you get the shell prompt immediately even though it hasn't finished executing. So that's bad.
The good news is that sync command cannot be doubled up. So, if you execute two sync command in a row, the second one must wait for the first one to finish. The solution is simple: run it twice!
- sync; sync
And you should be fine.
One more thing. When you shutdown the device, do you need to use sync? Common sense says no. However, I always do. Better to be overly safe too many times, than a mishap happens once. Do you need to run it twice? No, you don't. The shutdown/halt command issues its own sync command, so you only need to do it once.
- sync; sudo halt
And that should do it.