新聞中心
Linux 幾乎無(wú)處不在,不論是服務(wù)器構(gòu)建,還是客戶端開(kāi)發(fā),操作系統(tǒng)的基礎(chǔ)技能對(duì)全棧來(lái)說(shuō)都是必備的,本篇文章重點(diǎn)為大家分享一下Linux中的基礎(chǔ)命令以及使用方法,有需要的小伙伴可以參考一下。

一、復(fù)習(xí)常用命令
命令cd:打開(kāi)文件夾 命令ls:查看目錄下的文件 命令ls -l(簡(jiǎn)寫(xiě)為ll):查看目錄下的文件詳細(xì)信息 命令pwd:查看當(dāng)前位置 命令mkdir:創(chuàng)建文件夾,加參數(shù) -p 可以級(jí)聯(lián)創(chuàng)建文件夾。 命令touch:創(chuàng)建文件 命令vi:編輯文件(類似于使用記事本編輯文件) 命令vim:編輯文件(類似于使用Word編輯文件) 命令>:清空文件內(nèi)容,將正確的重定向內(nèi)容追加在文件結(jié)尾 命令>>:不清空文件內(nèi)容,將正確的內(nèi)容追加在文件結(jié)尾 命令1>:等同于命令> 命令1>>:等同于命令>> 命令2>:清空文件內(nèi)容,將錯(cuò)誤的重定向內(nèi)容追加在文件結(jié)尾 命令2>>:不清空文件內(nèi)容,將錯(cuò)誤的重定向內(nèi)容追加在文件結(jié)尾
二、復(fù)制與刪除
1、復(fù)制/備份文件命令cp 一般在編輯文件內(nèi)容前,都會(huì)將源文件進(jìn)行備份操作。備份后的文件在文件名后+.bak(用于區(qū)分文件)
[root@jsh-01 ~]# cd /usr/local/src/test
[root@jsh-01 test]# ls
1.txt
[root@jsh-01 test]# cp 1.txt 1.txt.bak
[root@jsh-01 test]# ls
1.txt 1.txt.bak
[root@jsh-01 test]# cp 1.txt /usr/local/src
[root@jsh-01 test]# ls /usr/local/src
1.txt mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz test
2、復(fù)制目錄命令cp -r:復(fù)制目錄及目錄下的內(nèi)容。 3、移動(dòng)文件或目錄,命令mv 4、刪除文件,命令rm
[root@jsh-01 test]# ls
1.txt 1.txt.bak 1.txt.bak2 1.txt.bak3 1.txt.bak4
[root@jsh-01 test]# rm 1.txt.bak4
rm: remove regular file ‘1.txt.bak4’? y
[root@jsh-01 test]# ls
1.txt 1.txt.bak 1.txt.bak2 1.txt.bak3
5、刪除目錄,命令rm -r(如果目錄不為空,則會(huì)提示是否刪除目錄下的文件。) 6、強(qiáng)制刪除目錄,命令 rm -rf(不論目錄是否為空,都會(huì)強(qiáng)制刪除)
[root@jsh-01 src]# ls
1.txt mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz test
[root@jsh-01 src]# cp test test.bak
cp: omitting directory ‘test’
[root@jsh-01 src]# cp -r test test.bak
[root@jsh-01 src]# ls
1.txt mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz test test.bak
[root@jsh-01 src]# rm -r test.bak
rm: descend into directory ‘test.bak’? n
[root@jsh-01 src]# rm -r test.bak
rm: descend into directory ‘test.bak’? y
rm: remove regular file ‘test.bak/1.txt.bak’? y
rm: remove regular file ‘test.bak/1.txt’? n
rm: remove directory ‘test.bak’? n
[root@jsh-01 src]# ls
1.txt mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz test test.bak
[root@jsh-01 src]# ls test.bak/
1.txt
[root@jsh-01 src]# rm -rf test.bak
[root@jsh-01 src]# ls
1.txt mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz test
三、fine命令:查找
一般在刪除文件之前先精準(zhǔn)查找,避免誤刪。 命令格式:find 路徑(在哪里找) -type f -name “1.txt” 其中-type 指的是查找的類型。常用的參數(shù)有f 和d。f 即file 文件;d 即directory 目錄。
[root@jsh-01 ~]# ll /usr/local/src
total 308920
-rw-r--r-- 1 root root 60 Dec 17 21:30 1.txt
-rw-r--r-- 1 root root 316320366 Nov 25 19:39 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x 2 root root 4096 Dec 17 22:02 test
[root@jsh-01 ~]# find /usr/ -type f -name "1.txt"
/usr/local/src/test/1.txt
/usr/local/src/1.txt
[root@jsh-01 ~]# find /usr/ -type f -name '1.txt'
/usr/local/src/test/1.txt
/usr/local/src/1.txt
[root@jsh-01 ~]# find /usr/ -type f -name 1.txt
/usr/local/src/test/1.txt
/usr/local/src/1.txt
四、管道符 “|”
一般管道符后面會(huì)緊跟 xargs 命令,用于將管道符前面的輸出結(jié)果轉(zhuǎn)換為命令行。 管道符作用:將管道符前面命令的結(jié)果傳遞給后面的命令。
[root@jsh-01 ~]# echo 123456789 > /usr/local/src/1.txt
[root@jsh-01 ~]# echo 666666666 > /usr/local/src/test/1.txt
[root@jsh-01 ~]# find /usr/local/src/ -type f -name 1.txt |xargs cat
666666666
123456789
[root@jsh-01 ~]# find /usr/ -type f -name 1.txt |xargs ls -l
-rw-r--r-- 1 root root 10 Dec 20 20:37 /usr/local/src/1.txt
-rw-r--r-- 1 root root 10 Dec 20 20:38 /usr/local/src/test/1.txt
五、過(guò)濾命令 grep
在文件中找到(過(guò)濾)你想要的內(nèi)容并輸出。例如:grep “666” 1.txt
grep -v 排除。在文件中找到你要排除的內(nèi)容,顯示排除后的內(nèi)容。
[root@jsh-01 test]# cat 1.txt
666666666
[root@jsh-01 test]# grep "5" 1.txt
[root@jsh-01 test]# grep -v "5" 1.txt
文章題目:Linux中基礎(chǔ)命令以及使用方法
網(wǎng)址分享:http://m.5511xx.com/article/dhshcoh.html


咨詢
建站咨詢
