Linux基礎命令快速入門

Linux基礎命令

write by Booboo Wei

[email protected]


摘要:

常用的命令 ls cd pwd


符號 * ? { } |


幫助命令 --help help type man info /usr/share/doc


針對文件的的基本操作 touch mkdir rmdir cp rm mv


針對文件內容的基本操作 cat tac head tail more less


文件的查看、編輯、過濾vi vim echo grep cut wc file


關於時間的命令cal date timedatectl hwclock


版權聲明:



本文遵循“署名非商業性使用相同方式共享2.5 中國大陸”協議

您可以自由複製、發行、展覽、表演、放映、廣播或通過信息網絡傳播本作品

您可以根據本作品演義自己的作品

您必須按照作者或者許可人指定的方式對作品進行署名。

您不得將本作品用於商業目的。

如果您改變、轉換本作品或者以本作品爲基礎進行創作,您只能採用與本協議相同的許

可協議發佈基於本作品的演繹作品。

對任何再使用或者發行,您都必須向他人清楚地展示本作品使用的許可協議條款。

如果得到著作權人的許可,您可以不受任何這些條件的限制。



Booboo Wei([email protected])




1 命令簡介

1.1 命令的構成

命令字 選項 參數

命令分:內部命令、外部命令;

選項: - 單個字符-- 多個字符

參數:對誰執行這個命令,可以有多個,選項和參數可以互換位置

1.2 命令使用的原因

Shell是系統的用戶界面,提供了用戶與內核進行交互操作的一種接口。它接收用戶輸入的命令並把它送入內核去執行。實際上Shell是一個命令解釋器,它解釋由用戶輸入的命令並且把它們送到內核。從這裏開始學習Linux命令,本課程讓你更清楚地瞭解和掌握它,在Linux中命令是講究大小寫的。使用命令即快速又能減少機器的性能消耗。

1.3 命令提示符

# root 用戶

$ 一般用戶

[ 用戶的身份@ 主機名 當前位置 ]

當前位置顯示的是目錄名

[root@www ~]# hostname

www.dabao.com

[root@www ~]# groupadd tom

[root@www ~]# useradd -g tom tom

[root@www ~]# id tom

uid=501(tom) gid=501(tom) groups=501(tom)

[root@www ~]# su - tom

[tom@www ~]$ who

root tty1

2016-03-20 23:56 (:0)

root pts/0

2016-03-21 00:39 (:0.0)

2 常用的命令

2.1 ls

ls

list的簡寫 查看當前目錄下的所有文件

備註

-l

long的縮寫 詳細列出當前目錄下的所有文件屬性

七列 文件名 <=255個字符

-d

directory的縮寫 查看當前目錄本身的信息

文件大小默認單位爲bites

-h

以人性化的方式顯示文件大小,錄的大小並不代表目錄內所有文件的大小du -sh /etc<== 查看etc目錄真正的大小


-a

查看隱藏文件 以 .開頭的文件


-R

查看多層目錄


-b

特殊字符將以\ 分割

ls 查看有特殊字符的文件

2.1.1 ls實驗

                   [tom@www tmp]$ ls -hl

                   total 68K

                   srwxr-xr-x. 1 root root 0 Mar 20 23:59 gedit.root.3177893063

                   drwx------. 2 root root 4.0K Feb 5 18:24 keyring-JL7MKY

                   [tom@www tmp]$ ls -ld /tmp

                   drwxrwxrwt. 22 root root 4096 Mar 21 00:43 /tmp

                   [tom@www tmp]$ ls -la /tmp

                   total 96

                   drwxrwxrwt. 22 root root 4096 Mar 21 00:43 .

                   dr-xr-xr-x. 29 root root 4096 Mar 20 23:55 ..

                   drwx------. 2 root root 4096 Mar 20 23:56 .esd-0

                   drwx------. 2 cong cong 4096 Jan 1 18:33 .esd-500

                   [tom@www tmp]$ ls -bl

                   -rw-rw-r--. 1 tom tom 0 Mar 21 00:48 a\ b.txt

                   [tom@www tmp]$ ls -l

                   -rw-rw-r--. 1 tom tom 0 Mar 21 00:48 a b.txt

                   [tom@www tmp]$ mkdir -p a/b/c

                   [tom@www tmp]$ ls -lR a/

                   a/:

                   total 4

                   drwxrwxr-x. 3 tom tom 4096 Mar 21 00:50 b

                   a/b:

                   total 4

                   drwxrwxr-x. 2 tom tom 4096 Mar 21 00:50 c

                   a/b/c:

total 0


2.2 cd

cd

change directory 切換工作目錄

絕對路徑

以根爲起始的路徑

相對路徑

                   ~當前用戶的家目錄

                   . 當前目錄

                   .. 上一層用戶

-回到上一次所在位置


2.2.1 cd實驗


                   [tom@www tmp]$ cd /etc/

                   [tom@www etc]$ cd ~

                   [tom@www ~]$ cd .

                   [tom@www  ~]$ cd ..

                   [tom@www  home]$ cd -

/home/tom


2.3 pwd

pwd:print working directory 顯示當前坐在位置的絕對路徑

2.3.1 pwd實驗

                   [tom@www tmp]$ cd /etc/nginx

                   [tom@www nginx]$ cd conf.d

                   [tom@www conf.d]$ pwd

/etc/nginx/conf.d


3 符號

3.1 通配符*

匹配任意一個字符

3.2 匹配一個字符?

匹配指定位數


3.2.1 *?實驗


                   rm -f *1

                   rm -f 1*

                   rm -f 1*1

rm -f test?<== 想刪除test後面有一個字符的文件


3.3 | 管道

output | input

對某些命令執行的結果去作操作,會用到管道

