npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

metla

v1.0.1

Published

search and remove files by regexp

Downloads

7

Readme

Metla / metla.js Build Status Node.js 10+ cli

Remove Files By Regexp Template

Metla allows you to remove files by searching via regexp template.

Main features are:

  • batch file deletion
  • filtering file names by regexp
  • ordering matched files by:
    • last modification datetime
    • lexicographically
  • keeping X number of files that match template
  • minimal flat dependencies (3 tiny modules)
  • no operation (output what will be deleted only)
  • configurable
  • ready for CI or cronjobs
  • traceable

Installation

There are 2 installation options:

  1. Traditional installation via npm
  2. Binary package

NPM

npm install metla.js
# or globally
npm install -g metla.js

Binary Package

Go to release page and download binary for your platform. This option allows you to run Metla without Node.js installed on your system.

If you don't want to specify path before binary name when executing Metla, then put binary to any path from ${PATH} (e.g. /usr/local/bin)

Usage

$ ./metla --help
Usage: metla [options]

search and remove files by regexp

Options:
  -V, --version       output the version number
  -p, --path <path>   path for files search
  -t, --tmpl <regex>  regexp expression to match file names
  -k, --keep <num>    number of files to keep
  -m, --mode <mode>   matched files ordering mode, valid values are: lastmod, lexorder; lastmod orders by modification date, lexorder orders lexicographically; default: lastmod
  -c, --conf <conf>   path to configuration file
  -l, --log <log>     path where log file is created/appended
  -n, --noop          do not perform deletion, show only what will be deleted (default: false)
  -s, --silent        prevent logs from stdout (default: false)
  -v, --verbose       enable verbose mode (default: false)
  -h, --help          output usage information

Configuration

There are 4 levels where configuration may be specified (from the lowest precedence to the highest one):

  1. Default configuration, comes with Metla (can't be changed, but you may not specify options if default config works for you)
  2. ${HOME}/.config/metla.ini - user default config in ini format
  3. External user custom configuration in ini format
  4. Command line options

Every next level overrides options defined at lower precedence level

ini configuration files can have the following options:

  • path - path for files search
  • tmpl - regular expression
  • keep - number of files to keep
  • mode - ordering mode
  • log - path to log file

Examples

Show what will be deleted

$ ls /tmp/
text10.txt  text11.txt  text12.txt  text1.txt  text2.txt  text3.txt  text4.txt  text5.txt  text6.txt  text7.txt  text8.txt  text9.txt

# Order by last modification (the newest files are kept)
$ metla --path /tmp/ --log /tmp/metla.log --keep 3 --tmpl '.+[.]txt' --noop --mode lastmod 
2020-01-12T15:02:31.304Z [info] will delete '/tmp/text9.txt' file
2020-01-12T15:02:31.306Z [info] will delete '/tmp/text8.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text7.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text6.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text5.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text4.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text3.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text2.txt' file
2020-01-12T15:02:31.307Z [info] will delete '/tmp/text1.txt' file

# Order lexicographically
$ metla --path /tmp/ --log /tmp/metla.log --keep 3 --tmpl '.+[.]txt' --noop --mode lexorder
2020-01-12T15:02:21.310Z [info] will delete '/tmp/text6.txt' file
2020-01-12T15:02:21.312Z [info] will delete '/tmp/text5.txt' file
2020-01-12T15:02:21.312Z [info] will delete '/tmp/text4.txt' file
2020-01-12T15:02:21.312Z [info] will delete '/tmp/text3.txt' file
2020-01-12T15:02:21.313Z [info] will delete '/tmp/text2.txt' file
2020-01-12T15:02:21.313Z [info] will delete '/tmp/text12.txt' file
2020-01-12T15:02:21.313Z [info] will delete '/tmp/text11.txt' file
2020-01-12T15:02:21.313Z [info] will delete '/tmp/text10.txt' file
2020-01-12T15:02:21.313Z [info] will delete '/tmp/text1.txt' file

Delete files

# Create config if you don't want supply command line arguments every time
$ cat <<EOF | tee /tmp/metla.conf
path=/tmp/
log=/tmp/metla.log
keep=3
tmpl=.+[.]txt
EOF

# Delete by specifying confiuration from file
$ metla --conf /tmp/metla.conf
2020-01-12T15:39:40.958Z [info] file '/tmp/text8.txt' has been deleted
2020-01-12T15:39:40.961Z [info] file '/tmp/text7.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text6.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text5.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text4.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text3.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text9.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text2.txt' has been deleted
2020-01-12T15:39:40.962Z [info] file '/tmp/text1.txt' has been deleted

$ ls /tmp/
metla.conf  text10.txt  text11.txt  text12.txt

Building Binaries

You can build binary for Linux/Windows and use Metla without installed Node.js. The binary size will be pretty large (around 40Mb) for such a simple tool, so keep it in mind.

# building binaries
npm install                 # install dependencies
npm run build-binaries
ls -lh bin/                 # list built binaries

Motivation

From time to time there is a need to remove files based on different rules (lexicographically, creation or modification date) in order to prevent disk space bloating. Yes, it is possible to solve many of these problems by using bash scripts (for Linux) or powershell scripts (for Windows), but the main motivation was to gain a bit of experience in Node.js along with creating not so useless thing.

License

MIT