




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、,第2章 Shell及常用命令,2.1 Shell的基本形式 2.2 幫助命令 2.3 文件與目錄的基本概念 2.4 目錄和文件的基本操作 2.5 歸檔與壓縮命令 2.6 其它常用命令,2.1 Shell的基本形式,Shell是一個(gè)命令解釋器,它可以用來(lái)啟動(dòng)、掛起、停止程序,還允許用戶編寫由Shell命令組成的程序。 在/etc/shells文件中理出了系統(tǒng)可以接受的shell,默認(rèn)安裝的Red Hat Linux 9中的shells文件的內(nèi)容如下:,Shell的基本形式,可以查看這些Shell的詳細(xì)情況:,Shell的種類: ash:貝爾實(shí)驗(yàn)室開發(fā)的shell;bsh是對(duì)它的符號(hào)鏈接 bas
2、h:GNU的Bourne Again shell,是GNU操作系統(tǒng)上默認(rèn)的shell;sh是對(duì)它的符號(hào)鏈接 tcsh:Berkeley UNIX C shell;csh是對(duì)它的符號(hào)鏈接,Shell命令的基本格式,格式:命令名 選項(xiàng) 表示可選項(xiàng) “選項(xiàng)”是對(duì)命令的特別定義。 以“-”開頭的選項(xiàng)通常只有一個(gè)字母,多個(gè)選項(xiàng)可以用一個(gè)“-”連接起來(lái);如“l(fā)s -a -l”與“l(fā)s -al”是等價(jià)的。 有的選項(xiàng)以“-”開頭,這些選項(xiàng)通常是一個(gè)單詞,如-number。 很多“-”格式的選項(xiàng)也有用“-”加上首字母的簡(jiǎn)寫方式。,命令格式舉例,RIGHT WRONG 1. Separation $ mail -
3、f personal $ mail - f personal $ who -u $ who-u 2. Order $ mail -s test root $ mail test root -s $ who -u $ -u who 3. Multiple options $ who -m -u $ who -m-u $ who -mu $ who -m u,命令自動(dòng)補(bǔ)全,如果輸入了文件名、命令或路徑名的一部分,然后按Tab鍵,則: 如果能匹配唯一的文件名,則bash將把文件名的剩余部分補(bǔ)全; 如果能匹配多個(gè)文件名,可以再按一次Tab鍵來(lái)獲取與已輸入部分匹配的文件名或路徑名的列表。,查看命令歷史,
4、使用上、下箭頭可以上下翻閱已輸入過(guò)的命令 方便輸入重復(fù)的或類似于以前輸入過(guò)的命令 bash命令行歷史文件中默認(rèn)可以儲(chǔ)存500條命令,2.2 幫助命令,man命令 info命令 whereis命令 -help選項(xiàng),(1) man命令,查看命令的手冊(cè)頁(yè)(manual pages),它存放在/usr/share/man下。 手冊(cè)頁(yè)的組成:,man命令的格式,man 選項(xiàng) 命令名稱 常用選項(xiàng): -f:只顯示命令的功能而不顯示其中詳細(xì)的說(shuō)明文件。 -w:不顯示手冊(cè)頁(yè),只顯示將被格式化和顯示的文件所在的位置 -k:顯示和給定關(guān)鍵字相關(guān)的所有命令。,man example (1),man example (
5、2),(2) info命令,info是另一個(gè)非常有用的幫助命令。 命令格式: info 命令名 其信息存放在/usr/share/info下。,info舉例,# info pwd,(3) whereis:尋找命令所在位置,命令格式:whereis 選項(xiàng) 命令名 常用選項(xiàng):,whereis舉例,以ls命令為例,(4) - help選項(xiàng),help是內(nèi)置在命令中的,2.3 文件與目錄的基本概念,2.3.1 文件與文件類型 Linux的文件均為無(wú)結(jié)構(gòu)的字符流形式。 文件名的命名規(guī)則 Linux系統(tǒng)有三種基本的文件類型: 普通文件 文本文件 二進(jìn)制文件 目錄文件,簡(jiǎn)稱為目錄 設(shè)備文件 塊設(shè)備文件 字符設(shè)
6、備文件,2.3.2 目錄,Linux通過(guò)目錄將系統(tǒng)中所有的文件分級(jí)、分層組織在一起,形成樹形層次結(jié)構(gòu),以根目錄 “/” 為起點(diǎn)。 特殊目錄: “.”代表該目錄自己, “.”代表該目錄的父目錄, 對(duì)于根目錄,“.”和“.”都代表其自己。,2.3.3 Linux的標(biāo)準(zhǔn)文件系統(tǒng),All Linux directories are contained in one, virtual, unified filesystem Physical devices are mounted on mount points Floppy disks Hard disk partitions CD-ROM drive
7、s No drive letters like A:, C:, .,Linux的標(biāo)準(zhǔn)文件系統(tǒng),/bin, /lib, /sbin,/bin contains executables for every user /sbin contains system administration executables /lib contains libraries Should always be available At system boot In single user mode When booting from rescue disk Can not be in separate filesy
8、stems(不能作為獨(dú)立的文件系統(tǒng)),/boot,Contains kernel image and some other goodies Should be located below cylinder 1023 and/or 8 GB (earlier version) Good habit to always make it a separate filesystem,/dev,Contains special files that represent hardware devices Block special device, for example, a hard disk Char
9、acter special device, for example, mouse and keyboard Each device has a major and minor number Identification within the kernel Can not be a separate filesystem,/etc,Contains system-wide configuration files Some subsystems have multiple files and therefore use a separate directory /etc/X11 contains
10、X Window System configuration /etc/skel contains default user configuration files /etc/sysconfig contains system configuration Can not be a separate filesystem,/home,Home directories of users Can be a separate filesystem,/mnt,Mount points for other filesystems Can be a separate filesystem Note: SuSE
11、 uses /media instead of /mnt for floppy and cdrom mountpoints,/proc,Virtual filesystem Represents kernel and process information,/root,Home directory of the root user Should not be a separate filesystem,/tmp,Temporary storage space for programs, users Can be a separate filesystem Sometimes automatic
12、 cleanup mechanism active,/usr,UNIX System Resources Contains all programs, libraries and so on which are not essential for system boot and emergency operations Can be a separate filesystem Can be mounted over NFS(可通過(guò)NFS掛載) Can be read-only /usr/local intended for programs not in the distribution Ma
13、y be a separate filesystem too,/var,Files of variable size logfiles lockfiles Directories with variable content mail scheduling printing Temporary storage space, longer than /tmp Can be a separate filesystem,/lost+found,Exists in every filesystem Place where lost+found files are stored after a crash
14、 recovery by fsck.,Other Directories in /,/opt: used for some software from external providers Separate filesystem advisable Whatever you create yourself.,Linux的標(biāo)準(zhǔn)文件系統(tǒng),以下文件系統(tǒng)可以作為獨(dú)立的文件系統(tǒng)存在: /boot /home /mnt /tmp /usr /var,2.3.4 工作目錄、用戶主目錄與路徑,工作目錄(Working Directory):用戶登錄到系統(tǒng)后,每時(shí)每刻都處在某個(gè)目錄之中,此目錄稱為工作目錄。 用
15、戶主目錄(Home Directory):是系統(tǒng)管理員在增加用戶時(shí)為該用戶建立起來(lái)的目錄,每個(gè)用戶都有自己的主目錄。 使用符號(hào)表示。 默認(rèn)情況下,用戶主目錄是/home目錄下與用戶名相同的目錄。 例:用戶lh的主目錄是/home/lh,命令 cd 和命令 cd /home/lh意義相同。 絕對(duì)路徑 相對(duì)路徑,通配符,*:匹配零或多個(gè)字符 ?:匹配任意一個(gè)字符 :該通配符把所有想匹配的字符放在 內(nèi),結(jié)果表達(dá)式將與 中任一字符相匹配;也可以使用 - 指定范圍。例如: myfile12將與myfiel1和myfile2匹配。 CchangeLlog將與Changelog、ChangeLog、chan
16、gelog、changeLog匹配。 ls /etc/0-9*將列出/etc中以數(shù)字開頭的所有文件。,通配符,! !與 構(gòu)造類似,只要不是列在 ! 和 之間的字符,它將與任何字符匹配。例:myfile!9匹配除myfile9之外的名為myfile加一個(gè)字符的所有文件。,2.4 目錄和文件的基本操作,pwd, cd, ls cat, more, less cp, rm ,mv mkdir ,rmdir touch find, locate ln,pwd:打印當(dāng)前工作目錄,pwd:打印當(dāng)前工作目錄,Print Working Directory,$ pwd /home/tux1 $,cd :切換目
17、錄,$ cd doc (relative) $ cd /home/tux1/doc (full) $ cd tux1/doc (home) $ cd (Go to your home directory) $ cd (Go to your home directory) $ cd . (Go one directory up) $ cd - (Go to previous directory),ls :顯示目錄內(nèi)容,格式:ls dir/file ,$ ls /home tux1 tux2 tux3 Important options: -l long listing (more informa
18、tion) -a lists all files (including hidden) -t lists files sorted by change date -R lists contents recursively,在Shell下使用ls命令顯示目錄及文件的顏色是不一樣的: 目錄:藍(lán)色 普通文件:白色 可執(zhí)行文件:綠色,ls :顯示目錄內(nèi)容,cat (concatenate), more, less,cat:顯示文件內(nèi)容 格式:cat filename more, less:分屏顯示文件內(nèi)容 看完一頁(yè)后按空格鍵向后翻頁(yè),按Enter鍵往下滾動(dòng)一行,按Q鍵退出顯示 more和less的區(qū)別
19、在于: more顯示的內(nèi)容只能向后翻頁(yè); less顯示的內(nèi)容可以前后翻頁(yè),用B鍵向前翻頁(yè),并且支持PageUp和PageDown鍵上下翻頁(yè)。,mkdir :創(chuàng)建子目錄,使用-p選項(xiàng)可以一次創(chuàng)建多層空目錄,$ mkdir /home/tux1/doc (full pathname) $ cd /home/tux1 $ mkdir doc (relative pathname),rmdir :刪除目錄,格式:rmdir dir_name 注意:rmdir只能刪除空目錄。 使用-p選項(xiàng)可以一次刪除多層空目錄。,rm :刪除文件或目錄,要?jiǎng)h除目錄,必須指定-r選項(xiàng),此時(shí)將會(huì)刪除目錄下的所有文件,然后刪
20、除該目錄,$ rm test/rob If unsure, use -i option $ rm -i test/rob rm: remove test/rob? To remove files and directories recursively: $ rm -ir test/,cp :復(fù)制文件,格式:cp sources target,Copying one file to another: $ cp .bashrc bashrc.old Copying multiple files into a target directory: $ cp doc/mon_report doc/wal
21、rus /tmp,-R選項(xiàng):遞歸地復(fù)制目錄,$ cp -R /home/tux1/doc /tmp To prevent cp from overwriting existing files, use: $ cp -R -i /home/tux1/doc /tmp cp: overwrite /tmp/doc/walrus?,mv :移動(dòng)文件,重命名,格式:mv sources target mv默認(rèn)以遞歸的方式移動(dòng) 如果名稱與目標(biāo)位置一樣,其作用就是更改目錄或文件名,To move a file to another directory: $ mv doc/walrus ././tmp To
22、 rename a file: $ mv doc documents Use the -i option to prevent mv from overwriting existing files!,touch,The touch command updates the access and/or modification times of a file.,$ ls -l -rw-rw-r- - 1 tux1 penguins 512 Feb 24 11:10 docs $ touch docs $ ls -l -rw-rw-r- - 1 tux1 penguins 512 Mar 5 15:
23、37 docs $ touch new $ ls -l -rw-rw-r- - 1 tux1 penguins 512 Mar 5 15:37 docs -rw-rw-r- - 1 tux1 penguins 0 Mar 5 15:37 new,find,格式:find path expression 該命令在目錄樹層次中從path開始向下查找文件,將符合expression要求的文件列出來(lái)。,find / -name test 從根目錄開始,查找所有名稱為test的文件 find . -cmin -20 查找當(dāng)前目錄(也包含其所有的子目錄)下所有最近20分鐘內(nèi)更新過(guò)的文件 find /usr
24、/ -size 50K 查找/usr目錄(也包含其所有的子目錄)下超過(guò)50K的文件,locate:搜索文件,使用locate命令,可以看到每一個(gè)包括搜尋條件的目錄或文件。例如要搜尋名稱中帶有finger這個(gè)詞的文件,輸入命令: $ locate finger 搜索結(jié)果為:所有文件或目錄名中帶有finger這個(gè)詞的文件和目錄。 locate命令使用一個(gè)數(shù)據(jù)庫(kù)來(lái)定位所有文件或目錄名中帶有finger這個(gè)詞的文件和目錄。,ln: 鏈接命令,命令格式: ln 選項(xiàng) 該命令產(chǎn)生一個(gè)從dest到source的鏈接。 在UNIX/Linux文件系統(tǒng)中,鏈接可分為: 硬鏈接 符號(hào)鏈接,硬鏈接,系統(tǒng)調(diào)用link
25、在文件系統(tǒng)結(jié)構(gòu)中將一個(gè)文件鏈接到另外一個(gè)新的名字上,也就是為被鏈接文件的索引節(jié)點(diǎn)創(chuàng)建一個(gè)新的目錄項(xiàng)。 通過(guò)鏈接操作,一個(gè)文件可以有兩個(gè)以上的不同名字,系統(tǒng)可以通過(guò)其中任意一個(gè)名字來(lái)訪問(wèn)文件。內(nèi)核并不知道哪個(gè)名字是最初的文件名。 這種為索引節(jié)點(diǎn)創(chuàng)建新目錄項(xiàng)的鏈接方式稱為“硬鏈接”。,一個(gè)給定的索引節(jié)點(diǎn)可以有任意數(shù)目的硬鏈接,該索引節(jié)點(diǎn)一直存在于文件系統(tǒng),直到所有的硬鏈接消失。 可以使用ln命令來(lái)創(chuàng)建新的硬鏈接:,$ cd /tmp$ touch firstlink$ ln firstlink secondlink$ ls i firstlink secondlink15782 firstlink
26、 15782 secondlink,硬鏈接,用ln命令創(chuàng)建硬鏈接,硬鏈接工作于索引節(jié)點(diǎn)級(jí)別,指向特殊的文件 硬鏈接的局限性: 只能給文件建立硬鏈接,而不能給目錄建立硬鏈接。即使. 和 . 是系統(tǒng)給目錄創(chuàng)建的硬鏈接,也不允許用戶創(chuàng)建自己的硬鏈接。 硬鏈接不能跨文件系統(tǒng)。,硬鏈接,符號(hào)鏈接,與 “硬鏈接”類似,也為新名字創(chuàng)建一個(gè)新的目錄項(xiàng),但是目錄項(xiàng)中不含有索引節(jié)點(diǎn)號(hào),而是含有從當(dāng)前目錄下訪問(wèn)被鏈接文件的相對(duì)路徑名或絕對(duì)路徑名。 當(dāng)進(jìn)程使用新名字訪問(wèn)文件時(shí),內(nèi)核首先找到新名字所在的目錄項(xiàng),發(fā)現(xiàn)目錄項(xiàng)中含有符號(hào)鏈接標(biāo)志,然后從目錄項(xiàng)中讀出被鏈接文件的路徑名,按此路徑名訪問(wèn)指定的文件。,符號(hào)鏈接是一種
27、專門的文件類型,在這種文件類型中,鏈接通過(guò)名稱引用另一個(gè)文件,而不是直接引用索引節(jié)點(diǎn)。 符號(hào)鏈接不阻止文件被刪除;如果源文件被刪除,那么符號(hào)鏈接仍然存在,但是不可用。,符號(hào)鏈接,在ls-l輸出中,可以用三種方式區(qū)分符號(hào)鏈接和一般文件: 第一欄包含一個(gè)l字符 符號(hào)鏈接的大小是目標(biāo)文件名的字符數(shù) 輸出的最后一欄顯示目標(biāo)文件名,$ln s secondlink thirdlink$ls l firstlink secondlink thirdlink -rw-rw-r- 2 agriffis agriffis 0 Dec 31 19:08 firstlink -rw-rw-r- 2 agriffis
28、 agriffis 0 Dec 31 19:08 secondlink lrwxrwxrwx 1 agriffis agriffis 10 Dec 31 19:39 thirdlink - secondlink,通過(guò)ln 的-s選項(xiàng),可以創(chuàng)建符號(hào)鏈接:,用ln -s命令創(chuàng)建符號(hào)鏈接,符號(hào)鏈接的優(yōu)點(diǎn),符號(hào)鏈接比硬鏈接更靈活 可以給任何類型的文件系統(tǒng)對(duì)象(包括目錄)創(chuàng)建符號(hào)鏈接 因?yàn)榉?hào)鏈接的實(shí)現(xiàn)是基于路徑的,所以符號(hào)鏈接可以跨文件系統(tǒng),2.5 歸檔與壓縮命令,歸檔文件(archive file)是一個(gè)文件和目錄的集合,而這個(gè)集合被存儲(chǔ)在一個(gè)文件中。歸檔文件沒有經(jīng)過(guò)壓縮。 壓縮文件(compres
29、sed file)也是一個(gè)文件和目錄的集合,這個(gè)集合也被存儲(chǔ)在一個(gè)文件中,但是,它的存儲(chǔ)方式所占用的磁盤空間比所有文件和目錄的總和要少。 歸檔文件可以壓縮也可以不壓縮,壓縮的歸檔文件才是壓縮文件。,1. 壓縮文件,壓縮工具,(1) zip和unzip,壓縮文件,例:$ zip r filename.zip file1 file2 dir ,從zip文件中刪除文件: $ zip d filename.zip file1 file2 ,解壓文件:$ unzip filename.zip 顯示zip文件內(nèi)容:$ unzip v filename.zip 指定解壓縮的目錄(unzip默認(rèn)將文件解壓到當(dāng)
30、前目錄)$ unzip filename.zip d dir,(2) gzip和gunzip,壓縮文件:$ gzip myfile文件即會(huì)被壓縮并保存為myfile.gz 解壓文件:$ gunzip myfile.gz myfile.gz文件會(huì)被刪除,而產(chǎn)生myfile文件,(3) bzip2和bunzip2,壓縮文件:$ bzip2 myfile 文件即會(huì)被壓縮并保存為myfile.bz2 解壓文件,使用命令:$ bunzip2 myfile.bz2 myfile.bz2文件會(huì)被刪除,而產(chǎn)生myfile文件,2. 文件歸檔,.tar文件是幾個(gè)文件和(或)目錄在一個(gè)文件中的集合 使用在tar命令上的選項(xiàng)有:,創(chuàng)建tar文件,$ tar -cvf filename.tar files/dir,$ tar cvf file.tar file1 file2 filedir file1 file2 filedir/ filedir/filea filedir/fileb,顯示tar文件內(nèi)容,$ tar tf filename.tar,$ tar tf file.tar file1 file2 filedir/ filedir/filea filedir/fileb,向tar文件內(nèi)加入文件,$ tar rvf filen
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度國(guó)際教育項(xiàng)目全新留學(xué)合同
- 2025年度員工股權(quán)激勵(lì)計(jì)劃實(shí)施協(xié)議書
- 2025年度文化創(chuàng)意公司兼職聘用員工合同
- 2025年度一手房帶家具家電裝修包購(gòu)服務(wù)協(xié)議
- 2025年度中式餐廳轉(zhuǎn)讓及品牌推廣合同
- 醫(yī)院裝修監(jiān)理合作協(xié)議
- 2025年度出租房屋裝修工程結(jié)算及租賃服務(wù)協(xié)議
- 2025年度安全生產(chǎn)達(dá)標(biāo)廠房租賃服務(wù)合同
- 2025年度健身機(jī)構(gòu)教練職務(wù)聘用協(xié)議
- 2025年度商鋪物業(yè)管理與社區(qū)文化活動(dòng)合作協(xié)議
- 精品課程建設(shè)驗(yàn)收自評(píng)報(bào)告
- 福建省義務(wù)教育課程設(shè)置及比例(修訂)
- 認(rèn)知語(yǔ)言學(xué)王寅讀書筆記
- 一年級(jí)上冊(cè)生字卡片帶拼音組詞可打印01637
- 未成年人需辦銀行卡證明(模板)
- 建設(shè)項(xiàng)目職業(yè)病防護(hù)設(shè)施設(shè)計(jì)專篇編制導(dǎo)則
- 員工考勤流程圖
- C21甾體化合物 (2)
- 出口加工區(qū)外匯管理培訓(xùn)(ppt49)
- 初中學(xué)生綜合素質(zhì)評(píng)價(jià)填寫示例
- 國(guó)家開放大學(xué)(湖南)
評(píng)論
0/150
提交評(píng)論