file

Git – Remove untracked files matching a pattern

Solution

$ git clean [-n] -f <path>...

Example

Run:

$ git clean -n -f *.json

to remove all untracked json files.

Important note

Always use -n or --dry-run before running the command.

Download streamable files with Axios/NestJS

Solution

Use responseType: arraybuffer. Example in NestJS (The httpService of NestJS uses Axios):

const response = this.httpService.get(downloadUrl, {
  responseType: 'arraybuffer', // <= THIS
});

return new Promise((resolve, reject) => {
  response.subscribe({
    next(response) {
      response.status === 200 ?
        resolve(response.data) :
        reject(response.data);
      },
      error(err) {
        reject(err);
      },
    }
  });
});

 

Perl – Detect non-ASCII characters in file

Solution

$ perl -ne 'if (/[^[:ascii:]]/) { print $. . ": " . $_ }' filepath

 

Get file content from line x to line y

Solution

$ awk 'NR >= x && NR <= y' path/to/file