作為前端開發(fā)工程師,我們需要了解哪些命令?如果您熟悉這些命令,它們將大大提高您的工作效率。
1. tree
小伙伴們,你們知道如何列出一個(gè)目錄的文件結(jié)構(gòu)嗎?
它在顯示文件之間的目錄關(guān)系方面做得很好,這真的很酷。
commands
├── a.js
├── b.js
├── c.js
├── copy-Apps
│ └── fe-apps
│ └── a.js
├── fe-apps
│ └── a.js
├── test.log
└── xxx
└── yyy
在此之前,您需要安裝命令樹。
brew install tree
然后只需在文件目錄中執(zhí)行tree即可。
2.wc
wc 是 word count 的縮寫,常用于文件統(tǒng)計(jì)。它可以統(tǒng)計(jì)字?jǐn)?shù)、行數(shù)、字符數(shù)、字節(jié)數(shù)等。
我經(jīng)常用它來計(jì)算文件中的代碼行數(shù)。
3.du
打印出一個(gè)目錄的文件大小信息。我們使用它的頻率較低,但它是一個(gè)非常值得學(xué)習(xí)的命令。
- du -h:打印出適合人類閱讀的信息。
- du -a:列出目錄中文件大小的信息;
- du -s:只顯示總大小,不顯示具體信息。
? commands git:(master) ? du
0 ./xxx/yyy
0 ./xxx
0 ./fe-apps
0 ./copy-apps/fe-apps
0 ./copy-apps
0 ./.git/objects/pack
0 ./.git/objects/info
0 ./.git/objects
8 ./.git/info
104 ./.git/hooks
0 ./.git/refs/heads
0 ./.git/refs/tags
0 ./.git/refs
136 ./.git
168 .
? commands git:(master) ? du -h
0B ./xxx/yyy
0B ./xxx
0B ./fe-apps
0B ./copy-apps/fe-apps
0B ./copy-apps
0B ./.git/objects/pack
0B ./.git/objects/info
0B ./.git/objects
4.0K ./.git/info
52K ./.git/hooks
0B ./.git/refs/heads
0B ./.git/refs/tags
0B ./.git/refs
68K ./.git
84K .
? commands git:(master) ? du -ha
4.0K ./a.js
0B ./xxx/yyy
0B ./xxx
0B ./fe-apps/a.js
0B ./fe-apps
4.0K ./test.log
0B ./copy-apps/fe-apps/a.js
0B ./copy-apps/fe-apps
0B ./copy-apps
4.0K ./c.js
4.0K ./.git/config
0B ./.git/objects/pack
0B ./.git/objects/info
0B ./.git/objects
4.0K ./.git/HEAD
4.0K ./.git/info/exclude
4.0K ./.git/info
4.0K ./.git/description
4.0K ./.git/hooks/commit-msg.sample
8.0K ./.git/hooks/pre-rebase.sample
4.0K ./.git/hooks/pre-commit.sample
4.0K ./.git/hooks/applypatch-msg.sample
4.0K ./.git/hooks/fsmonitor-watchman.sample
4.0K ./.git/hooks/pre-receive.sample
4.0K ./.git/hooks/prepare-commit-msg.sample
4.0K ./.git/hooks/post-update.sample
4.0K ./.git/hooks/pre-merge-commit.sample
4.0K ./.git/hooks/pre-applypatch.sample
4.0K ./.git/hooks/pre-push.sample
4.0K ./.git/hooks/update.sample
52K ./.git/hooks
0B ./.git/refs/heads
0B ./.git/refs/tags
0B ./.git/refs
68K ./.git
4.0K ./b.js
84K .
du -sh
4. alias
alias命令用于設(shè)置命令的別名。如果您僅鍵入別名,將列出所有當(dāng)前別名設(shè)置。
讓我們嘗試為 git status 設(shè)置一個(gè)別名
alias gs="git status"
值得注意的是:如果你想讓gs命令永久存在,你應(yīng)該在.profile或.zshrc中設(shè)置它。
5.grep
我們經(jīng)常需要查找服務(wù)器上日志文件的內(nèi)容,grep將是我們得心應(yīng)手的幫手。
有一個(gè)日志文件test.log。它包含以下內(nèi)容:
const a = 1
const b = 2
const c = 3
console.log(a + b + c)
如何突出顯示包含 a 字符的位置?這很容易,不是嗎?
grep a test.log
6.cat
cat 的主要用途是查看文件的內(nèi)容并將其打印在屏幕上。
但它至少還有一些其他用途。
1.清除a.js的內(nèi)容
? commands git:(master) ? cat a.js // There are two lines of code in a.js
const a = 'fatfish'
console.log(a)%
? commands git:(master) ? cat /dev/null > a.js // clear the contents of a.js
? commands git:(master) ? cat a.js // The content in a.js is cleared.
? commands git:(master) ?
2.將a.js的內(nèi)容復(fù)制到b.js
? commands git:(master) ? cat a.js
const name = 'fatfish'
console.log(name)
? commands git:(master) ? cat b.js // No content in b.js
? commands git:(master) ? cat a.js > b.js // Copy the contents of a.js to b.js
? commands git:(master) ? cat b.js // The content in b.js is the same as in a.js
const name = 'fatfish'
console.log(name)
? commands git:(master) ? cat a.js
const name = 'fatfish'
console.log(name)
3.將a.js的內(nèi)容添加到c.js的最后一個(gè)字符
? commands git:(master) ? cat a.js
const name = 'fatfish'
console.log(name)%
? commands git:(master) ? cat c.js
const age = 100
console.log(age)
? commands git:(master) ? cat a.js >> c.js
? commands git:(master) ? cat c.js
const age = 100
console.log(age)const name = 'fatfish'
console.log(name)
7.clear
有時(shí)候,我們需要在終端中進(jìn)行一些操作,這樣屏幕上的內(nèi)容就足以讓我們感到煩惱了。
如何清除它們?我們需要逐行刪除它們嗎?
8.cp
cp命令用于復(fù)制文件或目錄。
cp -f:當(dāng)要復(fù)制的文件覆蓋已有的目標(biāo)文件時(shí),不會(huì)有提示信息。
cp -r:如果復(fù)制的文件是目錄文件,則復(fù)制該目錄下的所有子目錄和文件。
? commands git:(master) ? ls -R
a.js b.js copy-apps fe-apps
./copy-apps:
./fe-apps:
// 1. copy a file
? commands git:(master) ? cp a.js fe-apps
? commands git:(master) ? ls -R
a.js b.js copy-apps fe-apps
./copy-apps:
./fe-apps:
a.js
? commands git:(master) ? cp fe-apps copy-apps
cp: fe-apps is a directory (not copied).
// 2. copy a directory
? commands git:(master) ? cp -rf fe-apps copy-apps
? commands git:(master) ? ls -R
a.js b.js copy-apps fe-apps
./copy-apps:
fe-apps
./copy-apps/fe-apps:
a.js
./fe-apps:
a.js
9.cd
這篇文章肯定沒什么技術(shù)性,因?yàn)殛P(guān)于 cd 真的沒什么可寫的,作為一個(gè)開發(fā)者,誰不熟悉它呢?
也許你是對(duì)的,但我只是想說 cd - 可以返回到你上次訪問的目錄。我認(rèn)為這是一個(gè)好技巧。
10. ls
這是一個(gè)非常常用的命令,它用于顯示文件目錄的內(nèi)容列表。
它至少可以通過 3 種方式使用。
- ls -a:顯示所有文件和目錄(包括以.目錄開頭的)
- ls -A:顯示所有文件和目錄(不包括以.directory開頭的目錄)
- ls -R:顯示所有文件和目錄,如果目錄中有文件,則按順序列出
11.rm
它用于刪除文件或目錄。
rm -i:將目錄下的文件逐個(gè)刪除,刪除前會(huì)詢問是否刪除該文件。
rm -r:一起處理指定目錄及其子目錄下的所有文件(注:不刪除文件。)
rm -f:用于強(qiáng)制刪除文件或目錄。
12.tAIl
我想你一定也有在服務(wù)器上查看日志內(nèi)容的經(jīng)歷,tail絕對(duì)是一個(gè)好幫手。
tail -f filename 會(huì)將 filename 尾部的內(nèi)容顯示在屏幕上,當(dāng)其內(nèi)容發(fā)生變化時(shí),您將在屏幕上看到最新的內(nèi)容。
13.MV
有時(shí)我們想要更改一個(gè)文件或目錄的名稱,或者將其移動(dòng)到另一個(gè)地方,那么我們可以使用 mv 命令。
1.修改文件名
? commands git:(master) ? ls
a.js
? commands git:(master) ? mv a.js xxx.js
? commands git:(master) ? ls
xxx.js
? commands git:(master) ?
2. 將文件移動(dòng)到其他目錄
? commands git:(master) ? ls -R
a.js fe-apps
./fe-apps:
xxx.js
? commands git:(master) ? mv a.js fe-apps
? commands git:(master) ? ls -R
fe-apps
./fe-apps:
a.js xxx.js
14.touch
我經(jīng)常使用 touch 命令來創(chuàng)建新文件,盡管它是用來修改文件或目錄的時(shí)間屬性的。
15.which
如果你想查看某個(gè)命令的具體路徑,可以使用which。
? commands git:(master) ? which node
/Users/dz0400229/.nvm/versions/node/v16.0.0/bin/node
? commands git:(master) ? which npm
/Users/dz0400229/.nvm/versions/node/v16.0.0/bin/npm
? commands git:(master) ? which npx
/Users/dz0400229/.nvm/versions/node/v16.0.0/bin/npx
? commands git:(master) ?
16.mkdir
是的,您以前肯定使用過這個(gè)命令,而且沒什么可說的!
但是mkdir -p dirname確實(shí)是我們很少使用的東西,它是用來做什么的呢?
? commands git:(master) ? ls
a.js b.js copy-apps fe-apps
? commands git:(master) ? mkdir xxx/yyy // You cannot create the yyy directory because the xxx directory does not exist
mkdir: xxx: No such file or directory
? commands git:(master) ? mkdir -p xxx/yyy // `-p` will check if the xxx directory already exists, and create it if it doesn't.
? commands git:(master) ? ls
a.js b.js copy-apps fe-apps xxx
? commands git:(master) ? ls -R
a.js b.js copy-apps fe-apps xxx
./copy-apps:
fe-apps
./copy-apps/fe-apps:
a.js
./fe-apps:
a.js
./xxx:
yyy
./xxx/yyy:
17.whoami
顯示用戶名。
? commands git:(master) ? whoami
dz0400229
總結(jié)
以上就是我今天想與你分享的全部內(nèi)容,如果你覺得有用的話,請(qǐng)記得點(diǎn)贊我,關(guān)注我,并將其文章分享給的朋友,也許能夠幫助到他。