Linux使用教程

2021-10-09 19:45:26 字數 1923 閱讀 5931

// 建立檔案

* 建立目錄:mkdir

-p 建立多層目錄

$ mkdir -p demo/file

* 建立檔案:touch

$ touch a.txt

// 顯示檔案

* 顯示當前檔案:ls

-l 顯示檔案的詳細資訊

-a 顯示所有檔案

-h 按照易讀性顯示檔案大小

-i 顯示節點號

$ ls -a

// 檢視單個檔案

* 有加號代表從某行開始,沒有加號則是多少行

tail -n 1000:顯示最後1000行

tail -n +1000:從1000行開始顯示,顯示1000行以後的

* 顯示filename檔案的3000-3999行

cat filename | tail -n +3000 | head -n 1000

* 顯示filename檔案的1000-3000行

cat filename | head -n 3000 | tail -n +1000

// 比較檔案

diff a.txt b.txt

// 搜尋

* 搜尋單個檔案( / 表示從根目錄搜尋 . 表示從當前目錄搜尋)

find -name

$ find / -name a.txt

* 搜尋字串test;-r:遞迴搜尋,-n:顯示行號,file:表示在file檔案中搜尋

grep -rn "test" file

* 搜尋字串 grep -r: 遞迴,-n: 顯示行號 -i: 忽略字串大小寫;wc -l : 統計行數

$ grep -rni "this" | wc -l

* 正則搜尋 -p:正則;\d:可以搜尋數字0-9

$ grep -p "a\d" file

// 排序

* 順序排不加r

$ ls -lrt

// 單個檔案內部處理

* 刪除檔案中每行開頭的前5個字元,並重定向到new_demo.txt, 不修改原始檔demo.txt

demo.txt:

this is ubuntu demo1 text

this is ubuntu demo2 text

new_demo.txt:

is ubuntu demo1 text

is ubuntu demo2 text

$ sed 's/^.\//g' demo.txt > new_demo.txt

* 在第1行之後新增1行 add one line after one line

demo.txt:

this is ubuntu demo1 text

this is ubuntu demo2 text

new_demo.txt:

this is ubuntu demo1 text

add one line after one line

this is ubuntu demo2 text

$ sed -e 1a\add\ one\ line\ after\ one\ line demo.txt > new_demo.txt

* 更改檔案許可權:chmod

-r 改變多層許可權

$ chmod -r 777 /home/demo

vim分為一般模式,編輯模式,命令列模式。使用命令vim file(檔名),開啟檔案進入一般模式

* 命令列模式:顯示行號

$ :set nu

* 命令列模式:跳轉到某一行(例如跳轉到第10行)

$ :10

* 命令列模式:搜尋字串a

$ /a

* 檢視下/上乙個匹配

鍵盤按下n/n

Linux之Tmux使用教程

tmux中有3種概念,會話,視窗 window 窗格 pane 會話有點像是tmux的服務,在後端執行,我們可以通過tmux命令建立這種服務,並且可以通過tmux命令檢視,附加到後端執行的會話中。乙個會話可以包含多個視窗,乙個視窗可以被分割成多個窗格 pane tmux的安裝方法很簡單,可直接通過a...

linux 下git使用教程

新增所有新增檔案 git add 提交所有修改,包括刪除,新增,修改 git add a git add all 檢視狀態 git status 新增乙個檔案 git add readme git commit m add readme git push u origin master 刪除檔案 g...

linux使用入門教程

說實話在第一次接觸linux系統時,確實很不習慣,尤其是在用了多年的windows後,可是專案需要又不得不頂著頭皮去學習了,下面就自己一點點摸索做下總結,以供後面學習。1 安裝linux系統 由於linux的開源性,我們可以有很多選擇,常見的有ubuntu,centos,fedora,debian ...