1、什么是Linux?
是一種免費使用和自由傳播的類UNIX操作系統,其內核由林納斯·本納第克特·托瓦茲于1991年10月5日首次發布,它主要受到Minix和Unix思想的啟發,是一個基于POSIX的多用戶、多任務、支持多線程和多CPU的操作系統。它能運行主要的Unix工具軟件、應用程序和網絡協議。它支持32位和64位硬件。
2、連接linux比較好用的工具:
一直在用FinalShell,不僅可以敲命令,還有圖形化界面可操作
官網下載連接為:點擊下載
3、登錄后你在的位置?
一般登陸后,你的位置位于自己的主目錄中。當不確定自己在哪,迷路時,可使用 pwd 顯示當前目錄
[root@ecs-yewuyingyong ~]# pwd
/root
4、文件的絕對路徑和相對路徑
絕對文件路徑:描述了在虛擬機目錄結構中該目錄的確切位置,以虛擬目錄根目錄開始,相當于目錄全名。
以正斜杠(/) 開始,比如 /usr/local
相對文件路徑:允許用戶執行一個基于當前位置的目標文件路徑。
比如,當前在 /usr/local 下
[root@ecs-yewuyingyong ~]# cd /usr/local
[root@ecs-yewuyingyong local]# ls
bin etc games include lib lib64 libexec mysql-8.0.33 mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz nginx redis sbin share src tomcat-gwc tomcat-php var web
[root@ecs-yewuyingyong local]# cd bin
[root@ecs-yewuyingyong bin]#
5、如何切換目錄
語法:cd destination
destination 相對文件路徑或者絕對文件路徑
/ 稱為根目錄
. 稱為當前目錄
… 稱為當前目錄的上級目錄
cd …: 返回上級目錄
cd ~:進入用戶家目
cd -:返回最近訪問目錄
6、如何查看目錄中的文件
ls 命令會用最基本的形式顯示當前目錄下的文件和和目錄:
[root@ecs-yewuyingyong nginx]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
可以用 ls -F來區分哪些是目錄(目錄帶/),哪些是文件(文件不帶/)
[root@ecs-yewuyingyong nginx]# ls -F
auto/ CHANGES CHANGES.ru conf/ configure* contrib/ html/ LICENSE Makefile man/ objs/ README src/
-a 列出目錄下的所有文件,包括以 . 開頭的隱含文件。
-l 列出文件的詳細信息。
-r 對目錄反向排序。
-t 以時間排序。
-R 列出所有子目錄下的文件。(遞歸)
7、創建文件或目錄
(1) 創建文件:touch 文件名
批量創建文件:touch 文件名 文件名
[root@ecs-yewuyingyong temp]# touch a.txt
[root@ecs-yewuyingyong temp]# ls
a.txt
[root@ecs-yewuyingyong temp]# touch b.txt c.txt
[root@ecs-yewuyingyong temp]# ls
a.txt b.txt c.txt
(1) 創建目錄:mkdir 目錄名
批量創建目錄:mkdir 文件名 目錄名
[root@ecs-yewuyingyong temp]# mkdir me
[root@ecs-yewuyingyong temp]# ls
me
[root@ecs-yewuyingyong temp]# mkdir you she
[root@ecs-yewuyingyong temp]# ls
me she you
8、刪除文件或目錄
語法:rm destination
可帶以下命令
-f: 不會出現警告信息,強制刪除
-i: 會出現提示刪除信息,詢問是否刪除
-r: 遞歸刪除,常用在目錄下的刪除,就是把目錄下的東西全刪了
[root@ecs-yewuyingyong temp]# rm -r me
rm:是否進入目錄"me"? y
rm:是否刪除普通空文件 "me/a.txt"?y
rm:是否刪除目錄 "me"?y
rm 不能刪除有文件的目錄,需要遞歸刪除。
9、重新命名文件,移動文件
語法:mv source target
(1) 重命名:
[root@ecs-yewuyingyong temp]# ls
redis
[root@ecs-yewuyingyong temp]# mv redis redis3.6
[root@ecs-yewuyingyong temp]# ls
redis3.6
(2) 移動文件:
新建 it 目錄,把 java 目錄移動到 it 目錄下
[root@ecs-yewuyingyong temp]# ls
java
[root@ecs-yewuyingyong temp]# mkdir it
[root@ecs-yewuyingyong temp]# mv java it
[root@ecs-yewuyingyong temp]# ls -R
.:
it
./it:
java
./it/java:
10、復制文件
語法:cp source target
[root@ecs-yewuyingyong temp]# ls
a.txt it
[root@ecs-yewuyingyong temp]# cp a.txt it
[root@ecs-yewuyingyong temp]# cd it
[root@ecs-yewuyingyong it]# ls
a.txt java
當然也可以帶上以下命令
-p 帶上文件的屬性一起賦值
-r 持續遞歸賦值,用于目錄的復制行為
-f 強制復制
-i 若目標文檔已經存在,會詢問是否覆蓋
注:如果重復復制,覆蓋會默認進行詢問,如果想強制執行不詢問: cp -r 路徑
11、壓縮文件和解壓文件
比如以 .gz 的格式舉例。
壓縮語法:gzip destination
解壓語法:gunzip destination
[root@ecs-yewuyingyong temp]# ls
a.txt it
[root@ecs-yewuyingyong temp]# gzip a.txt
[root@ecs-yewuyingyong temp]# ls
a.txt.gz it
[root@ecs-yewuyingyong temp]# gunzip a.txt.gz
[root@ecs-yewuyingyong temp]# ls
a.txt it
12、如何查看命令歷史記錄?
history 命令可以展示你用過的命令的歷史記錄
13、列出已經安裝的包、安裝軟件、更新軟件、卸載
列出已經安裝的包:yum list installed
安裝軟件:yum install package_name
更新軟件:yum update package_name
卸載軟件:yum remove package_name //只刪除軟件包,保留數據文件和配置文件
如果不希望保留數據文件和配置文件,可以執行:yum erase package_name
14、源碼安裝通常的套路
tar -zxvf xx.gz //解壓安裝包
cd xx
./configure
make
make install
15、vim 編輯器的基本操作
語法:vim [文件名]
功能 :能打開一個文件,如果不存在就會創建文件.
注意事項 :
(1) 第一次進入的時候是普通模式.
(2) 想要編輯,要按下 i 進入插入模式
(3) 當把內容寫完之后,按 Esc 退出插入模式
(4) 輸入英文下的冒號 :然后根據情況輸入5至7的字符
(5) q 如果未修改緩沖區數據,按 Enter 鍵退出。
(6) q! 取消所有對緩沖區數據的修改并按 Enter 鍵退出
(7) wq 將緩沖區數據保存到文件并按 Enter 鍵退出
16、查看設備還有多少磁盤空間
dm 可以查看所有已掛載在磁盤的使用情況,-m 用兆字節
[root@ecs-yewuyingyong ~]# df -m
文件系統 1M-塊 已用 可用 已用% 掛載點
devtmpfs 15996 0 15996 0% /dev
tmpfs 16006 0 16006 0% /dev/shm
tmpfs 16006 1 16005 1% /run
tmpfs 16006 0 16006 0% /sys/fs/cgroup
/dev/sda1 100664 53539 42912 56% /
tmpfs 3202 0 3202 0% /run/user/0
17、查看當前系統中的進程
語法:ps [參數]
例如查詢所在系統 nginx 的進程
[root@ecs-yewuyingyong ~]# ps aux|grep nginx
root 3744 0.0 0.0 20712 1520 ? Ss 2023 0:00 nginx: master process /usr/local/web/nginx-iot/sbin/nginx -c /usr/local/web/nginx-iot/conf/nginx.conf
nobody 16489 0.0 0.0 21380 2388 ? S 6月25 2:42 nginx: worker process
root 16857 0.0 0.0 112832 988 pts/1 S+ 21:25 0:00 grep --color=auto nginx
root 18085 0.0 0.0 20564 660 ? Ss 5月24 0:00 nginx: master process ./nginx
nobody 18086 0.0 0.0 21328 2076 ? S 5月24 14:39 nginx: worker process
root 18260 0.0 0.0 20708 1560 ? Ss 5月24 0:00 nginx: master process ./nginx
root 24103 0.0 0.0 21612 2480 ? S 5月15 1:27 nginx: worker process
18、netstat 命令,查看當前的網絡狀態
netstat -anp
netstat -anp | grep “進程名”
netstat -anp | grep “端口號”
查看端口是否被占用,用下面命令
[root@ecs-yewuyingyong ~]# netstat ntulp|grep 8080 //查詢8080端口是否被占用
19、搜索查詢匹配的文件
語法 find 「搜索范圍,就是目錄」「選項」
從指定目錄向下遞歸的遍歷各個子目錄,將滿足條件的文件或目錄顯示在終端
-name 按照指定的文件名查找
-user 按照指定的用戶進行查找
-size 按照文件大小進行查找
? +10M 表示超過10M的
[root@ecs-yewuyingyong local]# find -name nginx
./nginx
./nginx/objs/nginx
./web/nginx-iot/sbin/nginx
./web/nginx-php/screen2.0/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.7/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.8/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.3/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.1/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.2/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.4/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.9/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/sbin/nginx
./web/nginx-gwc/sbin/nginx
20、如何查看當前主機名,如何修改
[root@ecs-yewuyingyong ~]# hostname //查看當前主機名
ecs-yewuyingyong
[root@ecs-yewuyingyong ~]# hostname ecs-guanquyingyong//修改當前主機名
[root@ecs-yewuyingyong ~]# hostname //查看當前主機名
ecs-guanquyingyong
大家知道一般來講命令重啟就會失效,目前基本上用的centos7的比較多,兩種方式可以支持重啟生效。
(1) 命令
[root@ecs-yewuyingyong ~]# hostnamectl set-hostname leebao
[root@ecs-yewuyingyong ~]# hostname
leebao
[root@leebao ~]#
(2) 修改配置文件:/etc/hostname
[root@leebao ~l# vim /etc/hostname
以上就是最常用的一些命令,另外使用 tab 鍵可以補全命令