『壹』 如何使用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網上有許多產品團購,便宜有口碑