commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage.
This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed.
find -L ./ -type l -delete
And then removing empty directories
find ./ -type d -exec rmdir 2>/dev/null {} \;
**Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)
There are 6 alternatives - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.
Holy crap, that's compicated.
If the src and dest are on the same filesystem (and you're on a *nix box), you may as well use hard links. Your command is reduced to:
cp -al src destRather than dangling symlinks, which can also be found using the "symlinks" command, you will end up with files with a hard-link count of 1.
find src -type f -links 1 -deleteFinally you can tidy the empty directory command:
find . -depth -type d ! -name . -exec rmdir --ignore-fail-on-non-empty {} \;This version will remove deep, but empty trees, and it won't complain about non-empty dirs.
Er, .. well I'll take that as a compliment :)
But, in all truthfullness, I think it is simple. find just branches into two (if/else) for dirs and files and either makes a directory or makes a symlink to the file.
Relatively, however, I guess yours wins in terms of complexity. But hard links might be a tad little more unsafe IMO considering I'm backing up stuff..
If you're trying to back up data, this is very much the wrong way to do it.
Symlinks are NOT a backup. All they do is point to a file. If that file is changed, the symlink reflects that. Try this:
echo foo>file;ln -s file symlink;cat file;echo whoops>file;cat symlinkThis creates a file, symlinks it, edits the file, and changed your "backup".
Hard links aren't safe either. do the same thing, only, you have to look harder to find out it's a link.
echo foo>file;ln file hardlink;cat file;echo whoops>file;cat hardlinkThe only way to back up the data is to actually copy it elsewhere.
If you want to back up and save space, then rsync is your friend. It has some parameters that will compare to previous backups, and copy any changed files since the last backup, and hard link the rest. This way, you can delete any backup you want, and all others are unaffected. I can't tell you what they are, but google will help out:
http://www.google.com/search?q=rsync+incremental+backup
You may also be interested in Flyback, http://flyback-project.org/ , which is a gui wrapper over rsync.
Good luck!
OP mentioned "dropbox", I think that copies the stuff to the server.
I am interested in expanding this idea to re-point the symlinks to other locations if the information has moved. it won't be foolproof but something that "finds" and repoints the link. Only ways I can think of doing this involve long scripts, so oneliners would be apprecaited if anyone can think of one.