3.3.1 |實驗

                   # 詳細列出/tmp目錄下的文件,並截取以空格爲分割的第三列

                   [tom@www ~]$ ls -l /tmp|cut -d" " -f3

                   tom

                   tom

                   root

                   root

                   root

                   # 詳細列出/tmp目錄下的文件,截取含有關鍵字tom的行,再截取以空格爲分割的第一列內容

                   [tom@www ~]$ ls -l /tmp|grep tom|cut -d" " -f1

                   drwxrwxr-x.

-rw-rw-r--.


4 針對文件的的基本操作

4.1 touch

touch [filename] <== 創建文件,參數可以跟多個

如果要創建50 個有規律的文件,例如text1-text50

利用參數擴展

touch test{1..50}

touch test{a..e}

touch test{a..e}_{1..3}---> 會創建a_1 a_2 a_3...

上帝之手,本來是用來修改文件時間戳的。文件的三個時間ctime\mtime\atime

   拓展內容:可以通過“stat”命令查看文件的三個時間

touch " " 可以放一些特殊字符

4.1.1 touch實驗



                   [tom@www ~]$ touch test{a..c}_{1..4}

                   [tom@www ~]$ ls

                   testa_1 testa_4 testb_3 testc_2

                   testa_2 testb_1 testb_4 testc_3

                   testa_3 testb_2 testc_1 testc_4

                   #--full-time可以查看mtime的完整時間

                   [tom@www ~]$ ls -l --full-time

                   total 0

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_1

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_2

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_3

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_4

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_1

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_2

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_3

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_4

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_1

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_2

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_3

                   -rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_4

                   [tom@www ~]$ touch "ab cd"

                   [tom@www ~]$ ls -b

                   ab\ \ \ cd testa_3 testb_2 testc_1 testc_4

                   testa_1 testa_4 testb_3 testc_2

testa_2 testb_1 testb_4 testc_3


4.1.2 touch拓展實驗


[booboo@rhel7 ~]$ touch booboo

[booboo@rhel7 ~]$ ll

total 0

-rw-rw-r--. 1 booboo booboo 0 Jun 15 23:28 booboo

[booboo@rhel7 ~]$ stat booboo

File: ‘booboo’

Size: 0         Blocks: 0         IO Block: 4096   regular empty file

Device: fd01h/64769d Inode: 143       Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2016-06-15 23:28:55.041578819 -0400     #atime 文件最近一次被訪問的時間

Modify: 2016-06-15 23:28:55.041578819 -0400    #mtime 文件內容最近一次修改的時間

Change: 2016-06-15 23:28:55.041578819 -0400    #ctime 文件屬性最近一次修改的時間

Birth: -

#使用cat去訪問booboo文件,可以發現atime被修改了

[booboo@rhel7 ~]$ cat booboo

[booboo@rhel7 ~]$ stat booboo

File: ‘booboo’

Size: 0         Blocks: 0         IO Block: 4096   regular empty file

Device: fd01h/64769d Inode: 143       Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2016-06-15 23:32:35.898724748 -0400

Modify: 2016-06-15 23:28:55.041578819 -0400

Change: 2016-06-15 23:28:55.041578819 -0400

Birth: -

#通過chmod修改文件權限後,會看到ctime時間改變,通過ll命令看到的時間爲mtime

[booboo@rhel7 ~]$ chmod 777 booboo

[booboo@rhel7 ~]$ ll

total 0

-rwxrwxrwx. 1 booboo booboo 0 Jun 15 23:28 booboo  

[booboo@rhel7 ~]$ stat booboo

File: ‘booboo’

Size: 0         Blocks: 0         IO Block: 4096   regular empty file

Device: fd01h/64769d Inode: 143       Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2016-06-15 23:32:35.898724748 -0400

Modify: 2016-06-15 23:28:55.041578819 -0400

Change: 2016-06-15 23:33:49.195445761 -0400

Birth: -

#通過echo命令向booboo文件追加一些內容,會看到mtime時間變了,並且ctime也變了,思考爲什麼

[booboo@rhel7 ~]$ echo hi >> booboo

[booboo@rhel7 ~]$ ll

total 4

-rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo

[booboo@rhel7 ~]$ stat booboo

File: ‘booboo’

Size: 3         Blocks: 8         IO Block: 4096   regular file

Device: fd01h/64769d Inode: 143       Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)

Context: unconfined_u:object_r:user_home_t:s0

Access: 2016-06-15 23:32:35.898724748 -0400

Modify: 2016-06-15 23:34:53.251332183 -0400

Change: 2016-06-15 23:34:53.251332183 -0400

Birth: -



4.2 rm

rm

[filename] remove 刪除文件,root用戶有提示,普通用戶沒有提示

-f

force強制刪除, root 無提示

-i

普通用戶有提示的刪除

-r

遞歸刪除,慎重使用-rf


