导航:首页 > 程序命令 > 自己编写命令终端

自己编写命令终端

发布时间:2022-07-30 07:16:53

‘壹’ 如何使用Node.js编写命令工具

Node 给前端开发带来了很大的改变,促进了前端开发的自动化,我们可以简化开发工作,然后利用各种工具包生成生产环境。如运行sass src/sass/main.scss dist/css/main.css即可编译 Sass 文件。
在实际的开发过程中,我们可能会有自己的特定需求,
那么我们得学会如何创建一个Node命令行工具。
hello world

老规矩第一个程序为hello world。在工程中新建bin目录,在该目录下创建名为helper的文件,具体内容如下:
#!/usr/bin/env node console.log('hello world');

修改helper文件的权限:
$ chmod 755 ./bin/helper

执行helper文件,终端将会显示hello world:
$ ./bin/helperhello world

符号链接

接下来我们创建一个符号链接,在全局的node_moles目录之中,生成一个符号链接,指向模块的本地目录,使我们可以直接使用helper命令。

在工程的package.json文件中添加bin字段:
{ "name": "helper", "bin": { "helper": "bin/helper" }}

在当前工程目录下执行npm link命令,为当前模块创建一个符号链接:
$ npm link /node_path/bin/helper -> /node_path/lib/node_moles/myMole/bin/helper/node_path/lib/node_moles/myMole -> /Users/ipluser/myMole

现在我们可以直接使用helper命令:
$ helperhello world

commander模块

为了更高效的编写命令行工具,我们使用TJ大神的commander模块。
$ npm install --save commander

helper文件内容修改为:
#!/usr/bin/env node var program = require('commander'); program .version('1.0.0') .parse(process.argv);

执行helper -h和helper -V命令:
$ helper -h Usage: helper [options] Options: -h, --help output usage information -V, --version output the version number $ helper -V1.0.0

commander模块提供-h, --help和-V, --version两个内置命令。
创建命令

创建一个helper hello <author>的命令,当用户输入helper hello ipluser时,终端显示hello ipluser。修改helper文件内容:
#!/usr/bin/env node var program = require('commander'); program .version('1.0.0') .usage('<command> [options]') .command('hello', 'hello the author') // 添加hello命令 .parse(process.argv);

在bin目录下新建helper-hello文件:
#!/usr/bin/env node console.log('hello author');

执行helper hello命令:
$ helper hello ipluserhello author

解析输入信息
我们希望author是由用户输入的,终端应该显示为hello ipluser。修改helper-hello文件内容,解析用户输入信息:
#!/usr/bin/env node var program = require('commander'); program.parse(process.argv); const author = program.args[0]; console.log('hello', author);

再执行helper hello ipluser命令:
$ helper hello ipluserhello ipluser

哦耶,终于达到完成了,但作为程序员,这还远远不够。当用户没有输入author时,我们希望终端能提醒用户输入信息。
提示信息
在helper-hello文件中添加提示信息:
#!/usr/bin/env node var program = require('commander'); program.usage('<author>'); // 用户输入`helper hello -h`或`helper hello --helper`时,显示命令使用例子program.on('--help', function() { console.log(' Examples:'); console.log(' $ helper hello ipluser'); console.log();}); program.parse(process.argv);(program.args.length < 1) && program.help(); // 用户没有输入信息时,调用`help`方法显示帮助信息 const author = program.args[0]; console.log('hello', author);

执行helper hello或helper hello -h命令,终端将会显示帮助信息:$ helper hello Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser $ helper hello -h Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser

‘贰’ linux系统命令行在终端用脚本实现

echo "ifconfig wlan0 up" >> wifi_start.sh
echo "wpa_supplicant -B -i wlan0 -c /etc/wpa.conf" >> wifi_start.sh
echo "ifconfig wlan0 <ip> " >> wifi_start.sh
chmod +x wifi_start.sh
请用root用户执行

‘叁’ 如何用命令打开一个终端并在其中执行命令

shell 都是fork一个进程来执行的,你的程序执行完了就退出了,进程也就结束了,所以就关闭了。
1、(1)ctrl+shift+t 生成terminal
(2)ctrl+alt+F 切换到虚拟控制台(6个);ctrl+alt+F7/F8, 返回图形界面
(3)直接执行gnome-terminal就可以生成另一个终端,不需“cd /usr/bin;
./gnome-terminal”
2、显示helloworld,首先查看当前的终端号:
[root@redhat yuanwei]# tty
/dev/pts/2
[root@redhat yuanwei]# echo helloworld > /dev/pts/2
以上为网上找的资料,希望能帮到你。

‘肆’ linux awk命令基础 怎么在终端写

awk一般用于文本处理,通常用作数据提取。终端书写demo

awk'{print}'info.txt

以上是输出文本文件info.txt的所有内容,请使用实际文件进行替换info.txt

ps-ef|grepprocess_name|awk-F""'{print$2}'

以上是查找process_name进程的ID信息,把查找信息作为参数传给awk进行过滤,请使用实际进程名替换process_name。

‘伍’ 如何用shell 自定义终端命令

