1、 Linux 基礎命令

1. 文件相關

ls -al  # 
查看當前目錄所有文件夾包含隱藏文件並格式化

ls      # 查看當前目錄文件

rm      # 刪除文件

pwd     # 查看當前目錄路徑

2. Linux 創建文件,並進行輸入,修改,移動文件操作

創建hello.txt

touch hello.txt

打開hello.txt

vi hello.txt # 進入並修改文件

i            # 修改hello.txt文件內容

shrift + A   # 修改文件並光標置於一行開頭位置

esc :wq       # 保存並退出文件

文件相關操作

cat hello.txt            # 查看文件內容

cp hello.txt hello2.txt  # 複製文件

mv hello2.txt hello3.txt # 移動或者重命名文件

rm hello2.txt            # 刪除文件

man rm                   # 查看命令使用方式

echo 'hello' > test.txt  # 把hello內容覆蓋之前的內容

>  表示重定向,如果文件不存在,則創建,追加內容嗎?未驗證

>> 表示重定向,如果文件不存在,則創建,覆蓋內容嗎?未驗證

未完待續

3、 Linux 快捷鍵

清除文本

ctrl + L 

跳過正在輸入的命令行,直接進入下一行代碼,而不執行未輸入完成的代碼

ctrl + C 

進入文本編輯後 i進入可編輯狀態 ESC :wq 保存並退出 w表示保存,q表示退出

vi [filepath] 

進入編輯模式,且進入行尾

shift + a

跳到命令行最前面

ctrl + A

調到命令行結尾

ctrl + E

mkdir mydir && cd mydir

一個>替換原文件,兩個追加原文件或者創文件

echo ‘wwwww’ >/>> a.txt

vi hello.txt

dd 刪除某一行數據
:set number
:1,5d刪除一到五行的數據

3. Linux 命令之刪除命令

在Linux下刪除文件用rm命令,具體用法如下:

rm [選項] 文件

選項說明:

參數 參數全名稱 詳細內容
-f -force 忽略不存在的文件,強制刪除,無任何提示
-i –interactive 進行交互式地刪除
-r or -R –recursive 遞歸式地刪除列出的目錄下的所有目錄和文件
-v –verbose 詳細顯示進行的步驟
     

命令實例:

1、常規刪除a.txt文件

[root]# rm a.txt

2、強行刪除file.log文件

[root]# rm -f file.log

3、刪除dirname目錄下的所有東西

[root]# rm -R dir dirname
rm -rf dir dirname

4、刪除以 -f 開頭的文件

[root]# touch ./-f
[root]# ls ./-f
./-f
[root]# rm ./-f

或者使用

[root]# touch -- -f 
[root]# ls -- -f 
-f
[root]# rm -- -f   

:wq 保存文件
文件中 dd刪除一行

4.Which 命令

查看客戶端安裝位置

which git or which docker

卸載軟件

查看想要卸載的軟件,以 completion 爲例

rpm -qa | grep completion

卸載命令

rpm -e --nodeps bash-completion-2.1-6.el7.noarch
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章