4.2.1 rm實驗


                   # 普通用戶tom

                   [tom@www ~]$ rm testa_1

                   [tom@www ~]$ rm -i testa_2

                   rm: remove regular empty file `testa_2'? Y

                   #root 用戶

                   [root@www ~]# rm a.test

                   rm: remove regular empty file `a.test'? Y

                   [root@www ~]# rm -f b.test

                   # 普通用戶tom

                   [tom@www ~]$ mkdir -p a/b/c

                   [tom@www ~]$ rm a/

                   rm: cannot remove `a/': Is a directory

[tom@www ~]$ rm -r a/


4.3 mkdir

mkdir:make directory 創建目錄

mkdir -p /test/test1<== 第歸創建目錄

mkdir {a..e}<== 創建a-e 的目錄

touch {a..e}/file{1..4}<== a-e 的目錄下新建file1-file4 文件

4.3.1 mkdir實驗

                   [tom@www ~]$ mkdir -p test/test1

                   [tom@www ~]$ ls

                   ab cd testa_3 testb_2 testc_1 testc_4

                   p        testa_4 testb_3 testc_2

                   test    testb_1 testb_4 testc_3

                   [tom@www ~]$ mkdir {a..f}

                   [tom@www ~]$ ls

                   a d test testb_2 testc_2

                   ab cd e testa_3 testb_3 testc_3

                   b f testa_4 testb_4 testc_4 c p testb_1 testc_1

                   [tom@www ~]$ touch {a..f}/file{1..4}

                   [tom@www ~]$ ls

                   a d test testb_2 testc_2

                   ab cd e testa_3 testb_3 testc_3

                   b f testa_4 testb_4 testc_4 c p testb_1 testc_1

                   [tom@www ~]$ ls -rR

                   .:

                   testc_4 testb_4 testa_4 f b

                   testc_3 testb_3 testa_3 e ab cd

                   testc_2 testb_2 test d a

                   testc_1 testb_1 p c

                   ./test:

                   test1

                   ./test/test1:

                   ./p:

                   ./f:

                   file4 file3 file2 file1

                   ./e:

                   file4 file3 file2 file1

                   ./d:

                   file4 file3 file2 file1

                   ./c:

                   file4 file3 file2 file1

                   ./b:

                   file4 file3 file2 file1

                   ./a:

file4 file3 file2 file1

4.4 rmdir

rmdir:remove directory 刪除目錄

只能刪除空目錄,出於安全性的考慮

rm -rf [d_name]<== 可以刪除空目錄

4.4.1 rmdir實驗

                   [booboo@rhel7 ~]$ mkdir aa

                   [booboo@rhel7 ~]$ mkdir -p cc/bb

                   [booboo@rhel7 ~]$ rmdir aa

                   [booboo@rhel7 ~]$ ll

                   total 4

                   -rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo

                   drwxrwxr-x. 3 booboo booboo 15 Jun 16 00:08 cc

                   [booboo@rhel7 ~]$ rmdir cc

                   rmdir: failed to remove ‘cc’: Directory not empty

                   [booboo@rhel7 ~]$ rm -rf cc

                   [booboo@rhel7 ~]$ ll

                   total 4

-rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo

4.5 cp

cp:copy 複製文件

cp 源文件 目的地(目錄)

-p 保留文件原屬性

-r 複製目錄

4.5.4 cp實驗

                   # 使用root用戶,進入tom 的家目錄

                   [root@www ~]# cd /home/tom

                   # 保留原文件屬性複製testa_3文件到/tmp 目錄下

                   [root@www tom]# cp -p testa_3 /tmp

                   [root@www tom]# ll /tmp/testa_3

                   -rw-rw-r--. 1 tom tom 0 Mar 21 01:31 /tmp/testa_3

                   [root@www tom]# cp testa_4 /tmp

                   [root@www tom]# ll /tmp/testa_4

                   -rw-r--r--. 1 root root 0 Mar 21 01:55 /tmp/testa_4

                   # 拷貝目錄a /tmp,必須加上-r ,因爲a 目錄下還有b/c 目錄

                   [root@www tom]# cp a /tmp

                   cp: omitting directory `a'

[root@www tom]# cp -r a /tmp



4.6 mv

mv:move移動 移動和重命名

mv源文件 目的地(目錄)

4.6.1 mv實驗

[tom@www ~]$ mv testa_3 test

[tom@www ~]$ ls

a

c f testa_4 testb_3 testc_2

ab cd d p testb_1 testb_4 testc_3

b

e test testb_2 testc_1 testc_4

[tom@www ~]$ mv test??? f/

[tom@www ~]$ ll -R f

f:

total 0

-rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file1

-rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file2

-rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file3

-rw-rw-r--. 1 tom tom 0 Mar 21 01:47 file4

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testa_4

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_1

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_2

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_3

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testb_4

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_1

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_2

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_3

-rw-rw-r--. 1 tom tom 0 Mar 21 01:31 testc_4



5 針對文件內容的基本操作

5.1 文件的查看

小文件

cat

以正序查看 調用內存比較多

-n 指定行號

tac

以倒序查看 調用內存比較多


大文件

head

查看文件首部,默認10

-n 指定行號

tail

查看文件尾部,默認10

-n 指定行號

-f 顯示動態追加內容

more

查看大文件

按空格space 下一頁

b 向上翻頁

enter 下一行

less

more 多了一個搜索功能/[ 需搜索的子段]

N 向上查找

n 向下查找

q 退出

5.1.1 文件查看實驗

[tom@www ~]$ cat -n passwd

1 root:x:0:0:root:/root:/bin/bash

2 bin:x:1:1:bin:/bin:/sbin/nologin

3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

4 adm:x:3:4:adm:/var/adm:/sbin/nologin

5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

6 sync:x:5:0:sync:/sbin:/bin/sync

7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

8 halt:x:7:0:halt:/sbin:/sbin/halt

9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

10 cong:x:500:500:cong:/home/cong:/bin/bash

11 nginx:x:496:491:Nginx web server:/var/lib/nginx:/sbin/nologin

12 tom:x:501:501::/home/tom:/bin/bash

[tom@www ~]$ tac passwd

tom:x:501:501::/home/tom:/bin/bash

nginx:x:496:491:Nginx web server:/var/lib/nginx:/sbin/nologin

cong:x:500:500:cong:/home/cong:/bin/bash

mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

halt:x:7:0:halt:/sbin:/sbin/halt

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

sync:x:5:0:sync:/sbin:/bin/sync

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

bin:x:1:1:bin:/bin:/sbin/nologin

root:x:0:0:root:/root:/bin/bash



5.2 文件的修改

LibreOffice

.odt 結尾

類似於windows office

gedit

類似於windows 記事本

vim

插入模式

後面會專門講到vim 編輯器的使用

退出模式

命令模式

echo

本身代表回顯

echo xxx > file xxx 寫入file 文件,並覆蓋原有內容

echo xxx >> file file 文件追加xxx

5.2.1 echo實驗

[booboo@rhel7 ~]$ echo hi > file1

[booboo@rhel7 ~]$ cat file1

hi

[booboo@rhel7 ~]$ echo booboo > file1

[booboo@rhel7 ~]$ cat file1

booboo

[booboo@rhel7 ~]$ echo hihihihi >> file1

