CentOS命令之顯示,建立,複製,移動,刪除

來源:互聯網
上載者:User

第一個顯示:相關命令ls,pwd

ls命令很強大,很常用,但也很難記

1-1,對於非內部命令(如ls、rm、mkdir等),無法使用help來查看協助

1-2,ll=ls-l//以長格式顯示

[root@localhost~]#ls

anaconda-ks.cfgDesktopinstall.loginstall.log.syslog

[root@localhost~]#ll

總計56

-rw-------1rootroot100902-1021:03anaconda-ks.cfg

drwxr-xr-x2rootroot409602-1021:35Desktop

-rw-r--r--1rootroot3203602-1021:02install.log

-rw-r--r--1rootroot364502-1020:59install.log.syslog

[root@localhost~]#

1-3,ls的選項:

-d(顯示目錄)

-l(長格式顯示)

-F(如果為檔案夾,則有/標示)

-R(遞迴查看目錄)

-A(顯示除了該目錄和上級目錄之外這兩個檔案夾之外的所有檔案,包括隱藏檔案)

-a(顯示所有檔案,包括隱藏檔案以及該目錄和上級目錄這兩個檔案夾)

-h(以容易讀取的方式來顯示該檔案或者檔案夾(如果顯示檔案夾,則需要和-d參數搭配用)的大小)

1-4,經典執行個體

[root@localhostdata]#ll-hd//hd搭配,長格式顯示當前檔案夾的屬性

drwxr-xr-x4rootroot4.0K02-1021:49.

[root@localhostdata]#ll//僅長格式顯示該目錄下的內容,可以看到兩個檔案夾,下面ll//-F更能顯示為檔案夾,後面有/標示

總計20

drwx------2rootroot1638402-1104:45lost+found

drwxr-xr-x3rootroot409602-1021:50VMtools

[root@localhostdata]#ll-F//長格式查看該檔案夾下的文檔,若為檔案夾,則右面後/標示,那麼此檔案夾//下包含有兩個檔案夾

總計20

drwx------2rootroot1638402-1104:45lost+found/

drwxr-xr-x3rootroot409602-1021:50VMtools/

[root@localhostdata]#cdVMtools///進入到VMtools檔案夾

[root@localhostVMtools]#ll//不加-h和下面加了-h的區別,加粗字型。。。

總計60668

-r-xr-xr-x1rootroot196102-1021:50manifest.txt

-r--r--r--1rootroot184702-1021:50run_upgrader.sh

-r--r--r--1rootroot6063846502-1021:50VMwareTools-9.6.1-1378637.tar.gz

drwxr-xr-x7rootroot409610-1809:26vmware-tools-distrib

-r-xr-xr-x1rootroot68945602-1021:50vmware-tools-upgrader-32

-r-xr-xr-x1rootroot70247202-1021:50vmware-tools-upgrader-64

[root@localhostVMtools]#ll-h//查看該檔案夾下的檔案大小,-h參數為易懂格式顯示大小,加粗字型//為區別

總計60M

-r-xr-xr-x1rootroot2.0K02-1021:50manifest.txt

-r--r--r--1rootroot1.9K02-1021:50run_upgrader.sh

-r--r--r--1rootroot58M02-1021:50VMwareTools-9.6.1-1378637.tar.gz

drwxr-xr-x7rootroot4.0K10-1809:26vmware-tools-distrib

-r-xr-xr-x1rootroot674K02-1021:50vmware-tools-upgrader-32

-r-xr-xr-x1rootroot687K02-1021:50vmware-tools-upgrader-64

[root@localhost~]#ls-R/boot///-R參數表示遞迴顯示/boot目錄

/boot/:

config-2.6.18-348.el5lost+foundvmlinuz-2.6.18-348.el5

grubsymvers-2.6.18-348.el5.gz

initrd-2.6.18-348.el5.imgSystem.map-2.6.18-348.el5


/boot/grub:

