Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
find-remove
Advanced tools
recursively finds files and/or directories by filter options from a start directory onwards and deletes these according to plenty of options you can configure. useful if you want to clean up stuff within a directory in your node.js app.
finally in typescript (since v5)
recursively finds files by filter options from a start directory onwards and deletes only those which meet conditions you can define. useful if you want to clean up a directory in your node.js app.
you can filter by extensions, names, level in directory structure, file creation date and ignore by name, yeah!
to install find-remove, use npm:
$ npm install -S find-remove
then in your node.js app, get reference to the function like that:
import findRemoveSync from "find-remove";
const result = findRemoveSync("/temp", { extensions: [".bak", ".log"] });
the return value result
is a json object with successfully deleted files. if you output result
to the console, you will get something like this:
{
'/tmp/haumiblau.bak': true,
'/tmp/dump.log': true
}
const result = findRemoveSync("/temp", { files: "dump.log" });
const result = findRemoveSync("/temp", { files: "dump.log", dir: "*" });
const result = findRemoveSync("/temp", { extensions: [".bak"], ignore: "haumiblau.bak" });
const result = findRemoveSync("/dist", { dir: "CVS" });
const result = findRemoveSync("/tmp", {
age: { seconds: 3600 },
extensions: ".jpg",
limit: 100,
});
const result = findRemoveSync("/tmp", { prefix: "filenamestartswith" });
const result = findRemoveSync("/tmp", { maxLevel: 2, extensions: ".tmp" });
this deletes any .tmp
files up to two levels, for example: /tmp/level1/level2/a.tmp
but not /tmp/level1/level2/level3/b.tmp
why the heck do we have this maxLevel
option? because of performance. if you care about deep subfolders, apply that option to get a speed boost.
const result = findRemoveSync(rootDirectory, { dir: "*", files: "*.*" });
const result = findRemoveSync(rootDirectory, { files: "example[1-3]", regex: true });
this deletes files example1.txt
, example2.txt
, and example3.txt
, but not example8.txt
.
const result = findRemoveSync(rootDirectory, { dir: "^assets_", regex: true });
this deletes all directories that start with assets_
.
findRemoveSync takes any start directory and searches files from there for removal. the selection of files for removal depends on the given options. and at last, it deletes the selected files/directories.
arguments
dir
- any directory to search for files and/or directories for deletion (does not delete that directory itself)files
- can be a string or an array of files you want to delete within dir
.dir
- can be a string or an array of directories you want to delete within dir
.extensions
- this too, can be a string or an array of file extensions you want to delete within dir
.ignore
- useful to exclude some files. again, can be a string or an array of file names you do NOT want to delete within dir
age.seconds
- can be any float number. findRemoveSync then compares it with the file stats and deletes those with modification times older than age.seconds
limit
- can be any integer number. Will limit the number of files to be deleted at single operation to be limit
prefix
- can be any string. Will delete any files that start with prefix
.maxLevel
- advanced: limits filtering to a certain level. useful for performance. recommended for crawling huge directory trees.test
- advanced: set to true for a test run, meaning it does not delete anything but returns a JSON of files/directories it would have deleted. useful for testing.regex
- set to true to treat files
or dir
option strings as regular expression patterns.as a precaution, nothing happens when there are no options.
the unit tests are good examples on how to use the above arguments.
returns
JSON of files/directories that were deleted. For limit option - will only return number of files deleted.
MIT
FAQs
recursively finds files and/or directories by filter options from a start directory onwards and deletes these according to plenty of options you can configure. useful if you want to clean up stuff within a directory in your node.js app.
The npm package find-remove receives a total of 11,753 weekly downloads. As such, find-remove popularity was classified as popular.
We found that find-remove demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.