[booboo@rhel7 ~]$ cat file1

booboo

hihihihi



5.3 文件的過濾

grep

截取行

grep [OPTIONS] PATTERN [FILE...]

grep [ 字符串] [ 文件]<== 過濾帶有[ 字符串] 的行

grep [^ 字符串] [ 文件]<== 過濾以[ 字符串] 爲開始的行

grep [ 字符串$] [ 文件]<== 過濾以[ 字符串] 爲結尾的行

grep -v [ 字符串] [ 文件]---> 反選,不帶某個字符串的行

eg. grep ^root /etc/passwd<== 過濾以root 爲開始的行

grep bash$ /etc/passwd<== 過濾以bash 爲結尾的行

cut

截取列

cut -d" 分割符"( 以什麼爲分隔符) -fn( 第幾列) [ 文件]

eg. cut -d":" -f2 /etc/resolv.conf

wc

統計

wc 行數 單詞數 字符數 文件名

-l 只顯示行數

-w, --words 顯示單詞數

-c, -m,--bytes 顯示字節

eg.

[root@stu15 ~]# wc /etc/resolv.conf

4 11 98 /etc/resolv.conf

sort

排序

默認按照首字母ACII

-n 按照數字大小排序

-u 剔除重複的行

-r 降序排列

-k 指定某一列

-t 分隔符

eg.sort -n -k 2 -t : file1 <== file1 以第二列的數字排序,列以:分割

uniq

剔除重複行

uniq [file_name]



5.3.1 文件過濾實驗

#grep

[booboo@rhel7 ~]$ grep root passwd

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

[booboo@rhel7 ~]$ grep ^booboo passwd

booboo:x:1001:1001::/home/booboo:/bin/bash

[booboo@rhel7 ~]$ grep ^root passwd

root:x:0:0:root:/root:/bin/bash

[booboo@rhel7 ~]$ grep bash$ passwd

root:x:0:0:root:/root:/bin/bash

student:x:1000:1000:student:/home/student:/bin/bash

booboo:x:1001:1001::/home/booboo:/bin/bash

[booboo@rhel7 ~]$ grep -v nologin passwd

root:x:0:0:root:/root:/bin/bash

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

student:x:1000:1000:student:/home/student:/bin/bash

booboo:x:1001:1001::/home/booboo:/bin/bash

#cut

[booboo@rhel7 ~]$ cut -d":" -f1 passwd

root

bin

daemon

adm

lp

sync

shutdown

halt

mail

#wc

[booboo@rhel7 ~]$ wc passwd

42   72 2121 passwd

[booboo@rhel7 ~]$ wc -l passwd

42 passwd

[booboo@rhel7 ~]$ wc -w passwd

72 passwd

[booboo@rhel7 ~]$ wc -c passwd

2121 passwd

#sort

[booboo@rhel7 ~]$ vi num

[booboo@rhel7 ~]$ cat num

booboo 20 100

tom 21 100

tom 21 100

kevin 19 200

booboo 20 100

mark 20 200

[booboo@rhel7 ~]$ sort num

booboo 20 100

booboo 20 100

kevin 19 200

mark 20 200

tom 21 100

tom 21 100

[booboo@rhel7 ~]$ sort -r num

tom 21 100

tom 21 100

mark 20 200

kevin 19 200

booboo 20 100

booboo 20 100

[booboo@rhel7 ~]$ sort -u num

booboo 20 100

kevin 19 200

mark 20 200

tom 21 100

[booboo@rhel7 ~]$ sort -n -k 2 -t " " num |sort -u

booboo 20 100

kevin 19 200

mark 20 200

tom 21 100

#uniq

[booboo@rhel7 ~]$ uniq num

booboo 20 100

tom 21 100

kevin 19 200

booboo 20 100

mark 20 200



6 幫助命令

type [ 命令]

判斷是內部命令or 外部命令

--help

外部命令

help

只針對系統內部命令

man []

內容清晰、詳細,在線文檔,支持搜索( /name )

man [ 章節] [name]

章節一共有8

man -k passwd<== 查看passwd 屬於哪個章節

info []

太詳細

/usr/share/doc

存放幫助文檔,在與軟件同名的目錄下有所有軟件的使用文檔

man和—help以及help的區別

man命令

系統中會有單獨的man文件,就是說,如果系統沒有安裝對應man文件,哪怕命令完全正常,man都沒結果(同樣,只要安裝了man文件,哪怕沒命令,也可以得到一大堆東西)。

--help參數

將會顯示可執行程序自帶的信息,這些信息是嵌入到程序本身的,所以--help信息較簡短。

help命令

是選項幫助命令,顧名思義 你可以把單獨某個命令的某個選項列出來,方便快捷很多,省去了man當中查找的繁瑣,但是help只支持shell的內部命令。內部命令即存儲在shell內部可以直接調用的一些簡單命令,比如說echocdpwd等。



6.1 type

type命令用來顯示指定命令的類型,判斷給出的指令是內部指令還是外部指令。

語法

type(選項)(參數)

選項

-t:輸出“file”、“alias”或者“builtin”,分別表示給定的指令爲“外部指令”、“命令別名”或者“內部指令”;

-p:如果給出的指令爲外部指令,則顯示其絕對路徑;

-a:在環境變量“PATH”指定的路徑中,顯示給定指令的信息,包括命令別名。 參數 指令:要顯示類型的指令。

參數

關鍵字:指定要搜索幫助的關鍵字

命令類型

alias:別名

keyword:關鍵字,Shell保留字

function:函數,Shell函數

builtin:內建命令,Shell內建命令

file:文件,磁盤文件,外部命令

unfound:沒有找到



#嘗試幾個命令man,ls,touch,echo,cat

[booboo@rhel7 ~]$ type man

man is /bin/man

[booboo@rhel7 ~]$ type ls