device.mapgrub.confminix_stage1_5stage2

e2fs_stage1_5iso9660_stage1_5reiserfs_stage1_5ufs2_stage1_5

fat_stage1_5jfs_stage1_5splash.xpm.gzvstafs_stage1_5

ffs_stage1_5menu.lststage1xfs_stage1_5


/boot/lost+found:


2,pwd命令

單純的顯示目前所在的路徑

[root@localhostnetwork-scripts]#pwd

/etc/sysconfig/network-scripts

[root@localhostnetwork-scripts]#cd..

[root@localhostsysconfig]#pwd

/etc/sysconfig

[root@localhostsysconfig]#

第二個:建立之mkdir

用法:mkdir[選項]目錄...

若目錄不存在則建立目錄。


長選項必須用的參數在使用短選項時也是必須的。

-m,--mode=模式設定許可權<模式>(類似chmod),而不是rwxrwxrwx減umask

-p,--parents需要時建立上層目錄,如目錄早已存在則不當作錯誤

-v,--verbose每次建立新目錄都顯示資訊

--help顯示此協助資訊並退出

--version輸出版本資訊並退出

加上-p之後就不會提示什麼錯誤了,不論你是重複簡曆了相同的目錄還是你建立了目錄下的兩一個目錄:

[root@localhost~]#ls

anaconda-ks.cfgDesktopinstall.loginstall.log.syslog

[root@localhost~]#mkdira

[root@localhost~]#ls

aanaconda-ks.cfgDesktopinstall.loginstall.log.syslog

[root@localhost~]#mkdira

mkdir:無法建立目錄“a”:檔案已存在

[root@localhost~]#mkdir-pa

[root@localhost~]#mkdira/aa/aaa

mkdir:無法建立目錄“a/aa/aaa”:沒有那個檔案或目錄

[root@localhost~]#mkdir-pa/aa/aaa

[root@localhost~]#ls

aanaconda-ks.cfgDesktopinstall.loginstall.log.syslog

[root@localhost~]#ls-R

.:

aanaconda-ks.cfgDesktopinstall.loginstall.log.syslog


./a:

aa


./a/aa:

aaa


./a/aa/aaa:


./Desktop:

[root@localhost~]#

第三個:建立連結檔案之ln

1,不加參數的時候為建立永久連結,不可跨分區

[root@localhost~]#ln/etc/passwd./passwd//在root家目錄建立/etc/passwd的永久連結

ln:正在建立指向“/etc/passwd”的永久連結“./passwd”:檔案已存在

[root@localhost~]#ll

總計60

drwxr-xr-x3rootroot409602-1200:08a

-rw-------1rootroot100902-1021:03anaconda-ks.cfg

drwxr-xr-x3rootroot409602-1200:25Desktop

-rw-r--r--1rootroot3203602-1021:02install.log

-rw-r--r--1rootroot364502-1020:59install.log.syslog

lrwxrwxrwx1rootroot1102-1200:11passwd->/etc/passwd

[root@localhost~]#ls

aanaconda-ks.cfgDesktopinstall.loginstall.log.syslogpasswd

[root@localhost~]#cd/boot//到boot目錄下

[root@localhostboot]#ln/etc/passwd./passwd//在boot目錄下建立/etc/passwd的永久連結,是不能被//建立的,我在分區的時候,掛在到/boot目錄下的那個磁碟//空間為獨立劃分出來的磁碟空間,永久連結無法跨裝置串連,所以無法建立。

ln:正在建立指向“/etc/passwd”的永久連結“./passwd”:無效的跨裝置串連

[root@localhostboot]#ln-s/etc/passwd./passwd//可以看到,ln-s建立的軟串連是可以跨分區的

[root@localhostboot]#ll

總計6333

-rw-r--r--1rootroot678572012-11-29config-2.6.18-348.el5

drwxr-xr-x2rootroot102402-1021:03grub

