commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
There must be no space between -p and the password
Sometimes when copying files from one place to another, the timestamps get lost. Maybe you forgot to add a flag to preserve timestamps in your copy command. You're sure the files are exactly the same in both locations, but the timestamps of the files in the new home are wrong and you need them to match the source.
Using this command, you will get a shell script (/tmp/retime.sh) than you can move to the new location and just execute - it will change the timestamps on all the files and directories to their previous values. Make sure you're in the right directory when you launch it, otherwise all the touch commands will create new zero-length files with those names. Since find's output includes "." it will also change the timestamp of the current directory.
Ideally rsync would be the way to handle this - since it only sends changes by default, there would be relatively little network traffic resulting. But rsync has to read the entire file contents on both sides to be sure no bytes have changed, potentially causing a huge amount of local disk I/O on each side. This could be a problem if your files are large. My approach avoids all the comparison I/O. I've seen comments that rsync with the "--size-only" and "--times" options should do this also, but it didn't seem to do what I wanted in my test. With my approach you can review/edit the output commands before running them, so you can tell exactly what will happen.
The "tee" command both displays the output on the screen for your review, AND saves it to the file /tmp/retime.sh.
Credit: got this idea from Stone's answer at http://serverfault.com/questions/344731/rsync-copying-over-timestamps-only?rq=1, and combined it into one line.
rsync will copy the source directory into destination and any subsequent run will synchronize only the changes from the source.
Do not run this command if you already have ntpd running!
This needs to run as root, for example with sudo:
sudo ntpdate pool.ntp.org && sudo hwclock --systohc && sudo hwclock --adjust
This command will fetch accurate time from NTP servers and synchronize your system clock, then it will use the system clock to synchronize your hardware clock, and will calculate the time drift.
Find all corrupted jpeg in the current directory, find a file with the same name in a source directory hierarchy and copy it over the corrupted jpeg file.
Convenient to run on a large bunch of jpeg files copied from an unsure medium.
Needs the jpeginfo tool, found in the jpeginfo package (on debian at least).