📜 ⬆️ ⬇️

A simple search script of possibly orphaned project files.

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:


Well, three auxiliary 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.

Source: https://habr.com/ru/post/337140/


All Articles