一、Linux簡要介紹
-
Linux命令基礎
-
Linux命令幫助
- 目錄與文件基本操作
Linux家族
- Redhat 紅帽 三個認證 (開源但是不免費)---》社區(系統開發者)---》Centos(服務器端)
- Ubuntu 最好的客戶端系統,開源純免費(軟件開發人羣)
- Debian ---》kali Linux(專用工具資源佔用很少) 樹莓派
- suse Linux---》ISP(電信,移動,聯通) 定製版
shell——Linux系統的一種特殊程序——“翻譯官”
用戶登錄Linux系統時就自動加載一個shell程序,Bash是Linux系統中默認使用的shell程序
Linux的內核是由C語言開發出來的(面向過程的語言),應用程序是用c++開發
編譯器—— gcc gcc-c++ jdk(Java的編譯器)Python的編譯器就是Python2/3
源碼文件———》(編譯器)——》執行文件
Linux命令的分類
-
內部命令
- 外部命令
通用的命令行使用格式:
命令字 [選項] [參數] (對應於操作、功能、操作對象)
- -單個字符的組合
- -- 單詞
對root@localhost ~]# 的介紹
- root ——當前用戶
- @ ——分隔符
- localhost ——主機名字
- ~ ——當前目錄位置
- #——管理員
- $ ——普通用戶
路徑簡介
絕對路徑:例如——/etc/sysconfig/network-scripts/
相對路徑(以當前所在位置的路徑):例如——sysconfig/
家目錄:管理員(/root) 普通用戶(/home)
根目錄: /
二、Linux命令集(結合實例)
cd:切換工作目錄
pwd:查看當前所在的絕對目錄路徑
[root@lokott ~]# cd /etc/sysconfig/network-scripts/ //進入絕對路徑下的文件夾
[root@lokott network-scripts]# pwd //顯示當前所在的目錄的絕對路徑
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd - //返回上次進入的目錄命令,即cd /etc/sysconfig/network-scripts/
/root
[root@lokott ~]# cd -
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd .. //返回上層目錄
[root@lokott sysconfig]# cd ../../ //返回上兩層目錄
[root@lokott /]#
ls:顯示當前目錄的內容
- -l 顯示文件詳細信息
- -a 查看隱藏文件
- -A 查看除了. .. 的隱藏文件
- -d 顯示本目錄的信息
- -h 友好形式顯示帶有單位的信息
- -R 遞歸顯示
- -- color 以顏色區分文件類型
- 黑色(數據文件)
- 藍色(目錄)
- 紅色(壓縮包)
- 綠色(執行文件/命令文件/腳本)
- 天藍色(鏈接文件)
- 黃的(設備文件/磁盤文件)
[root@lokott ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg note shell 公共 模板 視頻 圖片 文檔 下載 音樂 桌面
[root@lokott ~]# cd shell/
[root@lokott shell]# ls
1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello
[root@lokott shell]# ls -a
. .. 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello
[root@lokott shell]# ls -A
1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello
[root@lokott shell]# ls -l
總用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root 18 10月 30 13:53 hello
[root@lokott shell]# ls -R
.:
1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello
./hello:
0.sh
[root@lokott shell]# ls -d
.
[root@lokott shell]# ls -ah
. .. 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello
[root@lokott shell]# ls -lR
.:
總用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root 18 10月 30 13:53 hello
./hello:
總用量 0
-rwxrwxrwx. 1 root root 0 10月 30 13:53 0.sh
[root@lokott shell]#
alias:給命令取一個別名
du:統計目錄及文件空間佔用情況
- -a
- -h 友好顯示
- -s
which: 查找命令存放目錄
- 搜索範圍由環境變量PATH決定
mkdir:創建目錄
- -p遞歸嵌套創建
touch:創建文件
[root@lokott shell]# alias c='clear' //clear是表示清屏相當於Ctrl+l的操作
[root@lokott shell]# which c
alias c='clear'
/usr/bin/clear
[root@lokott shell]# which clear
/usr/bin/clear
[root@lokott shell]# mkdir linux
[root@lokott shell]# ls
1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello linux
[root@lokott shell]# touch 0.sh
[root@lokott shell]# ls
0.sh 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh hello linux
[root@lokott shell]# du -ah
4.0K ./1.sh
4.0K ./2.sh
4.0K ./3.sh
4.0K ./4.sh
4.0K ./5.sh
4.0K ./6.sh
0 ./hello/0.sh
0 ./hello
0 ./linux
0 ./0.sh
24K .
[root@lokott shell]# du -sh
24K .
[root@lokott shell]# du -as //不可以設置選項爲-as(h)
du: 不能既顯示總用量,同時又顯示每個項目
Try 'du --help' for more information.
[root@lokott shell]#
[root@lokott shell]# mkdir -p /2019/2018/2017 //連續創建文件夾
[root@lokott shell]# cd /2019/2018/2017/
[root@lokott 2017]# touch {1..10}.txt //..表示創建連續10個名爲1-10的txt文件
[root@lokott 2017]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
下面的操作過程中會出現文件節點(inode值):文件在磁盤中存儲的標識序列
ln:創建鏈接文件(類似於Windows系統的快捷方式)
- 軟鏈接:相當於快捷方式 -s
- 硬鏈接:給文件取別名(無法創建硬鏈接文件夾)
[root@lokott shell]# ln -s 1.sh 8.sh
[root@lokott shell]# ln 1.sh 10.sh
[root@lokott shell]# ls -l
總用量 28
-rwxrwxrwx. 1 root root 0 10月 30 13:59 0.sh
-rwxr-xr-x. 2 root root 111 10月 25 19:10 10.sh //硬鏈接
-rwxr-xr-x. 2 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root 26 10月 25 19:37 6.sh
lrwxrwxrwx. 1 root root 4 10月 30 14:07 8.sh -> 1.sh //軟鏈接
drwxr-xr-x. 2 root root 18 10月 30 13:53 hello
drwxr-xr-x. 2 root root 6 10月 30 13:59 linux
[root@lokott shell]# ls -ih //顯示文件節點值的大小
19397655 0.sh 20564913 10.sh 20564913 1.sh 20564915 2.sh 20564917 3.sh 20564916 4.sh 20564918 5.sh 20564919 6.sh 19134334 8.sh 20565286 hello 35183604 linux
//上面文件左邊的就是該文件的文件節點(inode值)軟鏈接與源文件的文件節點是非一致的,而硬鏈接的文件節點與源文件是一致的
cp :複製文件或目錄 源|目標
- -f 不詢問
- -i 詢問是否覆蓋原有
- -p 保持源文件的用戶權限不變,權限高用戶使用
- -r 遞歸複製
rm:刪除
- -i:默認提醒
- -rf :強制遞歸刪除
mv:移動文件或目錄
[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh
[root@lokott hello]# cp ../5.sh .
[root@lokott hello]# ls
0.sh 5.sh
[root@lokott hello]# cp -i ../5.sh .
cp:是否覆蓋"./5.sh"? yes
[root@lokott hello]# cp -f ../5.sh . //猜測被alias了
cp:是否覆蓋"./5.sh"? y
[root@lokott hello]#
[root@lokott hello]# which cp //查看cp命令果然是被alias更改了
alias cp='cp -i'
/usr/bin/cp
[root@lokott hello]# cp -r ../linux/ . //遞歸複製上層路徑linux文件夾的所有內容到當前路徑(目前無內容)
[root@lokott hello]# ls
0.sh 5.sh linux
[root@lokott hello]# cd linux/
[root@lokott linux]# ls
[root@lokott linux]# mkdir 2020 //創建文件夾
[root@lokott linux]# ls
2020
[root@lokott linux]# cd 2020/
[root@lokott 2020]# touch 2.txt //創建文件
[root@lokott 2020]# cd ../../
[root@lokott hello]# ls
0.sh 5.sh linux
[root@lokott hello]# mv linux/ ../ //移動文件夾
mv:是否覆蓋"../linux"? y
[root@lokott hello]# cd ..
[root@lokott shell]# ls
0.sh 10.sh 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh 8.sh hello linux
[root@lokott shell]# ls -l linux/
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:15 2020
[root@lokott shell]# cp -r linux/ hello/ //遞歸複製linux文件夾的所有內容到hello文件夾中
[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh 5.sh linux
[root@lokott hello]# ls -l linux/
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020
[root@lokott hello]# ls -lR linux/ //遞歸查看拷貝過來的文件夾的信息
linux/:
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020
linux/2020:
總用量 0
-rw-r--r--. 1 root root 0 10月 30 14:16 2.txt
通配符
-
?表示一個
- *表示多個
find:查找文件或目錄
find 【查找範圍】【選項】[表達式]
- -name:根據目標名字查找
- -type:根據文件類型查找
- -size:根據大小查找
- -user:根據文件的用戶所有者查找
[root@lokott hello]# find . -name "*.sh" //*號表示通配符
./0.sh
./5.sh
[root@lokott hello]# find . -type f
./0.sh
./5.sh
./linux/2020/2.txt
[root@lokott hello]# find . -size -10k
.
./0.sh
./5.sh
./linux
./linux/2020
./linux/2020/2.txt
./ifcfg-ens33
[root@lokott hello]# find . -size -10k | du -ah
0 ./0.sh
4.0K ./5.sh
0 ./linux/2020/2.txt
0 ./linux/2020
0 ./linux
4.0K ./ifcfg-ens33
8.0K .
centos7系統啓動的命令清單
1. init 0 關機
2. init 1 單用戶模式(系統維護,破解密碼)
3. init 2 多用戶模式無網絡
4. init 3 多用戶模式有網絡 *
5. init 4 保留
6. init 5多用戶模式圖形化界面有網絡
7. init 6 重啓 (reboot)