Linux操作系統常用命令

目錄

 

日常操作命令

文件目錄操作

查找命令

文件權限操作


日常操作命令

查看當前所在的工作目錄的全路徑,完整路徑。

[root@xinxin001 dubbo-admin-tomcat]# pwd
/app/runtime/dubbo-admin-tomcat

查看當前系統的時間

[root@xinxin001 /]# date
2018年 10月 27日 星期六 14:18:04 CST
[root@xinxin001 /]# date +%Y-%m-%d
2018-10-27

顯示當前時間減去一天的時間、減去一個月的時間、減去一年的時間。

[root@xinxin001 /]# date +%Y-%m-%d  --date="-1 day" 
2018-10-26
[root@xinxin001 /]# date +%Y-%m-%d  --date="-1 month" 
2018-09-27
[root@xinxin001 /]# date +%Y-%m-%d  --date="-1 year"                                                       
2017-10-27  

修改設置系統時間。

[root@xinxin001 /]# date -s "2017-10-01 11:12:13"
2017年 10月 01日 星期日 11:12:13 CST

查看有哪些用戶登錄到了服務器,有誰在線。

[root@xinxin001 ~]# who
root     :0           2018-10-27 14:14 (:0)
root     pts/0        2018-10-27 14:14 (:0)
root     pts/1        2018-10-27 14:14 (:0)
admin    pts/2        2017-10-01 11:31 (:1)
admin    :1           2017-10-01 11:31 (:1)
admin    pts/3        2017-10-01 11:31 (:1)

查看最近用戶的登錄歷史記錄。

