Solving the problem with the place, the organization of the directory “Disassemble”

    I think each of us has the “Parse” and “Downloads” directories, looking into which we are all horrified by their contents, and especially from the very idea that someday all this will have to be raked. I propose my solution to the problem of lack of space, this is not a way of super-hierarchization, and not a way to infinitely increase space somewhere in the cloud, just the idea of ​​organizing the downloaded information.

    image

    What is the likelihood that if the file was not remembered for 2 weeks, it will be remembered in a year or two, despite the fact that almost everything downloaded on the Internet tends to quickly become outdated. This solution is also suitable for organizing shared resources (file dumps).

    It is not always possible to listen to an album of an unknown collective, being interested only in the fact that this music was attributed to your favorite genre, usually there are two solutions. In the first case, the album falls into the “Parse” directory / remains in the “Downloads” directory, which is called later, everyone knows how quickly these directories are inflated. In the second case, the album is saved in a specially designated directory “Music”, constantly increasing it, but as a result, at some point it comes to understanding that this is not a place where your favorite and selected artists are stored, but the same directory “Make out”, which sorted by type of sound files.
    The same with films, books, wallpapers, with any documents. You can download it by succumbing to emotions, recommendations, a beautiful cover, but whether this film or a book really deserves disk space is still worth finding out. About file trash is not worth commenting, because the name speaks for itself.

    Actually, my solution is a script that automatically cleans directory data, but in a smart way, and not immediately. I want to make a reservation that everything on my disk is sorted and located in my directories: “Music”, “Photo”, “Video”, “Books”, “Work”, etc, this is exactly the information I have selected that I know and remember . Everything that gets there I listen and look through. The idea is that the downloaded information is stored in “Downloads” for 2 weeks after which, if I remember about it (if this is really a well-known and expected book / artist usually remembers this), it falls into one of the allotted directories, otherwise it is removed into oblivion. On the process of "remembering" I leave myself 2 weeks. Week data is not counted for the “Downloads” directory as a whole, but for each file individually, i.e. the script does not delete everything every 2 weeks, and every four hours it checks for outdated files that can be deleted. Also, the script uses the atime argument (by the time the file was last accessed), if there is, for example, a clip / photo / music for which I’m still thinking, a counter that counts the same 2 weeks will be reset to zero every time the file is opened, therefore, if the information is important and in demand, it will last until it is really forgotten about it. This system has been working successfully for six months, one day, several books that didn’t have time to move to a smartphone were deleted, the rest are only pluses. the counter that counts those same 2 weeks will be reset to zero each time the file is opened, therefore, if the information is important and in demand, it will last until I really forget about it. This system has been working successfully for six months, one day, several books that didn’t have time to move to a smartphone were deleted, the rest are only pluses. the counter that counts those same 2 weeks will be reset to zero each time the file is opened, therefore, if the information is important and in demand, it will last until I really forget about it. This system has been working successfully for six months, one day, several books that didn’t have time to move to a smartphone were deleted, the rest are only pluses.

    Actually the scripts themselves:

    cat / var / scripts / cleaning

    #!/bin/bash
    FOLDERS="/mnt/drive_2/shared_folder /mnt/drive_2/Downloads /home/*/Desktop /home/*/Downloads /home/*/.Trash /home/*/.local/share/Trash"
    LOGDIR=/var/log/cleaning
    LOG="$LOGDIR/log"
    # проверяем наличие директории с логом, если отсутствует, создаем
    if [ -d "$LOGDIR" ]; then
    echo "directory $LOGDIR is exist"
    else
    mkdir $LOGDIR
    echo "directory $LOGDIR was created"
    fi
    # проходимся по директориям
    for DIRECTORY in $FOLDERS ; do
    echo "PROCESSING_DIRECTORY=$DIRECTORY"
    # чистим директории от файлов, к которым не было обращения более 2 недель
    find $DIRECTORY -atime +14 -type f | while read FILE ; do
    rm -rf "$FILE"
    echo "$(date +%d.%m.%y%t%H:%M:%S) File $FILE was delited from $DIRECTORY as old"
    echo "$(date +%d.%m.%y%t%H:%M:%S) File $FILE was deleted from $DIRECTORY as old" >> $LOG
    done
    # чистим пустые директории
    find $DIRECTORY -type d -empty | while read DIR ; do
    rm -rf "$DIR"
    echo "$(date +%d.%m.%y%t%H:%M:%S) Directory $DIR was delited from $DIRECTORY directory as empty"
    echo "$(date +%d.%m.%y%t%H:%M:%S) Directory $DIR was deleted from $DIRECTORY directory as empty" >> $LOG
    done
    done
    exit 0
    


    cat / etc / crontab

    # cleaning
    45 */4  * * *   root    /var/scripts/cleaning                                   # cleaning every 4 hours
    


    cat /etc/logrotate.d/cleaning

    /var/log/cleaning/log {
      rotate 12
      monthly
      compress
      missingok
      notifempty
    }
    


    Logging in this option is done specifically so that there are no questions about where and how the file disappeared, if you do not need it, you can use the following commands:
    for files: find $ DIRECTORY -atime +7 -type f -delete
    for directories: find $ DIRECTORY -type d -empty -delete

    In case of production of this script, where important information may be lost (for example, the shared shared resource of the organization), to eliminate the likelihood of a system time (or ntp server) failure, this script can be slightly improved, instead of deleting, moving files into some intermediate direct uw, where they will be removed only when the reduction of stock space, thus there will be no unnecessary "corns" eyes in the general directory, but, at the same time it remains possible, a quick return.

    Finally, a few useful excerpts from man find:

    -mtime is the time the file was last modified.
    -atime is the time the file was last accessed.
    -ctime - time of the last change of the owner or access rights to the file.

    -mmin - the number of minutes elapsed since the last file change.
    -amin - the number of minutes elapsed since the last access to the file.
    -cmin - the number of minutes that have passed since the last change in ownership or access rights to the file.

    When searching for Russian man for copy paste, a convenient configurator for the find command was found , maybe someone will come in handy ...

    Also popular now: