Is laziness my cause or painful dislike for harvesters, but I somehow didn’t have a relationship with big fat satisfied IDEs. I am satisfied with the simple tube Geany and several self-written scripts, the number of which is growing as needed.
On the one hand, the disadvantages are obvious - all these scripts often repeat the functionality of large development environments; bicycles - to the masses. But on the other hand, I get exactly what is needed and convenient to me. And, then, it turns out that unixing is done: it took you to drive a nail - you took a hammer, and you did not hire a construction crane with a brigade of workers and a foreman.

I decided to try writing some of these scripts here. Maybe someone will come in handy (and you can always sharpen one of them). If not - swear in the comments, I will consider. So.
Search for orphans (ds-findorphaned)
When working on more or less large projects, no matter how we were pedants, sometimes a decent amount of file garbage accumulates. Pictures, CSS, temporary versions. Of course, all this needs to be organized in one way or another - by name, label, location - whatever. But in the heat of creativity about something so forget. It weighs, sort of, a bit, but ... sloppy. Sometimes you want to clean the project, and for this you need to find this garbage among
other garbage necessary files.
One of the signs of the need for a file is its mention in other files. In other necessary files. All kinds of inclusions, the paths to the pictures in CSS and so on. Immediately you need to make a reservation that this is not the only sign. First, the desired file may not be mentioned in others. Secondly, it may be mentioned in others, but these others are not needed by themselves. But. Still, if the file is not mentioned anywhere else, it makes sense to pay attention to it.
')
Actually, to search for such single files, I wrote a small script (Perl, CLI -
description ,
github ). It's simple. The script keys indicate:
-d
- Directory with files that you want to check for orphanhood. A separate key, -r
specifies a recursive search in this directory.-f
- Mask (regular expression) of file names that you want to check for orphanhood.-D
- Directory with files in which you are looking for reference to the above specified orphan files. Another separate -R
key is a recursive search in this directory.-F
- Mask (regular expression) of file names in which reference to the above specified orphan files is searched.
Well, three auxiliary key:
-v
- Display additional summary information and sentences found orphan files can be deleted. Without a key, the script simply lists these files with full paths, line by line to file.-e
- With this key, you can specify the specific encoding of the analyzed files in case “Enca” (which is unlikely) cannot cope with this, which is included in the default operation if this key is not specified.-l
- Write search results to the log file specified with this key.
Of course, directories for search and name masks can intersect up to a complete match. By default, by the way, if these keys are not set, both directories are assumed to be current (
./
) and both masks mean any names (
.*
). At the same time, the recursiveness of the search is turned off by default, in order not to explode the disk and brain of a computer on large projects.
For example:
$ ds-findorphaned -v -r -R -l "~/log.txt" -d "~/maybe_orphaned_images" -f ".*\.jpg$" -D "~/search_here, ~/and_here" -F ".*\.php$"
The result will be a list of all .jpg files located in
~/maybe_orphaned_images
(and subdirectories, recursively) that are not mentioned in any of the .php files located in
~/search_here
and
~/and_here
(and subdirectories, recursively).
I myself usually run the script with the
-l
key (and without
-v
), so that I can open the log, view, delete the lines with the necessary files and feed the remaining
rm
or
mv
.
Once again. Not mentioning is just one of the signs that a file is useless, so the script is only an aid to decision making. But for me the tool is so useful.
I will tidy up another vote in order to understand whether I should write about such useful things in the future.