This page is part of © FOTW Flags Of The World website
Removing obsolete files under Unix
Last modified: 2013-04-28 by peter hans van den muijzenberg
Keywords: fotw | mirror |
Links: FOTW homepage |
disclaimer and copyright |
write us |
Instructions as sent to the FOTW mailing list by Peter Hans van den Muijzenberg
for processing the delete list into a script that can do the removing for you. It is fairly simple;
this is the shell version for unix et alii (but check Instructions for GUI).
- Read all this until the end first, make sure you understand what you'll be doing.
While you're at it, note that the '-s (single quotes) are just for readability, you don't
actually use them anywhere.
- Open the obsolete files list in a text editor. If you have lists for more than one month,
start with the oldest and go from 1 to 10 for each one in turn.
- Immediately save the list under a different name, '<something>.sh', and save it as
text with Unix line-ends. (If your editor doesn't have that option, save however you can, and
compare the exact file sizes ('ls -l') to check that your file is one byte per line smaller.
If it isn't, try starting a new document in the editor, copying all text, and saving that one.
Check again; if still not right, keep at it until you know a solution.). Saving as a new file
also saves you from changing the original file. Sooner or later you will make a mistake. Yes, you too;
we're all human. If so, start at 1 again (or at 0).
- Remove any line not starting with '1 <', '2 <' or '3 <'.
- Replace every '\' with '/'.
- Replace every '> 1', '> 2', and '> 3' with '"'. Double quotes.
(Read Instructions for keeping deleted files to see why we have three separate endings.)
- Replace '1 <' with 'rm "flags/', replace '2 <' with 'rm "images/',
and replace '3 <' with 'rm "misc/'.
- Admire, and check, your editing job.
- Save the result (as text with Unix line-ends, or whatever other way you found). This is your script.
- Move (mv) or copy (cp) this script file to the main directory of your home copy of FOTW-ws
(i.e., the place where you have the folders flags/, images/, and misc/).
- In that directory, execute the script with a shell of your choice (sh, csh, bash, ksh, etc.).
And that's it.
You might, however, want to keep the removed obsolete files (especially since this is from the shell,
where removed files are really gone, not just moved to a trash can). To keep the files, you can use
these steps below instead of the steps above with the same number:
- Replace '> 1' with '" obsolete/flags', '> 2' with '"
obsolete/images', and '> 3' with '" obsolete/misc'.
(Mind the starting double quote each time!)
- Replace '1 <' with 'mv "flags/', replace '2 <' with 'mv "images/',
and replace '3 <' with 'mv "misc/'.
- If this is the first time you're moving files, write the following line at the top of the list:
'mkdir obsolete obsolete/flags obsolete/images obsolete/misc'.
(It won't hurt if you if you do this step again, but the only effect will be to generate
error messages before continuing.)
Doing it this way, you'll move obsolete files to /obsolete/, at the same level as /flags/ etc.,
all neatly in their own subdirectories. Here the obsoleted files will remain until you really remove them,
or until FotW obsoletes a file with the exact same file name.
The above is intended for shell use. Doing the same thing using a GUI depends somewhat on your set-up.
You'll need these steps:
- Add as the very first line of the file a text like '#!/bin/sh'.
But if you find step 10 doesn't do anything, try '#!/usr/bin/sh' instead.
And if that doesn't work, try both with different shells instead of sh: bash, csh, bsh, ksh, ... .
- Now that you have a copy in the right location, change the file permission
to allow execution - probably: right-click / Properties / Permissions / Executable, or a similar sequence
- and once you've done so, double click. If you're sure it doesn't do anything, and you checked
it wasn't merely too fast to be noticed, go back to step 7 and try a different option.
This is intended to work correctly, and feedback to improve it is appreciated. However, you yourself are
the one doing this - don't blame me if things go wrong, and feel proud if things go well.