this post was submitted on 04 Feb 2025
16 points (94.4% liked)

Linux

50297 readers
754 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

New version for toarchive: https://gist.github.com/thingsiplay/889cb2899f35405e10839112f5181ab3#file-toarchive

(I have added a new version of the script. The old one is renamed to 'toarchive-old'. The new script has some guard rails and more checks. Also original files can be removed automatically on success, like gzip does. But an option -r must be explicitly given here, like toarchive zip -r file.txt. Directories can be removed too, but the option uppercase -R is required here, as in toarchive zip -R my_dir. Have in mind this will use rm -r system command. Although some guard rails are in place to prevent massive fail, you should be very careful. Note that no file is removed, if -r or -R are not used at all.)


I always write little scripts and aliases that help me from time to time. I just wanted to share some of my newest simple scripts. There are probably better or easier ways to do, but writing and testing them is fun too. Both make use of the 7z command, a commandline archive tool. Posting it here, so anyone can steal them. They are freshly written, so maybe there are edge cases.

crc32sum:

#!/usr/bin/env bash

# Calculate CRC32 for each file.
if [ "${#}" -eq 0 ]; then
    echo "crc32sum files..."
    echo "crc32sum *.smc"
else
    7z h -- "${@}" |
        \grep --after-context "${#}" '^-------- -------------  ------------$' |
        \grep --before-context "${#}" '^-------- -------------  ------------$' |
        awk '{print $1 "\t" $3}' |
        \grep -P '^[0-9A-Z]+\t'
fi

toarchive:

#!/usr/bin/env bash

# Create one archive for each file or folder.
if [ "${#}" -eq -1 ]; then
    echo "toarchive ext files..."
    echo "toarchive zip *.smc"
else
    ext="${1}"
    shift
    opt=()
    stop_parse=false

    for arg in "${@}"; do
        if [ ! "${stop_parse}" == true ]; then
            if [ "${arg}" == "--" ]; then
                stop_parse=true
                opt+=(--)
                continue
            elif [[ "${arg}" =~ ^- ]]; then
                opt+=("${arg}")
                continue
            fi
        fi
        file="${arg}"

        7z a "${opt[@]}" "${file}.${ext}" "${file}"
    done
fi
top 7 comments
sorted by: hot top controversial new old
[–] eldavi@lemmy.ml 6 points 2 weeks ago (1 children)

i always envy people who can do formatting/styling well.

why 7z instead of tar with xz or gzip? is it better somehow?

[–] thingsiplay@beehaw.org 5 points 2 weeks ago (1 children)

No, I'm just used to use 7z. As it does lot of formats, its my default program for archive stuff. In example I also use often 7z as file format too (toarchive 7z files). And to calculate crc32, not sure if the other tools print that information.

[–] eldavi@lemmy.ml 4 points 2 weeks ago (1 children)

i'd image that you'd use other tools to do that and i ask because you're not the first to extol 7z instead of the old tools that us greybeards of come accustomed to using over the last decades; i dont wanna be left behind to ossify. lol

[–] thingsiplay@beehaw.org 4 points 2 weeks ago (1 children)

Well I used to use gzip to create .gz files. But as I use 7z a lot, that inspired me to write this function to get a similar functionality. Only the auto delete original files is not implemented. Maybe in the future. BTW I also use tar for backing up files with a custom backup script. Want to share it someday too, but never got around to make it usable for others. So at least I'm half greybeard. :D

[–] eldavi@lemmy.ml 4 points 2 weeks ago

if you want to be a full greybeard, just tell them to rtfm instead of making it for them. lol

[–] bier@lemmy.blahaj.zone 3 points 2 weeks ago (1 children)
[–] thingsiplay@beehaw.org 1 points 2 weeks ago

I use Zstd specifically with tar to make backups ever since I realized how fast it is. But that is a complete different thing than this day to day tool, where Zstd is not needed.