alias ad=’git add’
alias st=’git status’
alias stsh=’git stash’
alias ci=’git commit’
alias br=’git branch’
alias bra=’git branch -a’
alias co=’git checkout’
alias dif=’git diff’
alias po=’git push’
alias poo=’git push origin’
alias pod=’git push origin develop’
alias por=’git push origin release’
alias pom=’git push origin master’
alias pl=’git pull’
alias plo=’git pull origin’
alias pld=’git pull origin develop’
alias pldreb=’git pull origin develop –rebase’
alias plr=’git pull origin release’
alias plm=’git pull origin master’
alias pu=’git pull upstream’
alias fch=’git fetch’
alias reseth=’git reset –hard’
alias reb=’git rebase’
alias rebc=’git add . && git rebase –continue’
alias reba=’git rebase –abort’
alias log=’git log’
alias kk=’gitk’

‘陆’ 用Linux Elementary OS终端命令写Hello world具体方法

OS X系统终端命令如下:
输入:sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts就可以用文本编辑来直接修改hosts了。
隐藏文件是否显示有很多种设置方法,最简单的要算在Mac终端输入命令。显示/隐藏Mac隐藏文件命令如下(注意其中的空格并且区分大小写):
显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true;
隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false;
或者
显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES;
隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO;
输完单击Enter键,退出终端,重新启动Finder就可以了;
重启Finder:鼠标单击窗口左上角的苹果标志-->强制退出-->Finder-->重新启动;
mac os x terminal清屏快捷键: cammand+k (clear其实没鸟用)
linux系统清屏快捷键 : ctrl+l (reset)
windows 命令行清屏命令: cls
OS X 采用的Unix文件系统,所有文件都挂在根目录 / 下面,所以不再有Windows 下的盘符概念。
在桌面上看到的硬盘都挂在 /Volumes 下。
比如接上个叫做 USBHD的移动硬盘,桌面上会显示出一个硬盘图标,它实际在哪里呢?
在终端里执行 ls /Volumes/USBHD, 看看显示出的是不是这个移动硬盘的内容。
根目录位置是 / 核心 Mach_kernel 就在这里,
驱动所在位置 /Systme/Library/Extensions
用户文件夹位置 /User/用户名
桌面的位置 /User/用户名/Desktop
文件通配符为星号 *
注意:在 Unix系统中是区别大小写字符的,A.txt 不等于 a.txt。
根目录标志 / 不是可有可无,cd /System 表示转到跟目录下的System中,而cd System 表示转到当前目录下的 System中

如何进入命令行操作模式
再图形界面下,用finder 打开 应用程序 》实用程序》终端
如果连图形界面都进不去了(比如安错了显示驱动),开机时按 F8,用-s参数启动,然后输入命令 mount -uw /
获得权限
为了防止误操作破坏系统,再用户状态下时没有权限操作系统重要文件的,所以先要取得root权限
sudo -s
然后输入密码,输入密码时没有任何回显,连星号都没有,只管输完回车就行了。

‘柒’ cmd命令如何编写

schtasks/create/tn计划11/tr"cmd/cjava-jarxx.jar"/scdaily/st11:00/ru"system"

rem 每天执行.

‘捌’ 我要做一个终端登陆系统,要求去掉某些linux固有的shell命令,并增加一些自己写的命令,怎么搞

你提到的需求都是些应用层次的,没有修改内核的必要,无非是限制权限等等。

只需要自己去用root用户整理下文件设置下权限~

“去掉某些linux固有的shell命令“,你直接把你不想用户执行的命令给弄到普通用户看不到而root可以看到的路径中去就好了,比如挪到/sbin或者/usr/sbin下,并且去掉普通用户的可执行权限和文件的s标志,而且禁止普通用户对sbin或者/usr/sbin目录的访问(防止拷贝)~

“增加一些自己写的命令“,道理如上,你把你增加的命令放到普通用户的系统路径就可以了~

PS:“怎样找到某个命令所对应的进程,即对应的可执行程序”(这个说法有点问题呢~~~),还是如上,在bash在执行一个命令时,首先判断是否是内建命令(这种命令是没有可执行文件的),或者是否存在于当前环境变量路径中(/bin或者/usr/bin或者/usr/local/bin或者/opt/bin等等),或者是否指定了路径。

‘玖’ 如何在linux终端下用命令编辑一个文件并保存

在linux终端下用命令编辑一个文件并保存的具体操作步骤如下:

1、首先打开命令控制台找到要编辑的文件,执行命令ls看看下面有几个文件,我这个下面有个index.php文件。

‘拾’ linux(ubuntu)如何编写shell能打开新的终端并在新终端执行其后的命令

linux都有shell
按ctrl+alt+f1或f2到f6随便哪个都可以进shell环境。
如果只要一个虚拟终端只要在附件里找终端就可以了。
另外,团IDC网上有许多产品团购,便宜有口碑

阅读全文

与自己编写命令终端相关的资料

热点内容
被调侃的程序员 浏览:483
哪里有无损音乐app下载 浏览:221
单片机如何使用proteus 浏览:991
java常用的服务器 浏览:281
集结APP在哪里下载 浏览:800
欧洲cf玩什么服务器 浏览:529
如何连接另一台电脑上的共享文件夹 浏览:681
如何让桌面文件夹搬家到e盘 浏览:73
java自动格式化 浏览:619
ipad怎么查看文件夹大小 浏览:583
手工粘土解压球 浏览:552
在线视频教育源码 浏览:41
快四十学什么编程 浏览:754
gnumakelinux 浏览:537
视易峰云服务器怎么改系统 浏览:535
javamap取值 浏览:768
mac和win磁盘加密软件 浏览:474
苹果为什么会连接不到服务器 浏览:726
pdf格式文件如何保存 浏览:303
小霸王服务器tx什么意思 浏览:75