Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Advice for filesystem operations under Zsh



    Hello all :))

    I have a little shell function that, for each file in certain
places of the filesystem, checks whether the file belongs to an
installed program or not, using some list files. I must tell how it
is implemented in order to ask for advice, so please be patient O:)

    The file list is stored in an array parameter, and in order to
avoid reading from disk, the check is performed reading every 'list
file' and comparing its contents (lines that are filenames) against
the entire array, deleting the corresponding entry if found. That
way, at the end of iterations, the array contains all 'orphan' files.

    This works ok for me, but I want to extend this shell function to
perform other tasks. One of them is, given a filename, find the 'list
file' it belongs to. That's pretty easy ;)) But I want to extend the
shell function so that, in one run, it outputs:

    - Orphan files in file descriptor 3
    - Dangling symlinks in file descriptor 4
    - Setuid binaries in file descriptor 5
    - Duplicate files in file descriptor 6
    - Empty directories in file descriptor 7
    - etc...

    Under Zsh is pretty easy to find all dangling symlinks
(**/*(@-)), setuid files (**/*(s)), etc... and I can do all that in
just one travel through the filesystem, since glob qualifiers work
too with filenames withouth globbing characters. My problems are:

    - finding dupes. I've tried to use 'I' subscript flag, but this
only return all matching keys in an associative array, not in normal
ones. The only solution seems to be deleting the match and search
again...

    - finding empty directories. Looking for the number of links in
the directory doesn't work (it only shows if the directory has files
or not, but not if it has subdirs).

    - doing all that in one run of the array. Since the 'orphans'
check destroys the contents of the array, I need to dupe it, or
convert it to a associative array, but then it cannot have duplicate
entries, since I would need to use the filename as a key and the
value as one of dangling, orphan, empty, setuid, etc... or even a
combination of that.

    The objetive is doing a lightweight version of FSlint without
using 'find'. The solutions to some of the problems are easy: use a
'master' array and duplicates as needed, for example for finding
orphans, duplicated filenames, etc... And I cannot find a solution
for empty files.

    Sorry for the long message, and thanks a lot in advance, truly.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



Messages sorted by: Reverse Date, Date, Thread, Author