July 2017
Intermediate to advanced
656 pages
16h 1m
English
By now we have learned how to fetch information about a file or directory, but how do we alter specific qualities?
Let's create a small program that creates a file, sets the UID and GID to nobody, and sets access permissions to 000 (not readable, writeable, or executable):
const fs = require('fs') const { execSync } = require('child_process') const file = process.argv[2] if (!file) { console.error('specify a file') process.exit(1) } try { fs.accessSync(file) console.error('file already exists') process.exit(1) } catch (e) { makeIt() } function makeIt() { const nobody = Number(execSync('id -u nobody').toString().trim()) fs.writeFileSync(file, '') fs.chownSync(file, nobody, nobody) fs.chmodSync(file, 0) console.log(file ...