-rw-------1rootroot283762602-1021:54initrd-2.6.18-348.el5.img

drwx------2rootroot1228802-1104:45lost+found

lrwxrwxrwx1rootroot1102-1212:44passwd->/etc/passwd

-rw-r--r--1rootroot1186262012-11-29symvers-2.6.18-348.el5.gz

-rw-r--r--1rootroot12824242012-11-29System.map-2.6.18-348.el5

-rw-r--r--1rootroot21256602012-11-29vmlinuz-2.6.18-348.el5

[root@localhostboot]#

2,-s參數表示建立一個捷徑(軟串連)

[root@localhost~]#ln-s/etc/passwdpasswd

[root@localhost~]#ll

總計60

drwxr-xr-x3rootroot409602-1200:08a

-rw-------1rootroot100902-1021:03anaconda-ks.cfg

drwxr-xr-x2rootroot409602-1021:35Desktop

-rw-r--r--1rootroot3203602-1021:02install.log

-rw-r--r--1rootroot364502-1020:59install.log.syslog

lrwxrwxrwx1rootroot1102-1200:11passwd->/etc/passwd

[root@localhost~]#

第四個:複製之cp

常用命令選項:

-i:當有相同檔案存在時,提示是否覆蓋

-r:遞迴複製整個目錄(複製一個目錄的時候需要加上r參數)

-f:強制覆蓋,不提示(與-i相對)

-p:保持源檔案的屬性不變


註:在使用cp的時候,可以先查看一下alias命令,cp命令預設的為cp–i,也就是在使用cp過程中,實際上是用的cp–i,即在有覆蓋的時間提醒,那麼,現在如果想用cp–f取消提示,就必須先取消cp=cp–i;或者是加上一個轉義符#\cp–ffile1.txt/host/test/

常用的命令有:

[root@localhost~]#cp-r/boot/grub//etc/host.confDesktop///將grub目錄和host.conf檔案複製到//Desktop目錄

[root@localhost~]#lsDesktop/

grubhost.conf

[root@localhost~]#cp-rf/boot/grub//etc/host.confDesktop///這時候不會提醒覆//蓋,若不加f參數,將會一個一個提醒

[root@localhost~]#ls-FDesktop/

grub/host.conf

[root@localhost~]

第五個:移動和重新命名之mv

[root@localhost~]#ls

aanaconda-ks.cfgDesktopinstall.loginstall.log.syslogpasswd

[root@localhost~]#touchfile1

[root@localhost~]#mvfile1file2//將file1的名字改為file2

[root@localhost~]#ls

aanaconda-ks.cfgDesktopfile2install.loginstall.log.syslogpasswd

[root@localhost~]#mvfile2Desktop///將file2移動到該目錄下的Desktop目錄下

[root@localhost~]#lsDesktop/

file2grubhost.conf

[root@localhost~]#

第六個:刪除之rm和rmdir

rm參數和cp參數相似,主要為r和f

-f為不提醒

-r為遞迴刪除一個目錄(加上-r才能刪除目錄)

[root@localhostDesktop]#rm-rgrub///加-r參數,為遞迴刪除一個目錄

rm:是否進入目錄“grub/”?

[root@localhostDesktop]#rmgrub///不加-r參數是無法刪除目錄的

rm:無法刪除目錄“grub/”:是一個目錄

[root@localhostDesktop]#rm-rgrub/

rm:是否進入目錄“grub/”?

//輸入y一個一個刪除,每一步都需要提示是否確認,這時加上-f參數取消提醒

[root@localhostDesktop]#rm-rfgrub///-rf刪除目錄不帶提醒的,強制遞迴刪除

[root@localhostDesktop]#ls//grub目錄被刪除了

file2host.conf

[root@localhostDesktop]#

rmdir只能刪除一個空的目錄,所以不需要使用了,知道rm-rf就能刪除任何目錄了,但是很危險



簡單的命令我會記住,但是參數我卻常常忘記,以此小記!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.