第二周課程練習
1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示?
1.1 目錄管理類命令:cd,pwd,ls,mkdir,rmdir,tree
1.1.1 cd:主要功能是改變當前目錄,可使用此命令在linux進行目錄跳轉。
命令格式:cd 目錄
使用實例:
1、跳轉至用戶主目錄
[tom@CentOS6 /]$ id uid=507(tom) gid=508(tom) 組=508(tom),2001(mygrp) [tom@CentOS6 /]$ pwd / [tom@CentOS6 /]$ cd ~ [tom@CentOS6 ~]$ pwd /home/tom
2、跳轉至用戶主目錄
[tom@CentOS6 /]$ pwd / [tom@CentOS6 /]$ cd [tom@CentOS6 ~]$ pwd /home/tom
3、切換至指定用戶的主目錄
[root@CentOS6 /]# cd ~jeery [root@CentOS6 jeery]# pwd /home/jeery [root@CentOS6 jeery]#
4、在上一個目錄和當前目錄之間來回切換
[root@CentOS6 ~]# pwd /root [root@CentOS6 ~]# cd /var [root@CentOS6 var]# pwd /var [root@CentOS6 var]# cd - /root [root@CentOS6 ~]# cd - /var
1.1.2 pwd:顯示當前工作目錄。
命令格式:pwd [選項]
常用參數:
-L:目錄連接鏈接時,輸出連接路徑
-P:輸出物理路徑
使用實例:
1、顯示當前路徑
1
2
|
[root@CentOS6 ~] # pwd /root |
2、顯示當前物理路徑
1
2
3
4
5
6
7
|
[root@CentOS6 ~] # cd /etc/init.d/ [root@CentOS6 init.d] # [root@CentOS6 init.d] # pwd -P /etc/rc .d /init .d [root@CentOS6 init.d] # [root@CentOS6 init.d] # pwd /etc/init .d |
3、顯示鏈接路徑
1
2
3
4
|
[root@CentOS6 init.d] # pwd -L /etc/init .d [root@CentOS6 init.d] # pwd /etc/init .d |
1.1.3 ls:顯示指定路徑下的文件列表。
命令格式:ls [選項]… [DIR]…
常用參數:
-a:顯示所有檔案及目錄(ls內定將檔案名或目錄名稱為“.”的視為隱藏,不會列出);
-A:顯示除隱藏文件“.”和“..”以外的所有文件列表;
-C:多列顯示輸出結果。這是默認選項;
-l:與“-C”選項功能相反,所有輸出信息用單列格式輸出,不輸出為多列;
-h, –human-readable:與-l 一起,以易于閱讀的格式輸出
-F:在每個輸出項后追加文件的類型標識符,具體含義:“*”表示具有可執行權限的普通文件,“/”表示目錄,“@”表示符號鏈接,“|”表示命令管道FIFO,“=”表示sockets套接字。當文件為普通文件時,不輸出任何標識符;
-c:與“-lt”選項連用時,按照文件狀態時間排序輸出目錄內容,排序的依據是文件的索引節點中的ctime字段。與“-l”選項連用時,則排序的一句是文件的狀態改變時間;
-d:僅顯示目錄名,而不顯示目錄下的內容列表。顯示符號鏈接文件本身,而不顯示其所指向的目錄列表;
-i:顯示文件索引節點號(inode)。一個索引節點代表一個文件; –file-type:與“-F”選項的功能相同,但是不顯示“*”;
-k:以KB(千字節)為單位顯示文件大??;
-l:以長格式顯示目錄下的內容列表。輸出的信息從左到右依次包括文件名,文件類型、權限模式、硬連接數、所有者、組、文件大小和文件的最后修改時間等;
-r:以文件名反序排列并輸出目錄內容列表;
-s:顯示文件和目錄的大小,以區塊為單位;
-t:用文件和目錄的更改時間排序;
-L:如果遇到性質為符號鏈接的文件或目錄,直接列出該鏈接所指向的原始文件或目錄;
-R:遞歸處理,將指定目錄下的所有文件及子目錄一并處理;
–full-time:列出完整的日期與時間;
–color[=WHEN]:使用不同的顏色高亮顯示不同類型的。
使用實例:
1、以列的形式顯示當前目錄下的目錄和文件
[root@CentOS6 ~]# ls -l 總用量 116 -rw------- 1 root root 1762 6月 6 2015 anaconda-ks.cfg -rw-r--r-- 1 root root 54 10月 17 2015 bashrc_logout -rw-r--r-- 1 root root 50263 6月 6 2015 install.log -rw-r--r-- 1 root root 11308 6月 6 2015 install.log.syslog
輸出解釋:-rw——- 1 root root 1762 6月 6 2015 anaconda-ks.cfg
-:文件類型,-表示普通文件,d表示文件夾,l表示符號鏈接文件,c表示字符或塊設備,b表示區塊設備二進制文件,s表示數據接口文件,-p表示數據傳送文件(FIFO,pipe);
rw——-:訪問權限:perm
1:文件被硬鏈接的次數;
左root:文件的屬主;
右root:文件的屬組;
1762:文件的大??;
6月 6 2015:文件最近一次被修改時間;
anaconda-ks.cfg:文件名
2、列出根目錄的所有文件,并且以列形式,按修改時間排序,以人類易看的格式顯示出來
[root@CentOS6 /]# ls -lhta 總用量 108K drwxrwxrwt 6 root root 4.0K 6月 28 15:26 tmp dr-xr-x--- 32 root root 4.0K 6月 28 11:41 root drwxr-xr-x 21 root root 4.0K 6月 28 08:10 home drwxr-xr-x 123 root root 12K 6月 28 07:24 etc drwxr-xr-x 7 root root 0 10月 26 2015 selinux drwxr-xr-x 13 root root 0 10月 26 2015 sys dr-xr-xr-x 196 root root 0 10月 26 2015 proc drwxr-xr-x 19 root root 3.9K 10月 26 2015 dev drwxr-xr-x 2 root root 0 10月 26 2015 net drwxr-xr-x 2 root root 0 10月 26 2015 misc dr-xr-xr-x 25 root root 4.0K 10月 26 2015 . dr-xr-xr-x 25 root root 4.0K 10月 26 2015 .. -rw-r--r-- 1 root root 0 10月 26 2015 .autofsck drwxr-xr-x 3 root root 4.0K 10月 26 2015 media -rw-r--r-- 1 root root 0 10月 12 2015 .autorelabel drwxr-xr-x 4 root root 4.0K 9月 1 2015 mnt drwxr-xr-x 3 root root 4.0K 8月 26 2015 srv dr-xr-xr-x 2 root root 4.0K 6月 8 2015 bin dr-xr-xr-x 2 root root 12K 6月 8 2015 sbin dr-xr-xr-x 18 root root 12K 6月 8 2015 lib drwx------ 3 root root 4.0K 6月 6 2015 .dbus dr-xr-xr-x 5 root root 1.0K 6月 6 2015 boot drwxr-xr-x 3 root root 4.0K 6月 6 2015 opt drwxr-xr-x 23 root root 4.0K 6月 6 2015 var drwxr-xr-x 12 root root 4.0K 6月 6 2015 usr drwxr-xr-x 3 root root 1.0K 6月 6 2015 myshare drwx------ 2 root root 16K 6月 6 2015 lost+found
1.1.4 mkdir:創建目錄
命令格式:mkdir [選項]… 目錄…
常用參數:
-m, –mode:設置權限模式(類似chmod)
-p, –parents:需要時創建目標目錄的上層目錄,但即使這些目錄已存在也不當作錯誤處理
-v, –verbose:每次創建新目錄都顯示詳細信息
使用實例:
1、創建test目錄,設置權限為所有人讀寫執行,并顯示創建過程;
[root@localhost tmp]# mkdir -v -m 777 test mkdir: 已創建目錄 "test" [root@localhost tmp]# ll 總用量 4 -rw-r--r--. 1 root root 0 8月 25 08:01 attrtest drwxrwxrwx. 2 root root 4096 8月 31 20:30 test
1.1.5 rmdir:刪除目錄,該命令只能刪除空目錄;
命令格式:rmdir [選項]… 目錄…
使用實例:
1、刪除test目錄
[root@localhost tmp]# ll 總用量 4 -rw-r--r--. 1 root root 0 8月 25 08:01 attrtest drwxrwxrwx. 2 root root 4096 8月 31 20:30 test [root@localhost tmp]# rmdir test [root@localhost tmp]# ll 總用量 0 -rw-r--r--. 1 root root 0 8月 25 08:01 attrtest [root@localhost tmp]#
1.1.6 tree:以樹形圖列出文件的層級結構
命令格式:tree [選項]… 目錄…
常用參數:
-d:只顯示目錄;
-L:level:指定顯示的層級數目;
-P pattern:只顯示由指定pattern匹配到的路徑;
使用實例:
1、列出根目錄下的子目錄1級樹形結構
[root@localhost tmp]# tree -dL 1 / / ├── bin ├── boot ├── dev ├── etc ├── home ├── lib ├── lost+found ├── media ├── misc ├── mnt ├── myshare ├── net ├── opt ├── proc ├── root ├── sbin ├── selinux ├── srv ├── sys ├── tmp ├── usr └── var 22 directories [root@localhost tmp]#
1.2 文件查看類命令:cat,tac,more,less,tail,head
1.2.1 cat:連結文件并輸出打印,一口氣將一個文本文件內容全部打印到屏幕上,日志文件慎用;
命令格式:cat [選項]… [文件]…
常用參數:
-A, –show-all:等同于-vET
-n 或 –number 由 1 開始對所有輸出的行數編號;
-b 或 –number-nonblank 和 -n 相似,只不過對于空白行不編號;
-s 或 –squeeze-blank 當遇到有連續兩行以上的空白行,就代換為一行的空白行;
-T, –show-tabs:將跳格字符顯示為 ^I;
-E, –show-ends:在每行結束處顯示$;
-v,–show-nonprinting:使用^和 M- 引用,除了 LFD 和 TAB 之外;
使用實例:
1、顯示/etc/hosts的文件內容,并編號和顯示每行的結束符;
[root@localhost tmp]# cat -nE /etc/hosts 1127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4$ 2::1 localhost localhost.localdomain localhost6 localhost6.localdomain6$ [root@localhost tmp]#
1.2.2 tac:和cat功能差不多,但是反序顯示內容;
命令格式:tac [OPTION]… [FILE]…
使用實例:顯示/etc/hosts的文件內容;
[root@localhost tmp]# tac /etc/hosts ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 [root@localhost tmp]#
1.2.3 more:跟cat一樣顯示文件內容,但是more會以一頁一頁的顯示文件內容,比較方便查看;
命令格式:more [OPTION] FILE……
常用參數:
+n從笫n行開始顯示
-n定義屏幕大小為n行
+/pattern 在每個檔案顯示前搜尋該字串(pattern),然后從該字串前兩行之后開始顯示
-c從頂部清屏,然后顯示
-d顯示翻頁及退出提示
常用操作命令:
Enter:向下n行,需要定義。默認為1行
Ctrl+F:向下滾動一屏
空格鍵:向下滾動一屏
Ctrl+B:返回上一屏
=:輸出當前行的行號
:f 輸出文件名和當前行的行號
V:調用vi編輯器
!命令:調用Shell,并執行命令
q:退出more
使用實例:
1、設置每屏幕顯示5行
[root@localhost tmp]# more -5 /etc/ssh/ssh_config #$OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm E xp $ # This is the ssh client system-wide configuration file. See # ssh_config(5) for more information. This file provides def --More--(8%)
2、和管道|結合起來 顯示/etc的目錄內容
[root@localhost tmp]# ll /etc | more -5 總用量 2316 drwxr-xr-x. 3 root root 4096 6月 6 17:58 abrt drwxr-xr-x. 4 root root 4096 6月 6 18:08 acpi -rw-r--r--. 1 root root 51 8月 31 20:02 adjtime drwxr-xr-x. 2 root root 4096 6月 6 17:56 akonadi --More--
1.2.4 less 具也是對文件或其它輸出進行分頁顯示的工具,功能極其強大。less的用法比起more更加的有彈性。
命令格式:less [參數] 文件
常用參數:
-b <緩沖區大小> 設置緩沖區的大小
-e 當文件顯示結束后,自動離開
-f 強迫打開特殊文件,例如外圍設備代號、目錄和二進制文件
-g 只標志最后搜索的關鍵詞
-i 忽略搜索時的大小寫
-m 顯示類似more命令的百分比
-N 顯示每行的行號
-o <文件名> 將less 輸出的內容在指定文件中保存起來
-Q 不使用警告音
-s 顯示連續空行為一行
-S 行過長時間將超出部分舍棄
-x <數字> 將“tab”鍵顯示為規定的數字空格
常用操作命令:
字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重復前一個搜索(與 / 或 ? 有關)
N:反向重復前一個搜索(與 / 或 ? 有關)
b 向后翻一頁
d 向后翻半頁
h 顯示幫助界面
Q 退出less 命令
u 向前滾動半頁
y 向前滾動一行
空格鍵 滾動一行
回車鍵 滾動一頁
[pagedown]: 向下翻動一頁
[pageup]: 向上翻動一頁
使用實例:
1、顯示/etc/hosts文件內容,并顯示行號;
[root@localhost tmp]# less -N /etc/hosts
1.2.5 head:輸出文件前面一部分內容,可以設置只顯示頭幾行;
命令格式:head [OPTION]… [FILE]..
常用參數:
-c#:指令獲取前#字節
-n: #或-#:指定獲取前#行
使用實例:
1、顯示文件前3行內容;
[root@localhost ssh]# head -n 3 ssh_config #$OpenBSD: ssh_config,v 1.25 2009/02/17 01:28:32 djm Exp $ # This is the ssh client system-wide configuration file. See [root@localhost ssh]#
1.2.6 tail: 輸出文件尾部的一部分內容,可以設置最顯示最后幾行;
tail [OPTION]… [FILE]..
常用參數:
-c#:指令獲取前#字節
-n #或-#:指定獲取前#行
使用實例:
1、顯示文件最后3行內容;
[root@localhost ssh]# tail -n 3 ssh_config SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE SendEnv XMODIFIERS
1.3 文件的時間戳管理工具:touch
1.3.1 touch:改變文件時間戳屬性,并可以創建文件。
使用格式: touch [選項]…文件…
常用參數:
-a:only atime
-m:only mtime
-t STAMP:[[CC]YY]MMDDhhmm[.ss]
-c:如果文件不存在,則不予創建
使用實例:
1、更改1.txt文件的訪問時間和修改時間;
[root@localhost tmp]# touch -t 201501121212.12 1.txt [root@localhost tmp]# ll 總用量 0 -rw-r--r--. 1 root root 0 1月 12 2015 1.txt -rw-r--r--. 1 root root 0 8月 25 2015 attrtest [root@localhost tmp]#
2、設置1.txt文件的修改時間跟當前時間同步;
[root@localhost tmp]# touch -m 1.txt [root@localhost tmp]# [root@localhost tmp]# [root@localhost tmp]# ll 總用量 0 -rw-r--r--. 1 root root 0 7月 2 21:50 1.txt
3、創建2.txt空文件
[root@localhost tmp]# touch 2.txt [root@localhost tmp]# ll 2.txt -rw-r--r--. 1 root root 0 7月 2 21:53 2.txt [root@localhost tmp]#
1.4 文件管理類命令:cp,mv,rm
1.4.1 cp:復制命令
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE..
cp SRC DEST
(SRC是文件)
如果目標不存在,新建DEST,并將SRC中內容填充至DEST中;
如果目標存在:
如果DEST是文件:將SRC中的內容覆蓋至DEST中;
此時建議為cp命令使用-i選項;
如果DEST是目錄:在DEST下新建與原文件同名的文件,并將SRC中內容填充至新文件中;
cp SRC……DEST
SRC……:多個文件
DEST必須存在,且為目錄;其它情形均會出錯;
cp SRC DEST
SRC是目錄:
則使用選項:-r
如果DEST不存在:
如果DEST不存在,則創建指定目錄,復制SRC目錄中的所有文件至DEST中;
如果DEST存在:
如果DEST是文件:報錯
如果DEST是目錄:在目標目錄下創建一個一源目錄同名的目錄,并且把源目錄文件復制到目標目中;
常用參數:
-i:交互式;
-r,-R:遞歸復制目錄及內部的所有內容;
-a:歸檔,相當于-dR –preserv=all
-d:–no-dereference –preserv=links:不追蹤符號鏈接
–preserv=[=ATTR_LIST]
mode:權限
ownership:屬主屬組
timestamp:時間戳
links:鏈接屬性
xattr:擴展屬性
context:安全上下文
-p: –preserve=mode,ownership,timestamps
-v:–verbose
-f:–force
使用實例:
1、復制/etc/hosts文件到tmp目錄
[root@localhost test]# cp /etc/hosts /tmp/
2、復制整個/etc目錄到tmp目錄
[root@localhost test]# cp -r /etc /tmp
1.4.2 mv:move,移動文件
mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE…
常用參數:
-i:交換式
-f:強制
使用實例:
1、移動/tmp目錄下的1.txt文件到/tmp/test文件夾下
[root@localhost tmp]# mv 1.txt /tmp/test
2、將/tmp目錄下1.txt改名為3.txt
[root@localhost tmp]# mv 1.txt 3.txt [root@localhost tmp]# ll 總用量 8 -rw-r--r--. 1 root root 0 7月 2 21:53 2.txt -rw-r--r--. 1 root root 0 7月 2 22:38 3.txt [root@localhost tmp]#
1.4.3 rm:remove,刪除
rm [OPTION]… FILE…
常用參數:
-i:交互式
-f:強制刪除
-r:遞歸
使用實例:
1、刪除/tmp目錄下的2.txt文件
[root@localhost tmp]# rm 2.txt
2、刪除/tmp目下的test文件夾包含其子文件
[root@localhost tmp]# rm -r test/
2、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示?
2.1 命令狀態返回值:在linux系統上,命令在執行的時候,一般有成功和失敗兩種狀態,如果執行成功將會得到命令執行后的結果和狀態返回值0,如果失敗將會得到1-255的錯誤號返回值;可以使用命令【echo $?】查看命令執行完成后的返回值,以下是從網上摘抄的一些錯誤返回值代表含義:
"OS error code 1: Operation not permitted"
"OS error code 2: No such file or directory"
"OS error code 3: No such process"
"OS error code 4: Interrupted system call"
"OS error code 5: Input/output error"
"OS error code 6: No such device or address"
"OS error code 7: Argument list too long"
"OS error code 8: Exec format error"
"OS error code 9: Bad file descriptor"
"OS error code 10: No child processes"
"OS error code 11: Resource temporarily unavailable"
"OS error code 12: Cannot allocate memory"
"OS error code 13: Permission denied"
"OS error code 14: Bad address"
"OS error code 15: Block device required"
"OS error code 16: Device or resource busy"
"OS error code 17: File exists"
"OS error code 18: Invalid cross-device link"
"OS error code 19: No such device"
"OS error code 20: Not a directory"
"OS error code 21: Is a directory"
"OS error code 22: Invalid argument"
"OS error code 23: Too many open files in system"
"OS error code 24: Too many open files"
"OS error code 25: Inappropriate ioctl for device"
"OS error code 26: Text file busy"
"OS error code 27: File too large"
"OS error code 28: No space left on device"
"OS error code 29: Illegal seek"
"OS error code 30: Read-only file system"
"OS error code 31: Too many links"
"OS error code 32: Broken pipe"
"OS error code 33: Numerical argument out of domain"
"OS error code 34: Numerical result out of range"
"OS error code 35: Resource deadlock avoided"
"OS error code 36: File name too long"
"OS error code 37: No locks available"
"OS error code 38: Function not implemented"
"OS error code 39: Directory not empty"
"OS error code 40: Too many levels of symbolic links"
"OS error code 42: No message of desired type"
"OS error code 43: Identifier removed"
"OS error code 44: Channel number out of range"
"OS error code 45: Level 2 not synchronized"
"OS error code 46: Level 3 halted"
"OS error code 47: Level 3 reset"
"OS error code 48: Link number out of range"
"OS error code 49: Protocol driver not attached"
"OS error code 50: No CSI structure available"
"OS error code 51: Level 2 halted"
"OS error code 52: Invalid exchange"
"OS error code 53: Invalid request descriptor"
"OS error code 54: Exchange full"
"OS error code 55: No anode"
"OS error code 56: Invalid request code"
"OS error code 57: Invalid slot"
"OS error code 59: Bad font file format"
"OS error code 60: Device not a stream"
"OS error code 61: No data available"
"OS error code 62: Timer expired"
"OS error code 63: Out of streams resources"
"OS error code 64: Machine is not on the network"
"OS error code 65: Package not installed"
"OS error code 66: Object is remote"
"OS error code 67: Link has been severed"
"OS error code 68: Advertise error"
"OS error code 69: Srmount error"
"OS error code 70: Communication error on send"
"OS error code 71: Protocol error"
"OS error code 72: Multihop attempted"
"OS error code 73: RFS specific error"
"OS error code 74: Bad message"
"OS error code 75: Value too large for defined data type"
"OS error code 76: Name not unique on network"
"OS error code 77: File descriptor in bad state"
"OS error code 78: Remote address changed"
"OS error code 79: Can not access a needed shared library"
"OS error code 80: Accessing a corrupted shared library"
"OS error code 81: .lib section in a.out corrupted"
"OS error code 82: Attempting to link in too many shared libraries"
"OS error code 83: Cannot exec a shared library directly"
"OS error code 84: Invalid or incomplete multibyte or wide character"
"OS error code 85: Interrupted system call should be restarted"
"OS error code 86: Streams pipe error"
"OS error code 87: Too many users"
"OS error code 88: Socket operation on non-socket"
"OS error code 89: Destination address required"
"OS error code 90: Message too long"
"OS error code 91: Protocol wrong type for socket"
"OS error code 92: Protocol not available"
"OS error code 93: Protocol not supported"
"OS error code 94: Socket type not supported"
"OS error code 95: Operation not supported"
"OS error code 96: Protocol family not supported"
"OS error code 97: Address family not supported by protocol"
"OS error code 98: Address already in use"
"OS error code 99: Cannot assign requested address"
"OS error code 100: Network is down"
"OS error code 101: Network is unreachable"
"OS error code 102: Network dropped connection on reset"
"OS error code 103: Software caused connection abort"
"OS error code 104: Connection reset by peer"
"OS error code 105: No buffer space available"
"OS error code 106: Transport endpoint is already connected"
"OS error code 107: Transport endpoint is not connected"
"OS error code 108: Cannot send after transport endpoint shutdown"
"OS error code 109: Too many references: cannot splice"
"OS error code 110: Connection timed out"
"OS error code 111: Connection refused"
"OS error code 112: Host is down"
"OS error code 113: No route to host"
"OS error code 114: Operation already in progress"
"OS error code 115: Operation now in progress"
"OS error code 116: Stale NFS file handle"
"OS error code 117: Structure needs cleaning"
"OS error code 118: Not a XENIX named type file"
"OS error code 119: No XENIX semaphores available"
"OS error code 120: Is a named type file"
"OS error code 121: Remote I/O error"
"OS error code 122: Disk quota exceeded"
"OS error code 123: No medium found"
"OS error code 124: Wrong medium type"
"OS error code 125: Operation canceled"
"OS error code 126: Required key not available"
"OS error code 127: Key has expired"
"OS error code 128: Key has been revoked"
"OS error code 129: Key was rejected by service"
"OS error code 130: Owner died"
"OS error code 131: State not recoverable"
"MySQL error code 132: Old database file"
"MySQL error code 133: No record read before update"
"MySQL error code 134: Record was already deleted (or record file crashed)"
"MySQL error code 135: No more room in record file"
"MySQL error code 136: No more room in index file"
"MySQL error code 137: No more records (read after end of file)"
"MySQL error code 138: Unsupported extension used for table"
"MySQL error code 139: Too big row"
"MySQL error code 140: Wrong create options"
"MySQL error code 141: Duplicate unique key or constraint on write or update"
"MySQL error code 142: Unknown character set used"
"MySQL error code 143: Conflicting table definitions in sub-tables of MERGE table"
"MySQL error code 144: Table is crashed and last repair failed"
"MySQL error code 145: Table was marked as crashed and should be repaired"
"MySQL error code 146: Lock timed out; Retry transaction"
"MySQL error code 147: Lock table is full; Restart program with a larger locktable"
"MySQL error code 148: Updates are not allowed under a read only transactions"
"MySQL error code 149: Lock deadlock; Retry transaction"
"MySQL error code 150: Foreign key constraint is incorrectly formed"
"MySQL error code 151: Cannot add a child row"
"MySQL error code 152: Cannot delete a parent row"
2.2 命令展開內容:
~:展開為用戶的主目錄,可以通過cd ~回到用戶家目錄;
~USERNAME:展開為指定用戶的主目錄,可以使用root用戶使用cd ~USERNAME進入任意用戶目錄;
{}:可承載一個以逗號分隔的列表,并將其展開為多個路徑,使用這個符號可以更有效率的創建目錄或者文件等……
例子 /tmp/{a,b} = /tmp/a,/tmp/b
/tmp/{tom,jerry}/hi = /tmp/tom/hi , /tmp/jerry/hi
3、請使用命令行展開功能來完成以下練習?
(1)、創建/tmp目錄下的:a_c, a_d, b_c, b_d
[root@localhost tmp]# touch /tmp/{a,b}_{c,d} [root@localhost tmp]# ll 總用量 16 drwxr-xr-x. 2 root root 4096 7月 2 23:53 a.c drwxr-xr-x. 2 root root 4096 7月 2 23:53 a.d -rw-r--r--. 1 root root 0 8月 25 2015 attrtest drwxr-xr-x. 2 root root 4096 7月 2 23:53 b.c drwxr-xr-x. 2 root root 4096 7月 2 23:53 b.d
(2)、創建/tmp/mylinux目錄下的:
mylinux/
├── bin
├── boot
│ └── grub
├── dev
├── etc
│ ├── rc.d
│ │ └── init.d
│ └── sysconfig
│ └── network-scripts
├── lib
│ └── modules
├── lib64
├── proc
├── sbin
├── sys
├── tmp
├── usr
│ └── local
│ ├── bin
│ └── sbin
└── var
├── lock
├── log
└── run
[root@localhost tmp]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/> {rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
4、文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息?
使用 stat file命令可查看文件的元數據信息,元數據里面大致有以下這些信息:
[root@localhost tmp]# stat 1.txt File: "1.txt" Size: 7872 Blocks: 16 IO Block: 4096 普通文件 Device: 802h/2050dInode: 389383 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2016-07-03 00:33:53.420132550 +0800 Modify: 2016-07-03 00:34:29.415134142 +0800 Change: 2016-07-03 00:34:29.417134044 +0800 [root@localhost tmp]#
File:文件名
Size:文件大小
Blocks:塊大小
IO Block:?
Device:?
Inode:indoe號
Links:連接數
Access:文件權限
Uid:屬主和屬主ID
Gid:屬組和屬組ID
Access: 2016-07-03 00:33:53.420132550 +0800:訪問時間,atime,讀取文件內容
Modify: 2016-07-03 00:34:29.415134142 +0800:修改時間,mtime,改變文件內容(數據)
Change: 2016-07-03 00:34:29.417134044 +0800:改變時間, ctime,元數據發生改變
5、如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?
5.1、命令別名(alias)
通過alias命令實現
(1)alias:顯示當前shell進程所有可用的命令別名;
(2)alias NAME='VALUE':定義別名NAME,其相當于執行命令VALUE;
注意:在命令行中定義的別名,僅對當前shell進程有效;如果想永久有效,要定義在配置文件中;
僅對當前用戶:~/.bashrc
對所有用戶有效:/etc/bashrc
使用實例:
[root@localhost tmp]# alias gohome="cd ~" [root@localhost tmp]# gohome [root@localhost ~]# pwd /root
5.2 在命令中引用另一個命令的執行結果
使用管道符"|"可以實現該功能,例如我想提取/etc/passwd的前三列內容,并以UID從小到大進行排序顯示:
[root@localhost ~]# cut -d: -f1-3 /etc/passwd | sort -n -k 3 -t: root:x:0 bin:x:1 daemon:x:2 adm:x:3 lp:x:4 sync:x:5 shutdown:x:6 halt:x:7 mail:x:8 uucp:x:10 operator:x:11 games:x:12 gopher:x:13 ftp:x:14 mysql:x:27 rpcuser:x:29 rpc:x:32 ntp:x:38 gdm:x:42 apache:x:48 webalizer:x:67 haldaemon:x:68 vcsa:x:69 tcpdump:x:72 sshd:x:74 dbus:x:81
6、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄?
[root@localhost ~]# ls -aR /var/1*[[:lower:]]
7、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄?
[root@localhost ~]# ls -aR /etc/[[:digit:]]*[^[:digit:]]
8、顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄?
ls -aR /etc/[^[:alpha:]][[:alpha:]]*
9、在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22?
[root@localhost tmp]# touch /tmp/tfile-$(date +'%Y-%m-%d-%H-%M-%S') [root@localhost tmp]# ll 總用量 0 -rw-r--r--. 1 root root 0 8月 25 2015 attrtest -rw-r--r--. 1 root root 0 7月 3 02:42 tfile-2016-07-03-02-42-35 [root@localhost tmp]#
10、復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中?
[root@localhost ~]# cp -av /etc/p*[^[:digit:]] /tmp/mytest1
11、復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中?
[root@localhost ~]# cp -av /etc/*.d /tmp/mytest2
12、復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中?
[root@localhost ~]# cp -av /etc/{1,m,n}*.conf /tmp/mytest3
不足總結:
1、在描述某個命令的時候,應減少一些不常見參數的描述,多增加一些實用的常用參數組合實例,避免華而不實;
2、在一些理論題,還是缺少自己對該技術的個人見解,只能摘抄馬哥和網上的理論知識作為答案回答,暫時只能加快學習速度增加知識廣度,后期靠練習之前的作業和復習筆記、閱讀參考書籍等增加個人的理論水平;
3、語言組織能力很差,寫出來的博客給人一種斷斷續續,無法首尾呼應,有種邏輯混亂的感覺,恩。。。。暫時只能向這方面比較強的人進行模仿,爭取后期能夠形成自己的一種有序的風格;
原創文章,作者:Net21_仲樂,如若轉載,請注明出處:http://www.www58058.com/21503
寫的很好,排版可以多關注一下,要理解你在網上找到的答案哦,加油
@馬哥教育:好的,爭取消化別人的東西變成自己的東西!