1. 程式人生 > >Linux作業系統常用命令

Linux作業系統常用命令

目錄

查詢命令

日常操作命令

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

[[email protected] dubbo-admin-tomcat]# pwd
/app/runtime/dubbo-admin-tomcat

檢視當前系統的時間

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

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

[[email protected]
/]# date +%Y-%m-%d --date="-1 day" 2018-10-26 [[email protected] /]# date +%Y-%m-%d --date="-1 month" 2018-09-27 [[email protected]xin001 /]# date +%Y-%m-%d --date="-1 year" 2017-10-27

修改設定系統時間。

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

檢視有哪些使用者登入到了伺服器,有誰線上。

[[email protected] ~]# 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)

檢視最近使用者的登入歷史記錄。

[[email protected] ~]# 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使用者關閉伺服器,關機。

立刻關機命令。

[[email protected] /]# shutdown -h now

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

[[email protected] /]# halt
[[email protected] /]# poweroff
[[email protected] /]# init 0

1分鐘後關機。

[[email protected] /]# shutdown -h +1
Shutdown scheduled for 六 2018-10-27 15:13:49 CST, use 'shutdown -c' to cancel.
[[email protected] /]# 
Broadcast message from [email protected] (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分鐘後關機。

[[email protected] /]# shutdown -h +10
Shutdown scheduled for 六 2018-10-27 15:28:00 CST, use 'shutdown -c' to cancel.
[[email protected] /]# 
Broadcast message from [email protected] (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分鐘後關機。

[[email protected] /]# shutdown +10 "The machine will shutdown"
Broadcast message from [email protected] (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

設定在指定時間關機。

[[email protected] /]# 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

檢視定時任務列表。

[[email protected] ~]# crontab -l

檢視定時任務執行情況。

[[email protected] /]# 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

取消定時關機。

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

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

使用root使用者立刻重啟伺服器。

[[email protected] ~]# reboot

 或

[[email protected] ~]# shutdown -r now

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

[[email protected] /]# clear

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

使用echo在終端視窗列印輸出資訊。
定一個變數a,值為hi, linux command。使用echo輸出變數a的值。
使用echo輸出資訊This is an output message。

[[email protected] /]# a="hi, linux command"
[[email protected] /]# echo $a
hi, linux command
[[email protected] /]# echo This is an output message
This is an output message
[[email protected] /]# echo 這是一條輸出資訊
這是一條輸出資訊


檔案目錄操作

檢視目錄資訊。
檢視目錄下的檔案和資料夾,ls。
檢視app資料夾下的檔案和資料夾,ls /app。
檢視隱藏檔案,ls -a。
以詳細列表方式檢視目錄下檔案和資料夾,ls -l 或者 ll。

[[email protected] /]# 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
[[email protected] /]# 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
[[email protected] /]# ls app
data  logs  runtime  services  soft
[[email protected] /]# 
[[email protected] /]# 
[[email protected] /]# 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
[[email protected] /]# 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
[[email protected] /]# 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
[[email protected] /]# 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  /

[[email protected] /]# cd /app/runtime
[[email protected] runtime]# cd ..
[[email protected] app]# cd ~
[[email protected] ~]# cd -
/app
[[email protected] app]# cd
[[email protected] ~]# cd /
[[email protected] /]# 

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

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

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

[[email protected] doc]# ls
01  02  03  04  05  06
[[email protected] doc]# rmdir 01
[[email protected] doc]# ls
02  03  04  05  06
[[email protected] doc]# cd ..
[[email protected] 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
[[email protected] files]# ls
doc
[[email protected] files]# rm -rf doc
[[email protected] files]# ls
[[email protected] 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

[[email protected] files]# ls
1.jpg  2.jpg  3.jpg  images
[[email protected] files]# mv 1.jpg  001.jpg
[[email protected] files]# ls
001.jpg  2.jpg  3.jpg  images
[[email protected] files]# mv 001.jpg  images/
[[email protected] files]# ls
2.jpg  3.jpg  images
[[email protected] files]# cd images
[[email protected] images]# ls
001.jpg
[[email protected] images]# cd ..
[[email protected] files]# ls
2.jpg  3.jpg  images
[[email protected] files]# rename 2.jpg 02.jpg *
[[email protected] files]# ls
02.jpg  3.jpg  images
[[email protected] files]# cp 3.jpg  images/
[[email protected] files]# cd images
[[email protected] images]# ls
001.jpg  3.jpg
[[email protected] images]# cd ..
[[email protected] files]# ls
02.jpg  3.jpg  images
[[email protected] files]# rm -f 3.jpg 
[[email protected] 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

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

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

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

[[email protected] files]# vi read.md 
[[email protected] 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

[[email protected] 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   

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

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

[[email protected] 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

[[email protected] 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  

[[email protected] 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

[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# gzip read.md 
[[email protected] files]# ls
02.jpg  images  read.md.gz  version.md
[[email protected] files]# gzip -d read.md.gz
[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# gzip read.md 
[[email protected] files]# ls
02.jpg  images  read.md.gz  version.md
[[email protected] files]# gunzip read.md.gz 
[[email protected] files]# ls
02.jpg  images  read.md  version.md

 .bz2字尾檔案。
壓縮檔案生成.bz2壓縮包。
bzip2 read.md
解壓.bz2壓縮包。
bunzip2 read.md.bz2 
bzip2 -d read.md.bz2 

[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# bzip2 read.md 
[[email protected] files]# ls
02.jpg  images  read.md.bz2  version.md
[[email protected] files]# bzip2 images/
bzip2: Input file images/ is a directory.
[[email protected] files]# ls
02.jpg  images  read.md.bz2  version.md
[[email protected] files]# bunzip2 read.md.bz2 
[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# bzip2 read.md 
[[email protected] files]# ls
02.jpg  images  read.md.bz2  version.md
[[email protected] files]# bzip2 -d read.md.bz2 
[[email protected] 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

[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# tar -cvf read.tar read.md
read.md
[[email protected] files]# ls
02.jpg  images  read.md  read.tar  version.md
[[email protected] files]# tar -cvf read.tar version.md 
version.md
[[email protected] files]# tar -cvf images.tar images/
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[[email protected] files]# ls
02.jpg  images  images.tar  read.md  read.tar  version.md
[[email protected] 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 

[[email protected] files]# ls
02.jpg  images  read.md  version.md
[[email protected] files]# 
[[email protected] files]# tar -zcvf read.tar.gz read.md 
read.md
[[email protected] files]# ls
02.jpg  images  read.md  read.tar.gz  version.md
[[email protected] files]# tar -zcvf images.tar.gz images
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[[email protected] files]# ls
02.jpg  images  images.tar.gz  read.md  read.tar.gz  version.md
[[email protected] files]# tar -zxvf read.tar.gz
read.md
[[email protected] files]# tar -zxvf images.tar.gz 
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[[email protected] files]# tar -ztvf read.tar.gz
-rw-r--r-- root/root       282 2018-10-29 00:55 read.md
[[email protected] 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 

[[email protected] files]# ls
02.jpg  images  read2.md  read.md  version.md
[[email protected] files]# tar -jcvf read.tar.bz2 read.md
read.md
[[email protected] files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[[email protected] files]# tar -jxvf read.tar.bz2 
read.md
[[email protected] files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[[email protected] files]# rm -rf read.md 
[[email protected] files]# ls
02.jpg  images  read2.md  read.tar.bz2  version.md
[[email protected] files]# tar -jxvf read.tar.bz2 
read.md
[[email protected] files]# ls
02.jpg  images  read2.md  read.md  read.tar.bz2  version.md
[[email protected] files]# tar -jcvf images.tar.bz2 images
images/
images/001.jpg
images/3.jpg
images/.001.jpg.swp
[[email protected] files]# ls
02.jpg  images  images.tar.bz2  read2.md  read.md  read.tar.bz2  version.md
[[email protected] 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 

[[email protected] files]# ls
02.jpg  images  news.zip  read2.md  read.md  version.md
[[email protected] files]# unzip news.zip 
Archive:  news.zip
  inflating: news.txt                
[[email protected] files]# ls
02.jpg  images  news.txt  news.zip  read2.md  read.md  version.md
[[email protected] files]# unzip -d images news.zip
Archive:  news.zip
  inflating: images/news.txt 
[[email protected] files]# zip  read.zip read.md
  adding: read.md (deflated 71%)
[[email protected] files]# ls
02.jpg    images    news.zip  read.md   version.md
[[email protected] files]# unzip -l news.zip
[[email protected] 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

[[email protected] files]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[[email protected] files]# which ll
alias ll='ls -l --color=auto'
	/usr/bin/ls
[[email protected] files]# which java
/app/runtime/jdk1.8.0_181/bin/java
[[email protected] files]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[[email protected] 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
[[email protected] /]# 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

[[email protected] 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.
[[email protected] 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

[[email protected] 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

[[email protected] 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

[[email protected] 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

[[email protected] 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

[[email protected] files]# grep '^15This' read.md
15This is a doc.

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

[[email protected] 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 '^$' 

[[email protected] 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

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

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

[[email protected] 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
[[email protected] files]# grep '^[^1-5]' read.md
9This is a doc.
8hi,ladies and gentlemen
7hi,ladies and gentlemen
6This is a doc.

檔案許可權操作

linux檔案許可權的描述格式解讀。

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

基本的使用者管理

系統管理操作

SSH免密登陸配置

網路管理

相關推薦

LinuxLinux作業系統常用命令

Linux作業系統常用命令 LInux基本命令 ~:代表當前使用者所在的home目錄。如:/home/zhangsan $:用來只是普通使用者輸入命令的地方;對於root使用者來說一般是‘#’ cat:檢視檔案,與‘<<END’連用可以用於輸入大段資料

Linux作業系統常用命令及快捷鍵(一)

1、常用命令 ls 顯示檔案或目錄 ls -l 列出檔案詳細資訊 ls -a 列出當前目錄下的都要檔案及目錄,包括隱藏的(all) mkdir 建立目錄 mkdir -p 建立目錄樹(形如:mkdir -p 當前目錄/目錄1/目錄2/目錄3) touch 建立檔案 cd 進入使

Linux作業系統常用命令

目錄 查詢命令 日常操作命令 檢視當前所在的工作目錄的全路徑,完整路徑。 [[email protected] dubbo-admin-tomcat]# pwd /app/runtime/dubbo-admin-tomcat 檢視當前系統的

linux 作業系統 常用命令和軟體安裝

1.系統時間更新 ntpdate time.windows.com 2.傳送檔案 rsync -av /home/data/a

Linux作業系統常用的網路狀態查詢命令

對於做系統運維的工程師來說,經常會在客戶那面臨這些問題:怎麼閘道器不通?怎麼埠被佔用了?怎麼IP配置不生效?所以掌握如何通過命令列設定IP、路由、排查網路故障的技巧就顯得非常重要了,這篇文章給大家介紹下Linux系統中常用的網路狀態查詢命令:ifconfig | ping |  netstat | 

Linux作業系統常用工具、vim常用命令

常用工具         yum 軟體包管理器         vim 文字編輯器         gcc編譯器         mak

Linux常用命令之sed學習總結

linux sed sed命令 正則表達式 sed總結 Sed功能說明:Sed是linux下一個強大的文本文件處理工具,通過對文件增加、刪除、查找、查詢操作,配合正則表達式以實現工作中的各種需求。同時也是一名運維人員必須掌握的核心技能。---------------------------

Linux常用命令

linux的常用命令 lofout 退出登錄 mount 查看系統當中已經掛載的設備 mount -a 依據配置文件/etc/fstab的內容,自動掛載 who 查看系統登錄了哪些用戶(能看到用戶名,登錄終端,登陸時間登錄IP) w 查看系統登錄了哪些用戶(跟who一樣,但是還能

Linux GCC常用命令

靜態加載 配置文件 情況 窗口 連接器 執行 二進制 c 語言 標準輸入輸出 Linux GCC常用命令 1簡介 2簡單編譯 2.1預處理 2.2編譯為匯編代碼(Compilation) 2.3匯編(Assembly) 2.4連接(Linking) 3

Linux常用命令

ln -s directory 沒有 開始 media 關機命令 範圍 後臺作業 解壓縮 命令基本格式: 命令提示符:[[email protected]/* */ ~]# root 代表當前的登錄用戶(linux當中管理員賬號是root)

Linux系統常用命令

所有 目錄 span txt spa png oot http style   首先利用虛擬機安裝Linux系統,在應用程序中找到終端(很重要,因為Linux系統都是以命令的方式執行任務,而所有的命令都要在終端中輸入並且執行),然後輸入命令 1.切換用戶,普通用戶前面顯示$

linux簡單常用命令

常用簡單命令一.進程相關 1.查看占用CPU最高的進程: ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head 2.查看占用內存最高的進程: ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4

linux YUM常用 命令

remove 可用 頭文件 erase pac ring 配置 依賴 mirror 語法 yum(選項)(參數) 選項 -h:顯示幫助信息; -y:對所有的提問都回答“yes”; -c:指定配置文件; -q:安靜模式; -v:詳細模式; -d:設置調試等級(0-10); -

linux系統常用命令 -設置文件夾讀寫權限

ima 所有 執行 權限 描述 分享 linux com bsp 設置文件夾的讀寫權限: sudo chmod -R 777 /data 權限碼描述 sudo chmod 600 ××× (只有所有者有讀和寫的權限)sudo chmod 644 ××× (所有者有讀和寫的權

linux centos7 常用命令【systemctl替換service】

centos7 user 配置 fig linux c entos 端口 nes unit 看所有網卡IP地址——ip addr 啟動防火墻——systemctl start firewalld.service 停止防火墻——systemctl stop fir

Linux常用命令總結

命令註:本文檔只記錄最常用的命令以及命令下的參數,更多的命令請參考linux文檔或使用命令help、man、info 進行對應查詢常用文件目錄操作指令ls 參數 文件 顯示文件或目錄(文件為空時,代表顯示當前目錄) -l 列出文件詳細信息l(list)

Linux Centos 常用命令

信息 edi lld 建立 zxvf amp all 啟動 blog 安裝程序包:yum install 包名 下載程序包:wget 程序包URL 解壓tar包:tar -zxvf 程序包名 編譯和安裝本地程序包:make 查看本地所有開放的端口:netstat -nlt

Linux基本常用命令之ls詳解(含date,cal)

Linux基礎【1】顯示日期的指令:date示例:(1)#date +%Y/%m/%d結果:2018/02/27(2)#date +%H:%M結果:10:48【2】顯示日歷的指令:cal格式:cal [month] [year]示例:(1)#cal 2 2018(2)#cal 13 2018結果:cal:il

Linux vim 常用命令

上下 ctrl 編輯模式 進入 三種模式 vim 常用命令 切換 保存 選中 vim 的命令相當多,基礎的保存、退出、插入、移動等,麻煩點的多行選中、分屏等。 vim 的命令也有三種模式,命令模式、編輯模式、底行模式。這三個模式有各種各樣的,我習慣用這三個名字。 命令模式:

linux系統常用命令(一)

shu 解析 txt 相關 name roc upd less 位置 管理 在UNIX/linux系統中,一切皆為文件;若非文件,則為進程。首先認識文件系統: linux文件系統 /var - 經常變化的(variable)文件,諸如日誌或數據庫等 /usr - 包含絕大部