You are not logged in.

#3276 2019-11-12 21:41:04

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: Post your handy self made command line utilities

When dealing with timestamped files, it is sometimes nice to be able to cleanup unnecessary files while keeping some for archive purposes. Could not find better option than to write small script for that. It searches directory content for timestamped files and lists only files for last N days/months/years. Optionally it allows to --invert filter and --delete filtered files:

https://gitlab.com/student/timestamps-archive

# list top 10 timestamped files in current directory
timestamps-archive.py --format "archive_%Y-%m-%d.zip"  --top 10

# first timestamped file from last 12 months  
timestamps-archive.py --format "%Y-%m-%d"  --months 12 

# delete timestamped files except latest 5 and last 10 years
timestamps-archive.py --format "%Y-%m-%d"  --top 5 --years 10 --invert --delete

# print help
timestamps-archive.py -h 
usage: timestamps-archive.py [-h] [--path PATH] [--format FORMAT] [--top TOP]
                             [--days DAYS] [--months MONTHS] [--years YEARS]
                             [--invert] [--delete]

Daily/monthly/yearly archive filter for timestamped files/directories

optional arguments:
  -h, --help       show this help message and exit
  --path PATH      files path, default is current directory
  --format FORMAT  date/time format, default is %Y-%m-%dT%H:%M:%S
  --top TOP        include TOP files
  --days DAYS      include number of DAYS
  --months MONTHS  include number of MONTHS
  --years YEARS    include number of YEARS
  --invert         invert filter
  --delete         delete filtered files/directories

Offline

#3277 2019-11-13 00:29:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,409
Website

Re: Post your handy self made command line utilities

studentik, is this just on the filenames, or do you look at mtime/atime?  If the latter, you should really just use find as it has flags for file times in certain ranges.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3278 2019-11-13 05:50:16

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: Post your handy self made command line utilities

Trilby wrote:

studentik, is this just on the filenames, or do you look at mtime/atime?  If the latter, you should really just use find as it has flags for file times in certain ranges.

This looks for timestamp in names. Regarding find, I don't know if that is possible, since whether or not file should end up in list depends on existance/absence of another files, not current time. Let's say we don't have archive for January 1st, but do have for January 2nd, filtering --years should keep this January 2nd since it is first existing timestamp for particular year.

Offline

#3279 2019-11-13 12:53:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,409
Website

Re: Post your handy self made command line utilities

Well I was thinking find piped to head/sed or the like for restricting the number of results, but yes, if this is just about dates in the names of files, find wouldn't help.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3280 2019-12-01 22:46:05

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 720
Website

Re: Post your handy self made command line utilities

I lied, I have a little AUR helper; this is all it does:

aur pkgname:

git clone https://aur.archlinux.org/$1.git

I also have a little ABS helper,

abs pkgname:

git clone git://git.archlinux.org/svntogit/packages.git --{single-,}branch {packages/,}$1

Offline

#3281 2019-12-02 13:47:16

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 2,030
Website

Re: Post your handy self made command line utilities

How many AUR packages do you manage with your "little" helper?

Just wondering.


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

#3282 2019-12-02 18:50:57

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 53

Re: Post your handy self made command line utilities

quequotion wrote:
git clone https://aur.archlinux.org/$1.git

I have almost the same:

#!/bin/sh

if [ -z "$1" ]; then
    exit 1
fi

git clone "https://aur.archlinux.org/$1"

Offline

#3283 2019-12-02 20:03:17

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 720
Website

Re: Post your handy self made command line utilities

Alad wrote:

How many AUR packages do you manage with your "little" helper?

lol, "manage" may be too strong a word; it's downloaded a few dozen packages.

EDIT: If you were asking about the packages I maintain in the AUR; I "manage" those in a couple of git repositories of their own. All my published AUR packages have been managed with git since.. aur 4?.

dimich wrote:
if [ -z "$1" ]; then
    exit 1
fi

ooh, mine just breaks!

Last edited by quequotion (2019-12-03 10:31:58)

Offline

#3284 2019-12-03 00:15:28

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 2,030
Website

Re: Post your handy self made command line utilities

Suggested improvement:

#!/bin/bash
if [[ -z $1 ]]; then
  echo "The trash heap of Arch. Dig around enough and maybe you will find some gold."
else
  git clone https://aur.archlinux.org/"$1".git
fi

Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

#3285 2019-12-03 00:32:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,409
Website

Re: Post your handy self made command line utilities

The quotes around $1 don't really help much - they just change the type of problem you'd face if you pass a first parameter with spaces in it - but it really doesn't matter as package names can't have spaces.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3286 2019-12-03 01:04:04

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 2,030
Website

Re: Post your handy self made command line utilities

That reminds me of an AUR pkgbuild I saw which had depends like 'foo bar'. I guess that's for the grr thread...


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

#3287 2019-12-03 05:49:40

quequotion
Member
From: Oita, Japan
Registered: 2013-07-29
Posts: 720
Website

Re: Post your handy self made command line utilities

Alad wrote:

The trash heap of Arch. Dig around enough and maybe you will find some gold.

Is that a proposal for the AUR FAQ?

I support this proposal. It makes clear the risks involved; the dumpster diving metaphor is excellent: this may give you cholera, or hepatitis, not to mention a sore stomach (and honestly a few headaches).

Also fine documentation for a little AUR helper.

Trilby wrote:

they just change the type of problem you'd face if you pass a first parameter with spaces in it

It just does one pkgname at a time; someone may attempt multiple pkgnames in a single call. That won't work without a loop; and is going to cause some unspecified behavior as is.

Maybe mandatory single pkgname mode is best anyway ($1 without quotes; relies on user not supplying $1 as a string with a space in it using their own quotes; silently drops other parameters if say, someone tried to aur multiple-bzr aurpkgs-git atonce-hg)?

Last edited by quequotion (2019-12-03 13:20:36)

Offline

#3288 2019-12-03 12:58:39

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 2,030
Website

Re: Post your handy self made command line utilities

If someone quoted multiple packages in one string they only have themselves to blame...


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

Board footer

Powered by FluxBB