ls is aliased to `ls –color=auto'

[booboo@rhel7 ~]$ which ls

alias ls='ls --color=auto'

                    /bin/ls

[booboo@rhel7 ~]$ type touch

touch is hashed (/bin/touch)

[booboo@rhel7 ~]$ type echo

echo is a shell builtin

[booboo@rhel7 ~]$ type cat

cat is hashed (/bin/cat)

#內置命令一般顯示爲“is a shell builtin ”

#除了內置命令外,其他命令都是通過某個安裝包安裝生成的可執行文件

#接下來我們一起看看這些命令都是什麼軟件生成的

[booboo@rhel7 ~]$ rpm -qf /bin/man

man-db-2.6.3-9.el7.x86_64

[booboo@rhel7 ~]$ rpm -qf /bin/ls

coreutils-8.22-11.el7.x86_64

[booboo@rhel7 ~]$ rpm -qf /bin/touch

coreutils-8.22-11.el7.x86_64

[booboo@rhel7 ~]$ rpm -qf /bin/cat

coreutils-8.22-11.el7.x86_64

[booboo@rhel7 ~]$ type if

if is a shell keyword



6.2 --help

--help參數是大所數命令自帶的選項,用於查看使用幫助。

[booboo@rhel7 ~]$ ls --help

Usage: ls [OPTION]... [FILE]...

List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.


Mandatory arguments to long options are mandatory for short options too.

-a, --all                  do not ignore entries starting with .

-A, --almost-all           do not list implied . and ..

--author               with -l, print the author of each file

-b, --escape               print C-style escapes for nongraphic characters

--block-size=SIZE      scale sizes by SIZE before printing them; e.g.,

'--block-size=M' prints sizes in units of

1,048,576 bytes; see SIZE format below

-B, --ignore-backups       do not list implied entries ending with ~

-c                         with -lt: sort by, and show, ctime (time of last

modification of file status information);

with -l: show ctime and sort by name;

otherwise: sort by ctime, newest first

-C                         list entries by columns

--color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',

or 'always' (the default); more info below

-d, --directory            list directories themselves, not their contents

-D, --dired                generate output designed for Emacs' dired mode

-f                         do not sort, enable -aU, disable -ls --color



6.3 help

help只支持shell的內部命令。內部命令即存儲在shell內部可以直接調用的一些簡單命令,例如cd,echo,help等。

help(選項)(參數)

-s:輸出短格式的幫助信息。僅包括命令格式。

[booboo@rhel7 ~]$ type cd

cd is a shell builtin

[booboo@rhel7 ~]$ help cd

cd: cd [-L|[-P [-e]]] [dir]

Change the shell working directory.

   

Change the current directory to DIR.  The default DIR is the value of the

HOME shell variable.

   

The variable CDPATH defines the search path for the directory containing

DIR.  Alternative directory names in CDPATH are separated by a colon (:).

A null directory name is the same as the current directory.  If DIR begins

with a slash (/), then CDPATH is not used.

   

If the directory is not found, and the shell option `cdable_vars' is set,

the word is assumed to be  a variable name. If that variable has a value,

its value is used for DIR.

   

Options:

-L force symbolic links to be followed

-P use the physical directory structure without following symbolic

    links

-e if the -P option is supplied, and the current working directory

    cannot be determined successfully, exit with a non-zero status

   

