This article introduces the use of writing a simple command line tool and share it with you. The details are as follows:
The operating system needs to be Linux
1. Goal
- Enter the command you wrote on the command line to complete the target task
- The command line requires global validity
- The command line requires that it can be deleted
- The command line functions to generate a file to display the current date
2. Code section
- Create a new file and name it sherryFile
- Contents of file sherryFile
Introduction: Generate a file with the current date and creator
#! /usr/bin/env node ('command start'); const fs = require('fs'); let date = new Date().toLocaleDateString(); let data = date + '\n\t' + '——create By karuru'; ('./', data, 'utf8', (err) => { if (err) { ('sherryFile command wrong', err); return false; } ('writeFile success!!!!'); ('command end'); });
- Give the execution permissions to this file chmod 755 sherryFile
- Enter ./sherryFile in the file path where the file is located
- If the following is output, the command execution is successful
command start
writeFile success!!!!
command end
In this file directory, a new file will be generated, with the following content
2/28/2018
create By karuru
Modify the command to be valid globally
ln sherryFile /usr/local/bin/sherryFile
Delete command
rm /usr/local/bin/sherryFile
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.