[root@xinxin001 ~]# last
admin    pts/3        :1               Sun Oct  1 11:31   still logged in   
admin    pts/2        :1               Sun Oct  1 11:31   still logged in   
admin    :1           :1               Sun Oct  1 11:31   still logged in   
root     pts/2        :0               Thu Jul 28 16:12 - 16:12  (00:00)    
root     pts/1        :0               Sat Oct 27 14:14   still logged in   
root     pts/0        :0               Sat Oct 27 14:14   still logged in   
root     :0           :0               Sat Oct 27 14:14   still logged in   
reboot   system boot  3.10.0-862.el7.x Sat Oct 27 14:13 - 11:33 (-391+-2:-39
root     pts/1        :0               Thu Oct 18 23:26 - down   (01:15)    
root     pts/0        :0               Thu Oct 18 23:26 - down   (01:15)    
root     :0           :0               Thu Oct 18 23:26 - down   (01:16)    
reboot   system boot  3.10.0-862.el7.x Thu Oct 18 23:02 - 00:42  (01:40)    
root     pts/1        :0               Mon Oct 15 22:33 - 00:22  (0

 

使用root用戶關閉服務器,關機。

立刻關機命令。

[root@xinxin001 /]# shutdown -h now

 其他關機命令,不安全,不建議使用。

[root@xinxin001 /]# halt
[root@xinxin001 /]# poweroff
[root@xinxin001 /]# init 0

1分鐘後關機。

[root@xinxin001 /]# shutdown -h +1
Shutdown scheduled for 六 2018-10-27 15:13:49 CST, use 'shutdown -c' to cancel.
[root@xinxin001 /]# 
Broadcast message from root@xinxin001 (Sat 2018-10-27 15:12:49 CST):

The system is going down for power-off at Sat 2018-10-27 15:13:49 CST

10分鐘後關機。

[root@xinxin001 /]# shutdown -h +10
Shutdown scheduled for 六 2018-10-27 15:28:00 CST, use 'shutdown -c' to cancel.
[root@xinxin001 /]# 
Broadcast message from root@xinxin001 (Sat 2018-10-27 15:18:00 CST):

The system is going down for power-off at Sat 2018-10-27 15:28:00 CST

通知在線使用者關機時間,通知10分鐘後關機。

[root@xinxin001 /]# shutdown +10 "The machine will shutdown"
Broadcast message from root@xinxin001 (Sat 2018-10-27 15:43:11 CST):

The machine will shutdown
The system is going down for power-off at Sat 2018-10-27 15:51:11 CS

設置在指定時間關機。

[root@xinxin001 /]# shutdown -h 11:12
Shutdown scheduled for 日 2018-10-28 11:12:00 CST, use 'shutdown -c' to cancel

使用crontab定時任務關機。
crontab格式,星號分別代表分、時、日、月、周:
*  *  *  *  *  command
分 時 日 月 周  命令

/etc/crontab
# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

編輯定時任務。
crontab -e
添加保存定時任務內容,每天下午16點25分定時任務執行一條關機命令,關機命令將在16點30分定時關機。

25 16 * * * /sbin/shutdown -h 16:30

查看定時任務列表。

[root@xinxin001 ~]# crontab -l

查看定時任務執行情況。

[root@xinxin001 /]# tail -f /var/log/cron
Oct 27 16:18:50 xinxin001 crontab[3015]: (root) BEGIN EDIT (root)
Oct 27 16:19:34 xinxin001 crontab[3015]: (root) REPLACE (root)
Oct 27 16:19:34 xinxin001 crontab[3015]: (root) END EDIT (root)
Oct 27 16:19:37 xinxin001 crontab[3017]: (root) LIST (root)
Oct 27 16:20:01 xinxin001 crond[1181]: (root) RELOAD (/var/spool/cron/root)
Oct 27 16:20:02 xinxin001 CROND[3023]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 27 16:20:02 xinxin001 CROND[3022]: (root) CMD (/sbin/shutdown -h 16:21)
Oct 27 16:21:00 xinxin001 crond[1181]: (CRON) INFO (Shutting down)
Oct 27 16:30:42 xinxin001 crond[1181]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 1% if used.)
Oct 27 16:30:47 xinxin001 crond[1181]: (CRON) INFO (running with inotify sup

取消定時關機。

[root@xinxin001 /]# sudo shutdown -c
[root@xinxin001 /]# 
Broadcast message from root@xinxin001 (Sat 2018-10-27 16:34:46 CST):

The system shutdown has been cancelled at Sat 2018-10-27 16:35:46 CST

 

使用root用戶立刻重啓服務器。

[root@xinxin001 ~]# reboot

 或

[root@xinxin001 ~]# shutdown -r now

 清屏,清除終端窗口所有內容。

[root@xinxin001 /]# clear

退出當前進程,ctrl+c快捷鍵。
掛起當前進程,ctrl+z快捷鍵,進程會掛起到後臺。
讓進程在後臺繼續執行,bg jobid。
讓進程回到前臺,fg jobid。

使用echo在終端窗口打印輸出信息。
定一個變量a,值爲hi, linux command。使用echo輸出變量a的值。
使用echo輸出信息This is an output message。

[root@xinxin001 /]# a="hi, linux command"
[root@xinxin001 /]# echo $a
hi, linux command
[root@xinxin001 /]# echo This is an output message
This is an output message
[root@xinxin001 /]# echo 這是一條輸出信息
這是一條輸出信息


文件目錄操作

查看目錄信息。
查看目錄下的文件和文件夾,ls。
查看app文件夾下的文件和文件夾,ls /app。
查看隱藏文件,ls -a。
以詳細列表方式查看目錄下文件和文件夾,ls -l 或者 ll。

[root@xinxin001 /]# ls
app   bin   dev  home  lib64  mnt  proc  run   srv  tmp                  usr  zookeeper.out
app1  boot  etc  lib   media  opt  root  sbin  sys  tomcat-webapps-ROOT  var
[root@xinxin001 /]# ls /
app   bin   dev  home  lib64  mnt  proc  run   srv  tmp                  usr  zookeeper.out
app1  boot  etc  lib   media  opt  root  sbin  sys  tomcat-webapps-ROOT  var
[root@xinxin001 /]# ls app
data  logs  runtime  services  soft
[root@xinxin001 /]# 
[root@xinxin001 /]# 
[root@xinxin001 /]# ls -a
.   app   bin   dev  home  lib64  mnt  proc  run   srv  tmp                  usr  zookeeper.out
..  app1  boot  etc  lib   media  opt  root  sbin  sys  tomcat-webapps-ROOT  var
[root@xinxin001 /]# ls -al
總用量 48
dr-xr-xr-x.  20 root root 4096 10月 15 23:35 .
dr-xr-xr-x.  20 root root 4096 10月 15 23:35 ..
drwxr-xr-x.   7 root root   73 10月 14 20:19 app
drwxr-xr-x.   6 root root   61 9月  25 01:00 app1
lrwxrwxrwx.   1 root root    7 9月  24 05:41 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 9月  24 06:05 boot
drwxr-xr-x.  20 root root 3300 10月 27 16:30 dev
drwxr-xr-x. 135 root root 8192 10月 27 16:46 etc
drwxr-xr-x.   3 root root   19 9月  24 05:52 home
lrwxrwxrwx.   1 root root    7 9月  24 05:41 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 9月  24 05:41 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   3 root root   16 9月  24 05:46 opt
dr-xr-xr-x. 190 root root    0 10月 27 16:30 proc
dr-xr-x---.  22 root root 4096 10月 27 16:33 root
drwxr-xr-x.  40 root root 1180 10月 27 16:30 run
lrwxrwxrwx.   1 root root    8 9月  24 05:41 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 10月 27 16:30 sys
drwxrwxrwt.  24 root root 4096 10月 27 16:33 tmp
drwxr-xr-x.   3 root root 4096 10月 15 23:35 tomcat-webapps-ROOT
drwxr-xr-x.  13 root root  155 9月  24 05:41 usr
drwxr-xr-x.  21 root root 4096 9月  24 06:05 var
-rw-r--r--.   1 root root 4331 10月 27 16:30 zookeeper.out
[root@xinxin001 /]# ls -l
總用量 40
drwxr-xr-x.   7 root root   73 10月 14 20:19 app
drwxr-xr-x.   6 root root   61 9月  25 01:00 app1
lrwxrwxrwx.   1 root root    7 9月  24 05:41 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 9月  24 06:05 boot
drwxr-xr-x.  20 root root 3300 10月 27 16:30 dev
drwxr-xr-x. 135 root root 8192 10月 27 16:46 etc
drwxr-xr-x.   3 root root   19 9月  24 05:52 home
lrwxrwxrwx.   1 root root    7 9月  24 05:41 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 9月  24 05:41 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   3 root root   16 9月  24 05:46 opt
dr-xr-xr-x. 190 root root    0 10月 27 16:30 proc
dr-xr-x---.  22 root root 4096 10月 27 16:33 root
drwxr-xr-x.  40 root root 1180 10月 27 16:30 run
lrwxrwxrwx.   1 root root    8 9月  24 05:41 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 10月 27 16:30 sys
drwxrwxrwt.  24 root root 4096 10月 27 16:33 tmp
drwxr-xr-x.   3 root root 4096 10月 15 23:35 tomcat-webapps-ROOT
drwxr-xr-x.  13 root root  155 9月  24 05:41 usr
drwxr-xr-x.  21 root root 4096 9月  24 06:05 var
-rw-r--r--.   1 root root 4331 10月 27 16:30 zookeeper.out
[root@xinxin001 /]# ll
總用量 40
drwxr-xr-x.   7 root root   73 10月 14 20:19 app
drwxr-xr-x.   6 root root   61 9月  25 01:00 app1
lrwxrwxrwx.   1 root root    7 9月  24 05:41 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 9月  24 06:05 boot
drwxr-xr-x.  20 root root 3300 10月 27 16:30 dev
drwxr-xr-x. 135 root root 8192 10月 27 16:46 etc
drwxr-xr-x.   3 root root   19 9月  24 05:52 home
lrwxrwxrwx.   1 root root    7 9月  24 05:41 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 9月  24 05:41 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   3 root root   16 9月  24 05:46 opt
dr-xr-xr-x. 190 root root    0 10月 27 16:30 proc
dr-xr-x---.  22 root root 4096 10月 27 16:33 root
drwxr-xr-x.  40 root root 1180 10月 27 16:30 run
lrwxrwxrwx.   1 root root    8 9月  24 05:41 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 10月 27 16:30 sys
drwxrwxrwt.  24 root root 4096 10月 27 16:33 tmp
drwxr-xr-x.   3 root root 4096 10月 15 23:35 tomcat-webapps-ROOT
drwxr-xr-x.  13 root root  155 9月  24 05:41 usr
drwxr-xr-x.  21 root root 4096 9月  24 06:05 var
-rw-r--r--.   1 root root 4331 10月 27 16:30 zookeeper.out

切換文件夾目錄,進入某個文件目錄。
進入runtime文件夾。
cd /app/runtime
進入上一層級文件夾目錄。
cd ..
進入當前用戶主目錄。
cd ~ 
返回到上次命令所在的文件夾目錄。
cd - 
進入根目錄。 
cd  /

[root@xinxin001 /]# cd /app/runtime
[root@xinxin001 runtime]# cd ..
[root@xinxin001 app]# cd ~
[root@xinxin001 ~]# cd -
/app
[root@xinxin001 app]# cd
[root@xinxin001 ~]# cd /
[root@xinxin001 /]# 

創建文件夾。
創建名稱爲files的目錄。
mkdir files。
創建層級目錄,文件夾層級不存在也可以創建。
mkdir -p /files/doc/01
一次創建多個目錄02、03、04、05、06。
mkdir 02 03 04 05 06

[root@xinxin001 app]# ls
data  logs  runtime  services  soft
[root@xinxin001 app]# mkdir files
[root@xinxin001 app]# ls
data  files  logs  runtime  services  soft
[root@xinxin001 app]# mkdir -p /files/doc/01
[root@xinxin001 01]# cd /files
[root@xinxin001 files]# ls
doc
[root@xinxin001 files]# cd doc
[root@xinxin001 doc]# ls
01
[root@xinxin001 doc]# mkdir 02 03 04 05 06
[root@xinxin001 doc]# ls
01  02  03  04  05  06
[root@xinxin001 doc]# 

刪除文件夾。
刪除文件夾目錄01。
rmdir  01
刪除doc目錄下所有文件夾和文件,文件夾中的所有子節點。需要輸入yes或y確認刪除。
rm -r doc
強制刪除文件夾或目錄,不需要確認刪除。
rm  -rf  doc

[root@xinxin001 doc]# ls
01  02  03  04  05  06
[root@xinxin001 doc]# rmdir 01
[root@xinxin001 doc]# ls
02  03  04  05  06
[root@xinxin001 doc]# cd ..
[root@xinxin001 files]# rm -r doc
rm:是否進入目錄"doc"? y
rm:是否刪除目錄 "doc/02"?y
rm:是否刪除目錄 "doc/03"?y
rm:是否刪除目錄 "doc/04"?y
rm:是否刪除目錄 "doc/05"?y
rm:是否刪除目錄 "doc/06"?y
rm:是否刪除目錄 "doc"?n
[root@xinxin001 files]# ls
doc
[root@xinxin001 files]# rm -rf doc
[root@xinxin001 files]# ls
[root@xinxin001 files]

修改文件夾名稱、移動文件、複製文件、刪除文件。
mv修改文件名稱。
mv 1.jpg  001.jpg
rename修改文件名稱。
rename 2.jpg 02.jpg *
移動文件。
mv 001.jpg  images/
複製文件到images目錄。
cp 3.jpg  images/
刪除文件3.jpg。
rm -f 3.jpg

[root@xinxin001 files]# ls
1.jpg  2.jpg  3.jpg  images
[root@xinxin001 files]# mv 1.jpg  001.jpg
[root@xinxin001 files]# ls
001.jpg  2.jpg  3.jpg  images
[root@xinxin001 files]# mv 001.jpg  images/
[root@xinxin001 files]# ls
2.jpg  3.jpg  images
[root@xinxin001 files]# cd images
[root@xinxin001 images]# ls
001.jpg
[root@xinxin001 images]# cd ..
[root@xinxin001 files]# ls
2.jpg  3.jpg  images
[root@xinxin001 files]# rename 2.jpg 02.jpg *
[root@xinxin001 files]# ls
02.jpg  3.jpg  images
[root@xinxin001 files]# cp 3.jpg  images/
[root@xinxin001 files]# cd images
[root@xinxin001 images]# ls
001.jpg  3.jpg
[root@xinxin001 images]# cd ..
[root@xinxin001 files]# ls
02.jpg  3.jpg  images
[root@xinxin001 files]# rm -f 3.jpg 
[root@xinxin001 files]# ls
02.jpg  images

創建文件。
使用touch創建一個空的文件read.md。
touch read.md
使用vi創建一個空的文件version.md。
vi version.md
使用echo >重定向功能,將一條指令的輸出結果內容寫入到一個文件中,覆蓋原文件內容。指定的文件不存在,將會創建文件。
echo "hello,ladies and gentlemen" > read.md
使用echo >>追加功能,將一條指令的輸出結果內容追加到一個文件中,不會覆蓋原文件內容。
echo "This is a doc." >> read.md

[root@xinxin001 files]# ls
02.jpg  3.jpg  images
[root@xinxin001 files]# touch read.md
[root@xinxin001 files]# ls
02.jpg  3.jpg  images  read.md
[root@xinxin001 files]# vi version.md 
[root@xinxin001 files]# ls
02.jpg  3.jpg  images  read.md  version.md
[root@xinxin001 files]# echo "hello,ladies and gentlemen" > read.md
[root@xinxin001 files]# vi read.md 
[8]+  已停止               vi read.md

[root@xinxin001 files]# echo "This is a doc." >> read.md
[root@xinxin001 files]# vi read.md 
[9]+  已停止               vi read.md

編輯文件。
vi編輯文件、或vim編輯文件。
vi是系統自帶的編輯器,vim系統不一定會自帶,可能需要安裝,vim會對編輯的內容關鍵字高亮顯示,用不同顏色區分,適合修改配置文件使用。

[root@xinxin001 files]# vi read.md 
[root@xinxin001 files]# vim read.md 

最基本用法。
1、使用vi編輯文件時,先會進入只讀模式。只讀模式可以接受快捷鍵操作,但不能編輯文件內容。
2、按Insert插入鍵,編輯器左下角顯示“-- 插入 -- ”或“-- Insert -- ”,從只讀模式變成編輯模式。編輯模式下,可以編輯文件內容。
3、編輯完成之後,按Esc鍵退出編輯模式,返回只讀模式。
4、按“Shift + :”進入命令模式,在編輯器底部輸入wq或wq!,保存編輯內容。不想保存文件內容,按Ctrl + z退出編輯文件內容。

只讀模式下常用快捷鍵。
a          在光標後一位開始插入,進入編輯模式。
A         在光標所在行的最後面插入,進入編輯模式。
I          在光標所在行的最前面插入,進入編輯模式。
gg      直接跳到文件的首行,光標定位到首行第一個字符。
G        直接跳到文件的末行,光標定位到末行第一個字符。
dd      刪除一行,刪除光標當前所在行。
3dd    刪除3行,刪除從光標所在行開始往下數3行,刪除包括光標所在行。ndd,n需要刪除幾行的數字,2dd,3dd,4dd,5dd。
yy      複製一行,複製光標當前所在行。
3yy    複製3行,複製從光標所在行開始往下數3行,複製包括光標所在行。ndd,n需要複製幾行的數字,3yy,4yy,5yy。
p       粘貼,複製後粘貼。
u       undo,撤銷、取消修改的文件內容,文件內容還原到修改之前的。
v       進入字符選擇模式,按上下左右箭頭選擇文件內容,選擇完成後,按y複製,按p粘貼。取消選擇再按一次v。
ctrl+v    進入內容塊選擇模式,按上下左右箭頭選擇文件內容,選擇完成後,按y複製,按p粘貼。取消選擇再按一次ctrl+v。
shift+v  進入行選擇模式,按上下左右箭頭選擇文件內容,選擇完成後,按y複製,按p粘貼。取消選擇再按一次shift+v。

只讀模式下查找並替換文件內容。
顯示行號。

:set nu

隱藏行號,不顯示行號。

:set nonu

查找關鍵字。查找文件中出現的hello,並定位到第一個找到的地方,按n可以定位到下一個匹配位置,按N定位到上一個匹配位置。

:/hello

修改替換文件內容。
查找光標所在行的第一個hello,替換爲hi。

:s/hello/hi   

 查找文件中所有hello,全部替換爲hi。

:%s/hello/hi 

查看文件內容。
一次性將read.md文件內容全部輸出到控制檯。
cat    read.md
可以翻頁查看,下翻一頁(空格),上翻一頁(b),退出(q)。
more   somefile
可以翻頁查看,下翻一頁(空格),上翻一頁(b),上翻一行(↑) ,下翻一行(↓),可以搜索關鍵字(/keyword)。
less   somefile      
跳到文件末尾: G
跳到文件首行: gg
退出less :  q

[root@xinxin001 files]# cat read.md 
15This is a doc.
14This is a doc.
13This is a doc.
12hi,ladies and gentlemen
11This is a doc.
10This is a doc.
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
2This is a doc.
1This is a doc.

查看文件尾部的3行。
tail -3 read.md   

[root@xinxin001 files]# tail -3 read.md 
3hi,ladies and gentlemen
2This is a doc.
1This is a doc.

顯示文件內容,文件內容改變會顯示出來。小f跟蹤文件的唯一inode號,就算文件改名後,還是跟蹤原來這個inode表示的文件。
tail -f  read.md

[root@xinxin001 files]# tail -f  read.md 
10This is a doc.
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
2This is a doc.
1This is a doc.

 顯示文件內容,文件內容改變會顯示出來。大F按照文件名來跟蹤。
 tail -F read.md

[root@xinxin001 files]# tail -F  read.md 
10This is a doc.
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
2This is a doc.
1This is a doc.

查看文件頭部的5行。
head -5  read.md  

[root@xinxin001 files]# head -5 read.md 
15This is a doc.
14This is a doc.
13This is a doc.
12hi,ladies and gentlemen
11This is a doc.

打包壓縮文件、解壓文件。

.gz後綴文件。
壓縮文件生成.gz壓縮包。
gzip read.md 
解壓.gz壓縮包。
gzip -d read.md.gz
gunzip read.md.gz

[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# gzip read.md 
[root@xinxin001 files]# ls
02.jpg  images  read.md.gz  version.md
[root@xinxin001 files]# gzip -d read.md.gz
[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# gzip read.md 
[root@xinxin001 files]# ls
02.jpg  images  read.md.gz  version.md
[root@xinxin001 files]# gunzip read.md.gz 
[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md

 .bz2後綴文件。
壓縮文件生成.bz2壓縮包。
bzip2 read.md
解壓.bz2壓縮包。
bunzip2 read.md.bz2 
bzip2 -d read.md.bz2 

[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# bzip2 read.md 
[root@xinxin001 files]# ls
02.jpg  images  read.md.bz2  version.md
[root@xinxin001 files]# bzip2 images/
bzip2: Input file images/ is a directory.
[root@xinxin001 files]# ls
02.jpg  images  read.md.bz2  version.md
[root@xinxin001 files]# bunzip2 read.md.bz2 
[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# bzip2 read.md 
[root@xinxin001 files]# ls
02.jpg  images  read.md.bz2  version.md
[root@xinxin001 files]# bzip2 -d read.md.bz2 
[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md

 .tar後綴文件。
壓縮文件生成.tar壓縮包,可指定文件或文件夾。
tar -cvf read.tar read.md
壓縮文件夾。
tar -cvf images.tar images/
解壓.tar後綴壓縮包。
tar -xvf read.tar

[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# tar -cvf read.tar read.md
read.md
[root@xinxin001 files]# ls
02.jpg  images  read.md  read.tar  version.md
[root@xinxin001 files]# tar -cvf read.tar version.md 
version.md
[root@xinxin001 files]# tar -cvf images.tar images/
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[root@xinxin001 files]# ls
02.jpg  images  images.tar  read.md  read.tar  version.md
[root@xinxin001 files]# tar -xvf read.tar 

 .tar.gz後綴文件。
壓縮文件生成.tar.gz壓縮包,可指定文件或文件夾。
tar -zcvf read.tar.gz read.md 
tar -zcvf images.tar.gz images
解壓.tar.gz後綴壓縮包。
tar -zxvf read.tar.gz
tar -zxvf images.tar.gz 
查看.tar.gz壓縮包中包含哪些文件。
tar -ztvf read.tar.gz
tar -ztvf images.tar.gz 

[root@xinxin001 files]# ls
02.jpg  images  read.md  version.md
[root@xinxin001 files]# 
[root@xinxin001 files]# tar -zcvf read.tar.gz read.md 
read.md
[root@xinxin001 files]# ls
02.jpg  images  read.md  read.tar.gz  version.md
[root@xinxin001 files]# tar -zcvf images.tar.gz images
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[root@xinxin001 files]# ls
02.jpg  images  images.tar.gz  read.md  read.tar.gz  version.md
[root@xinxin001 files]# tar -zxvf read.tar.gz
read.md
[root@xinxin001 files]# tar -zxvf images.tar.gz 
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[root@xinxin001 files]# tar -ztvf read.tar.gz
-rw-r--r-- root/root       282 2018-10-29 00:55 read.md
[root@xinxin001 files]# tar -ztvf images.tar.gz 
drwxr-xr-x root/root         0 2018-10-29 00:37 images/
-rw-r--r-- root/root         2 2018-10-27 18:04 images/001.jpg
-rw-r--r-- root/root         4 2018-10-27 19:14 images/3.jpg
-rw-r--r-- root/root      4096 2018-10-29 00:31 images/.001.jpg.swp

 .tar.bz2後綴文件。
壓縮文件生成.tar.bz2壓縮包,可指定文件或文件夾。
tar -jcvf read.tar.bz2 read.md
tar -jcvf images.tar.bz2 images
解壓.tar.bz2後綴壓縮包。
tar -jxvf read.tar.bz2 
tar -jxvf images.tar.bz2 

[root@xinxin001 files]# ls
02.jpg  images  read2.md  read.md  version.md
[root@xinxin001 files]# tar -jcvf read.tar.bz2 read.md
read.md
[root@xinxin001 files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[root@xinxin001 files]# tar -jxvf read.tar.bz2 
read.md
[root@xinxin001 files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[root@xinxin001 files]# rm -rf read.md 
[root@xinxin001 files]# ls
02.jpg  images  read2.md  read.tar.bz2  version.md
[root@xinxin001 files]# tar -jxvf read.tar.bz2 
read.md
[root@xinxin001 files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[root@xinxin001 files]# tar -jcvf images.tar.bz2 images
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[root@xinxin001 files]# ls
02.jpg  images  images.tar.bz2  read2.md  read.md  read.tar.bz2  version.md
[root@xinxin001 files]# tar -jxvf images.tar.bz2 
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp

 .zip後綴文件。
壓縮文件生成.zip壓縮包。
zip  read.zip read.md
解壓.zip後綴壓縮包。
unzip news.zip
把文件解壓到指定的images目錄下
unzip -d images news.zip
查看zip壓縮包中包含哪些文件。
unzip -l news.zip
查看顯示的文件列表,包含壓縮比率。
unzip -v news.zip 

[root@xinxin001 files]# ls
02.jpg  images  news.zip  read2.md  read.md  version.md
[root@xinxin001 files]# unzip news.zip 
Archive:  news.zip
  inflating: news.txt                
[root@xinxin001 files]# ls
02.jpg  images  news.txt  news.zip  read2.md  read.md  version.md
[root@xinxin001 files]# unzip -d images news.zip
Archive:  news.zip
  inflating: images/news.txt 
[root@xinxin001 files]# zip  read.zip read.md
  adding: read.md (deflated 71%)
[root@xinxin001 files]# ls
02.jpg    images    news.zip  read.md   version.md
[root@xinxin001 files]# unzip -l news.zip
[root@xinxin001 files]#  unzip -v news.zip 

查找命令

常用查找命令的使用。
查找可執行的命令所在的路徑。
which ls
which ll
which java
查找可執行的命令和幫助的位置。
whereis ls
whereis java

從某個文件夾開始查找文件。
find / -name "java"
find / -name "zookeeper*" -ls
查找並刪除。
find / -name "test*" -ok rm {} \;
find / -name "test*" -exec rm {} \;
查找用戶爲admin的文件。
find  /  -user  admin  -ls
查找用戶爲admin的文件夾。
find /home -user admin -type d -ls

查找權限爲777的文件。
find / -perm -777 -type d -ls
顯示命令歷史,會顯示所有輸入過的命令歷史記錄,所有在Linux上操作的命令記錄。
history

[root@xinxin001 files]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@xinxin001 files]# which ll
alias ll='ls -l --color=auto'
	/usr/bin/ls
[root@xinxin001 files]# which java
/app/runtime/jdk1.8.0_181/bin/java
[root@xinxin001 files]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@xinxin001 files]# whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /app/runtime/jdk1.8.0_181/bin/java /usr/share/man/man1/java.1.gz
[root@xinxin001 /]# history
    1  ls
    2  cd root
    3  cd /
    4  ls
    5  ll
    6  cd /
    7  /etc/hosts
    8  vim /etc/hosts
    9  hostname
   10  ls
......

基本使用。
查詢包含hi的行。
grep hi read.md
grep hi *.md

[root@xinxin001 files]# grep hi read.md
15This is a doc.
14This is a doc.
13This is a doc.
12hi,ladies and gentlemen
11This is a doc.
10This is a doc.
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
2This is a doc.
1This is a doc.
[root@xinxin001 files]# grep hi *.md
read2.md:15This is a doc.
read2.md:14This is a doc.
read2.md:13This is a doc.
read2.md:12hi,ladies and gentlemen
read2.md:11This is a doc.
read2.md:10This is a doc.
read2.md:9This is a doc.
read2.md:8hi,ladies and gentlemen
read2.md:7hi,ladies and gentlemen
read2.md:6This is a doc.
read2.md:5This is a doc.
read2.md:4This is a doc.
read2.md:3hi,ladies and gentlemen
read2.md:2This is a doc.
read2.md:1This is a doc.
read.md:15This is a doc.
read.md:14This is a doc.
read.md:13This is a doc.
read.md:12hi,ladies and gentlemen
read.md:11This is a doc.
read.md:10This is a doc.
read.md:9This is a doc.
read.md:8hi,ladies and gentlemen
read.md:7hi,ladies and gentlemen
read.md:6This is a doc.
read.md:5This is a doc.
read.md:4This is a doc.
read.md:3hi,ladies and gentlemen
read.md:2This is a doc.
read.md:1This is a doc.

cut截取以.分割保留第7段
grep hi read.md | cut -d. -f7

[root@xinxin001 files]# grep hi read.md | cut -d. -f7
12hi,ladies and gentlemen
8hi,ladies and gentlemen
7hi,ladies and gentlemen
3hi,ladies and gentlemen

查詢不包含This的行。
grep -v This read.md

[root@xinxin001 files]# grep -v This read.md
12hi,ladies and gentlemen
8hi,ladies and gentlemen
7hi,ladies and gentlemen
3hi,ladies and gentlemen

使用正則表達式查詢包含This的行。
grep 'This' read.md

[root@xinxin001 files]# grep 'This' read.md
15This is a doc.
14This is a doc.
13This is a doc.
11This is a doc.
10This is a doc.
9This is a doc.
6This is a doc.
5This is a doc.
4This is a doc.
2This is a doc.
1This is a doc.

使用正則表達式匹配,點代表任意一個字符。
grep 'T.*i*' read.md

[root@xinxin001 files]# grep 'T.*i*' read.md
15This is a doc.
14This is a doc.
13This is a doc.
11This is a doc.
10This is a doc.
9This is a doc.
6This is a doc.
5This is a doc.
4This is a doc.
2This is a doc.
1This is a doc.

正則表達式以15This開頭。
grep '^15This' read.md

[root@xinxin001 files]# grep '^15This' read.md
15This is a doc.

正則表達式以doc.結尾。
grep 'doc\.$' read.md

[root@xinxin001 files]# grep 'doc\.$' read.md
15This is a doc.
14This is a doc.
13This is a doc.
11This is a doc.
10This is a doc.
9This is a doc.
6This is a doc.
5This is a doc.
4This is a doc.
2This is a doc.
1This is a doc.

正則表達式匹配規則。
.  : 任意一個字符
a* : 任意多個a(零個或多個a)
a? : 零個或一個a
a+ : 一個或多個a
.* : 任意多個任意字符
\. : 轉義.
o\{2\} : o重複兩次

查找不是以1開頭的行。
grep -v '^1' read.md | grep -v '^$' 

[root@xinxin001 files]# grep -v '^1' read.md | grep -v '^$' 
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
2This is a doc.

查找以8或9開頭的行。
grep '^[89]' read.md

[root@xinxin001 files]# grep '^[89]' read.md
9This is a doc.
8hi,ladies and gentlemen

查找不是以1和2開頭的行。
grep '^[^12]' read.md

[root@xinxin001 files]# grep '^[^12]' read.md
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.
5This is a doc.
4This is a doc.
3hi,ladies and gentlemen
[root@xinxin001 files]# grep '^[^1-5]' read.md
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.

文件權限操作

linux文件權限的描述格式解讀。

[root@xinxin001 bin]# ls -la java
lrwxrwxrwx. 1 root root 22 9月  24 05:43 java -> /etc/alternatives/java
 

基本的用戶管理

系統管理操作

SSH免密登陸配置

網絡管理

 

重要參考來自Linux愛好者微信公衆號(文章來源:李東浩):
https://mp.weixin.qq.com/s/Ye4Rn_Dl58Sb_2PAsch_1g
www.lxx.help/2016/07/26/大數據學習之基礎部分-----Linux常用命令/
   

centos服務器如何自動關機自動開機
https://dwz.cn/FpIaLi9m

https://www.cnblogs.com/sxdcgaq8080/p/7498906.html

https://www.cnblogs.com/woshimrf/p/linux-file-properties.html#_caption_1

https://jingyan.baidu.com/article/4853e1e5413b541909f72632.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章