The default is to follow symbolic links, as if `-L' were specified.

   

Exit Status:

Returns 0 if the directory is changed, and if $PWD is set successfully when

-P is used; non-zero otherwise.

[booboo@rhel7 ~]$ type touch

touch is hashed (/bin/touch)

[booboo@rhel7 ~]$ type echo

echo is a shell builtin

[booboo@rhel7 ~]$ help echo

echo: echo [-neE] [arg ...]




6.4 man

man命令是Linux下的幫助指令,通過man指令可以查看Linux中的指令幫助、配置文件幫助和編程幫助等信息。

語法

man(選項)(參數)

選項

-a:在所有的man幫助手冊中搜索;

-f:等價於whatis指令,顯示給定關鍵字的簡短描述信息;

-P:指定內容時使用分頁程序;

-M:指定man手冊搜索的路徑。

參數

字:指定從哪本man手冊中搜索幫助

關鍵字:指定要搜索幫助的關鍵字



例如輸入man ls,它會在左上角顯示“ECHO(1)”“ECHO”代表手冊名稱;“(1)”代表 表示該手冊位於第一節章1)”表示該手冊位於第一節章,同樣,我們輸man ifconfig它會在最左上角顯示“IFCONFIG(8)”。也可以這樣輸入命令:“man [章節號]手冊名稱”。man是按照手冊的章節號的順序進行搜索的,比如:man sleep 只會顯示sleep命令的手冊,如果想查看庫函數sleep,就要輸入: man 3 sleep



[booboo@rhel7 ~]$ man echo|cat

ECHO(1)                         User Commands                        ECHO(1)

#此處“ECHO”代表手冊名稱;“(1)”代表 表示該手冊位於第一節章


NAME

echo - display a line of text


SYNOPSIS

echo [SHORT-OPTION]... [STRING]...

echo LONG-OPTION


DESCRIPTION

Echo the STRING(s) to standard output.


-n     do not output the trailing newline


-e     enable interpretation of backslash escapes


-E     disable interpretation of backslash escapes (default)


--help display this help and exit


--version

output version information and exit


If -e is in effect, the following sequences are recognized:


\\     backslash


\a     alert (BEL)


\b     backspace


\c     produce no further output


\e     escape


\f     form feed


\n     new line


\r     carriage return


\t     horizontal tab


\v     vertical tab


\0NNN  byte with octal value NNN (1 to 3 digits)


\xHH   byte with hexadecimal value HH (1 to 2 digits)


NOTE:  your  shell  may  have  its  own version of echo, which usually

supersedes the version described here. Please refer to  your  shell's

documentation for details about the options it supports.


GNU  coreutils  online  help: <http://www.gnu.org/software/coreutils/>

Report echo translation bugs to <http://translationproject.org/team/>

AUTHOR

Written by Brian Fox and Chet Ramey.

COPYRIGHT

Copyright  2013 Free Software Foundation, Inc.  License  GPLv3+:  GNU

GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

This  is  free  software:  you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

SEE ALSO

The full documentation for echo is maintained as a Texinfo manual.  If

the  info  and  echo programs are properly installed at your site, the

command

info coreutils 'echo invocation'

should give you access to the complete manual.


GNU coreutils 8.22               January 2014                        ECHO(1)

6.5 info(作爲拓展內容)

info命令是Linux下info格式的幫助指令。 就內容來說,info頁面比man page編寫得要更好、更容易理解,也更友好,但man page使用起來確實要更容易得多。一個man page只有一頁,而info頁面幾乎總是將它們的內容組織成多個區段(稱爲節點),每個區段也可能包含子區段(稱爲子節點)。理解這個命令的竅門就是不僅要學習如何在單獨的Info頁面中瀏覽導航,還要學習如何在節點和子節點之間切換。可能剛開始會一時很難在info頁面的節點之間移動和找到你要的東西,真是具有諷刺意味:原本以爲對於新手來說,某個東西比man命令會更好些,但實際上學習和使用起來更困難。

語法

info(選項)(參數)

選項

-d:添加包含info格式幫助文檔的目錄;

-f:指定要讀取的info格式的幫助文檔;

-n:指定首先訪問的info幫助文件的節點;

-o:輸出被選擇的節點內容到指定文件。

參數

幫助主題:指定需要獲得幫助的主題,可以是指令、函數以及配置文件。

常用快捷鍵

                    ?鍵:它就會顯示info的常用快捷鍵。

                    N鍵:顯示(相對於本節點的)下一節點的文檔內容。

                    P鍵:顯示(相對於本節點的)前一節點的文檔內容。

                    U鍵:進入當前命令所在的主題。

                    M鍵:敲M鍵後輸入命令的名稱就可以查看該命令的幫助文檔了。

                    G鍵:敲G鍵後輸入主題名稱,進入該主題。

                    L鍵:回到上一個訪問的頁面。SPACE鍵:向前滾動一頁。

                    BACKUP或DEL鍵:向後滾動一頁。

                    Q:退出info。

命令

                    ? 顯示幫助窗口

                    在幫助窗口中:

                    Ctrl-x 0 關閉幫助窗口

                    Ctrl-x Ctrl-c 關閉整個Info

                    q 退出info

                    n 打開與本Node關聯的下一個Node

                    p 打開與本Node關聯的前一個Node

                    u 打開與本Node關聯的上一個Node

                    l 回到上一次訪問的Node

                    m或g選擇一個菜單項(Node的名字)

                    輸入指定菜單的名字後按回車,打開指定菜單項關聯的Node

                    空格鍵 下一頁(PageDown也可以,下一頁從當前頁的最後兩行開始算起)

                    下一個Node(若當前頁在Node文檔的末尾)

                    Del 鍵 上一頁(PageUp也可以,上一頁從當前頁的開始兩行開始算起)

                    上一個Node(若當前頁Node文檔的開始)

                    b 或t 或Home文檔的開始(b是begining的意思)

                    e 或End文檔的末尾(b是ending的意思)

                    Ctrl-l 刷新當前頁,若當前文檔顯示情況有問題時

                    Ctrl-g取消所鍵入的指令



7 關於時間的命令

7.1 date

date命令是顯示或設置系統時間與日期。 很多shell腳本里面需要打印不同格式的時間或日期,以及要根據時間和日期執行操作。延時通常用於腳本執行過程中提供一段等待的時間。日期可以以多種格式去打印,也可以使用命令設置固定的格式。在類UNIX系統中,日期被存儲爲一個整數,其大小爲自世界標準時間(UTC)1970年1月1日0時0分0秒起流逝的秒數。

語法

date(選項)(參數)

選項

-d<字符串>:顯示字符串所指的日期與時間。字符串前後必須加上雙引號;

-s<字符串>:根據字符串來設置日期與時間。字符串前後必須加上雙引號;

-u:顯示GMT;

--help:在線幫助;

--version:顯示版本信息。

參數

<+時間日期格式>:指定顯示時使用的日期時間格式。


日期格式字符串列表

%H 小時,24小時制(00~23)

%I 小時,12小時制(01~12)

%k 小時,24小時制(0~23)

%l 小時,12小時制(1~12)

%M 分鐘(00~59)

%p 顯示出AM或PM

%r 顯示時間,12小時制(hh:mm:ss %p)

%s 從1970年1月1日00:00:00到目前經歷的秒數

%S 顯示秒(00~59)

%T 顯示時間,24小時制(hh:mm:ss)

%X 顯示時間的格式(%H:%M:%S)

%Z 顯示時區,日期域(CST)

%a 星期的簡稱(Sun~Sat)

%A 星期的全稱(Sunday~Saturday)

%h,%b 月的簡稱(Jan~Dec)

%B 月的全稱(January~December)

%c 日期和時間(Tue Nov 20 14:12:58 2012)

%d 一個月的第幾天(01~31)

%x,%D 日期(mm/dd/yy)

%j 一年的第幾天(001~366)

%m 月份(01~12)

%w 一個星期的第幾天(0代表星期天)

%W 一年的第幾個星期(00~53,星期一爲第一天)

%y 年的最後兩個數字(1999則是99)

%Y 年1999



7.1.1 date實驗

#格式化輸出

[booboo@rhel7 ~]$ date +"%y/%m/%d"

16/06/16

[booboo@rhel7 ~]$ date +"%Y/%m/%d"

2016/06/16

#輸出昨天或後天的日期

[booboo@rhel7 ~]$ date -d "1 day ago" +"%Y-%m-%d"

2016-06-15

[booboo@rhel7 ~]$ date -d "-1 day" +%Y%m%d

20160615

[booboo@rhel7 ~]$ date -d "+1 day" +%Y%m%d

20160617

#輸出50秒後的時間

[booboo@rhel7 ~]$ date -d "50 second" +"%Y-%m-%d %H:%M:%S"

2016-06-16 02:52:41

#傳說中的1234567890秒

[booboo@rhel7 ~]$ date -d "1970-01-01 1234567890 seconds" +"%Y-%m-%d %H:%M:%S"

2009-02-13 23:31:30

#2009年2月13日星期五,協調世界時(UTC)晚上11:31:30,UNIX時間將抵達1234567890秒。

UNIX時間是UNIX或類UNIX系統使用的時間表示方式:從協調世界時1970年1月1日0時0分0秒起至現在的總秒數,不包括閏秒。由於大部分UNIX的系統都是32位,因此到2038年時間計數就可能溢出,解決方法是更換爲64位模式。Linux內核開發者Alan Cox表示,Linux現在都運行64位時間模式,它可以記錄到2900億年後,因此即使太陽燃料用盡也不會出問題。

#普通格式轉化

[booboo@rhel7 ~]$ date -d "2016-06-16" +"%Y/%m/%d %H:%M:%S"

2016/06/16 00:00:00

#設定時間需要root用戶權限,此處用booboo用戶模擬,沒有真的修改時間

[booboo@rhel7 ~]$ date

Thu Jun 16 03:01:19 EDT 2016

[booboo@rhel7 ~]$ date -s "02:03:08 2018-05-09"

date: cannot set date: Operation not permitted

Wed May  9 02:03:08 EDT 2018

[booboo@rhel7 ~]$ date -s "02:03:08 20180509"

date: cannot set date: Operation not permitted

Wed May  9 02:03:08 EDT 2018

[booboo@rhel7 ~]$ date -s "20180509 15:02:02"

date: cannot set date: Operation not permitted

Wed May  9 15:02:02 EDT 2018

[booboo@rhel7 ~]$ date -s "2018-05-09 15:02:02"

date: cannot set date: Operation not permitted

Wed May  9 15:02:02 EDT 2018

[booboo@rhel7 ~]$ date -s "2019/05/09 15:02:02"

date: cannot set date: Operation not permitted

Thu May  9 15:02:02 EDT 2019



7.1.2 date拓展實驗

1)有時需要檢查一組命令花費的時間 比如

#ping執行的時間

[root@rhel7 ~]# vi a.sh

[root@rhel7 ~]# cat a.sh

#!/bin/bash

start=$(date +%s)

ping -c 10 172.25.0.11 &> /dev/null

end=$(date +%s)

difference=$(( $end - $start ))

echo $difference seconds.

[root@rhel7 ~]# bash a.sh

9 seconds.

#sql腳本運行的是時間

#!/bin/bash

start=$(date +%s)

$mysql< mysql.all.sql &> /dev/null

end=$(date +%s)

difference=$(( $end - $start ))

echo $difference seconds.



2)創建以當前時間爲文件名的目錄

[root@rhel7 ~]# mkdir `date +%Y%m%d`

[root@rhel7 ~]# ls

20160616



3)備份以時間做爲文件名的

[root@rhel7 ~]# tar -cvf `date +%Y%m%d`.tar ./`date +%Y%m%d`

./20160616/

[root@rhel7 ~]# ls

20160616         Documents                       Pictures

20160616.tar



4)編寫shell腳本計算離自己生日還有多少天?

[root@rhel7 ~]# cat bb.sh

#!/bin/bash

read -p "Input your birthday(YYYYmmdd):" date1

m=`date -d "$date1" +%m`    #得到生日的月

d=`date -d "$date1" +%d`    #得到生日的日

date_now=`date +%s`             #得到當前時間的秒值

y=`date +%Y`                    #得到當前時間的年

birth=`date -d "$y$m$d" +%s`     #得到今年的生日日期的秒值

internal=$(($birth-$date_now))       #計算今日到生日日期的間隔時間

if [ "$internal" -lt "0" ]; then             #判斷今天的生日是否已過

      birth=`date --date="$(($y+1))$m$d" +%s`      #得到明年的生日日期秒值

      internal=$(($birth-$date_now))             #計算今天到下一個生日的間隔時間

fi

echo "There is :$(($internal/60/60/24)) days."       #輸出結果,秒換算爲天

Input your birthday(YYYYmmdd):19960506

There is :323 days.

[root@rhel7 ~]# bash bb.sh

Input your birthday(YYYYmmdd):19960902

There is :77 days.


7.2 hwclock

hwclock命令是一個硬件時鐘訪問工具,它可以顯示當前時間、設置硬件時鐘的時間和設置硬件時鐘爲系統時間,也可設置系統時間爲硬件時鐘的時間。 在Linux中有硬件時鐘與系統時鐘等兩種時鐘。硬件時鐘是指主機板上的時鐘設備,也就是通常可在BIOS畫面設定的時鐘。系統時鐘則是指kernel中的時鐘。當Linux啓動時,系統時鐘會去讀取硬件時鐘的設定,之後系統時鐘即獨立運作。所有Linux相關指令與函數都是讀取系統時鐘的設定。

查看BIOS 時間

修改BIOS 時間

hwclock --systohc 將硬件時間與系統時間同步,以系統爲基準

hwclock --hctosys 將系統時間與硬件時間同步,以硬件爲基準



7.3 timedatectl

比date 多了時區的功能

rhel6修改時區

[booboo@rhel7 ~]$ tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

1) Africa

2) Americas

3) Antarctica

4) Arctic Ocean

5) Asia

6) Atlantic Ocean

7) Australia

8) Europe

9) Indian Ocean

10) Pacific Ocean

11) none - I want to specify the time zone using the Posix TZ format.

#? 5

Please select a country.

1) Afghanistan  18) Israel    35) Palestine

2) Armenia  19) Japan    36) Philippines

3) Azerbaijan  20) Jordan    37) Qatar

4) Bahrain  21) Kazakhstan    38) Russia

5) Bangladesh  22) Korea (North)    39) Saudi Arabia

6) Bhutan  23) Korea (South)    40) Singapore

7) Brunei  24) Kuwait    41) Sri Lanka

8) Cambodia  25) Kyrgyzstan    42) Syria

9) China  26) Laos    43) Taiwan

10) Cyprus  27) Lebanon    44) Tajikistan

11) East Timor  28) Macau    45) Thailand

12) Georgia  29) Malaysia    46) Turkmenistan

13) Hong Kong  30) Mongolia    47) United Arab Emirates

14) India  31) Myanmar (Burma)    48) Uzbekistan

15) Indonesia  32) Nepal    49) Vietnam

16) Iran  33) Oman    50) Yemen

17) Iraq  34) Pakistan

#? 9

Please select one of the following time zone regions.

1) east China - Beijing, Guangdong, Shanghai, etc.

2) Heilongjiang (except Mohe), Jilin

3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.

4) most of Tibet & Xinjiang

5) west Tibet & Xinjiang

#? 1


The following information has been given:


                    China

                    east China - Beijing, Guangdong, Shanghai, etc.


Therefore TZ='Asia/Shanghai' will be used.

Local time is now: Thu Jun 16 15:08:57 CST 2016.

Universal Time is now: Thu Jun 16 07:08:57 UTC 2016.

Is the above information OK?

1) Yes

2) No

#? 1


You can make this change permanent for yourself by appending the line

                    TZ='Asia/Shanghai'; export TZ

to the file '.profile' in your home directory; then log out and log in again.


Here is that TZ value again, this time on standard output so that you

can use the /bin/tzselect command in shell scripts:

Asia/Shanghai



rhel7 版本



[kiosk@foundation0 Desktop]$ timedatectl

Local time: Wed 2016-06-15 16:47:40 CST

Universal time: Wed 2016-06-15 08:47:40 UTC

RTC time: Wed 2016-06-15 16:47:40

Time zone: Asia/Shanghai (CST, +0800)

NTP enabled: yes

NTP synchronized: yes

RTC in local TZ: yes

DST active: n/a



關鍵詞:

UTC協調世界時Coordinated Universal Time

    又稱世界統一時間,世界標準時間,國際協調時間。1972年1月1日,UTC(協調世界時)成爲新的世界標準時間。

CST時區縮寫

    CST可以爲如下4個不同的時區的縮寫:

  美國中部時間:Central Standard Time (USA) UT-6:00

    澳大利亞中部時間:Central Standard Time (Australia) UT+9:30

    中國標準時間:China Standard Time UT+8:00 例如,UTC是0點,那麼CST中國爲早晨8點

    古巴標準時間:Cuba Standard Time UT-4:00

RTC Time

    硬件時鐘時間

    set-local-rtc 1 本地時區

    set-local-rtc 0 UTC

DST Daylight Saving Time日光節約時間、夏令時

    是一種爲節約能源而人爲規定地方時間的制度,在這一制度實行期間所採用的統一時間稱爲“夏令時間”。

    一般在天亮早的夏季人爲將時間提前一小時,可以使人早起早睡,減少照明量,以充分利用光照資源,從而節約照明用電。

    各個採納夏時制的國傢俱體規定不同。目前全世界有近110個國家每年要實行夏令時。

    1986年至1991年,中國在全國範圍實行了六年夏令時,1992年4月5日後不再實行。



7.4 cal

cal命令用於顯示當前日曆,或者指定日期的日曆。

cal [-smjy13] [[[day] month] year]

-1 顯示當月日曆並將今日標黑

-3 顯示上個月、當月、下個月。

-s 週日作爲第一列

-m 週一作爲第一列

-j 列出今天是一年的第幾天

-y 列出今年所有的月

[root@rhel7 ~]# cal

June 2016

Su Mo Tu We Th Fr Sa

1  2  3  4

5  6  7  8  9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30


[root@rhel7 ~]# cal -3

May 2016              June 2016            July 2016

Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa

1  2  3  4  5  6  7            1  2  3  4                1  2

8  9 10 11 12 13 14   5  6  7  8  9 10 11   3 4  5  6  7  8  9

15 16 17 18 19 20 21  12 13 14 15 16 17 18  10 11 12 13 14 15 16

22 23 24 25 26 27 28  19 20 21 22 23 24 25  17 18 19 20 21 22 23

29 30 31              26 27 28 29 30        24 25 26 27 28 29 30

31                

[root@rhel7 ~]# cal -j

June 2016

Sun Mon Tue Wed Thu Fri Sat

153 154 155 156

157 158 159 160 161 162 163

164 165 166 167 168 169 170

171 172 173 174 175 176 177

178 179 180 181 182



附錄2——作業

Linux基礎命令作業



1./tmp目錄下創建testdir 目錄,在該目錄下創建file1 file30 30 個文件。

2.刪除所有以file1 起始的文件。

3.刪除file2 後匹配一個字符的所有文件。

4.在/home/student目錄下遞歸創建一個/home/student/a/b/c/d/e目 錄,並且將該a 目錄保留原屬性的複製到/tmp目錄下。

5.將/tmp下的a 目錄重命名爲test 目錄。

6.統計一下/etc/passwd文件總共有幾行。

7.在/tmp下創建一個目錄,目錄名爲study

8.在study 目錄下創建一個文件,文件名任意,並向這個文件裏寫hello 字段

9.往該文件裏追加study 字段。

10.查看該文件內容。

11.統計一下該文件共有幾行,幾個單詞,幾個字節。

12.將/etc/passwd裏以bash 結尾的行過濾出來,並從中截取第一列字

段內容。

13.統計/boot/下所有文件的屬性中含root 字段的文件共有幾個。

14.熟悉一下vim 編輯器,利用vim 編輯器書寫整理一下今天所學的 知識點。

15. 判斷一下boot 目錄下文件的內容類型,並將屬於ASCII 碼文件內容 類型的文件名顯示到屏幕上


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