linux基礎:7、基礎命令介紹(2)

來源:互聯網
上載者:User

標籤:linux 基礎命令

目錄相關命令)


mkdir

作用:make directories 建立目錄

文法:mkdir [選項] 目錄名稱

選項:

    -p 級聯建立目錄,如果目標目錄已存在不會報錯

==================================================================================#1、同一目錄下目錄檔案和普通檔案不可重名,因為在linux下目錄檔案和普通檔案都被視為檔案[[email protected] ~]# ls -l test1-rw-r--r--. 1 root root 60 Mar  4 23:17 test1[[email protected] ~]# mkdir test1mkdir: cannot create directory `test1‘: File exists2、-p參數的使用[[email protected] ~]# mkdir aa/bb/ccmkdir: cannot create directory `aa/bb/cc‘: No such file or directory[[email protected] ~]# mkdir -p aa/bb/cc                #加上-p參數建立成功[[email protected] ~]# tree aa                          #tree命令,看一下目錄結構aa└── bb    └── cc2directories, 0 files[[email protected] ~]# ls -ld aadrwxr-xr-x. 3 root root 4096 Mar  5 02:44 aa[[email protected] ~]# mkdir -p aa#aa目錄已存在,但加上-p以後目錄重複並不會報錯,也不會改變aa目錄的內容和屬性==================================================================================

rm

作用:remove files or directories 刪除檔案

文法:rm [選項] 檔案名稱

選項:

    -r recursive 遞迴的刪除目錄檔案及其內容

    -f force 強制移除,不會提示使用者,哪怕此檔案並不存在

===================================================================================#1、-r選項[[email protected] ~]# ls ./dir1text1[[email protected] ~]# rm dir1rm: cannot remove `dir1‘: Is a directory      #rm不加-r選項無法刪除目錄檔案[[email protected] ~]# rm -r dir1rm: descend into directory `dir1‘? yrm: remove regular empty file `dir1/text1‘? yrm: remove directory `dir1‘? y#2、-f選項[[email protected] ~]# ls dir2test2[[email protected] ~]# rm -rf dir2                   #並不會做任何提示,直接刪除[[email protected] ~]# ls badls: cannot access bad: No such file or directory[[email protected] ~]# rm -f bad                     #bad檔案並不存在,加上-f選項後不會提示===================================================================================



cp

作用:copy files and directories 複製檔案

文法:cp [選項] 源檔案/目錄 目標檔案/目錄

選項:

    -r 遞迴複製目錄及其內容

    -p 保留檔案時間戳記、擁有者、許可權等資訊

==================================================================================#1、-r選項[[email protected] ~]# ls -l dir3total 0-rw-r--r--. 1 root root 0 Mar  5 04:34 test3[[email protected] ~]# cp dir3 dir4cp: omitting directory `dir3‘[[email protected] ~]# cp -r dir3 dir4[[email protected] ~]# ls -l dir4total 0-rw-r--r--. 1 root root 0 Mar  5 04:35 test3      #可以看出來test3檔案的時間戳記改變了#2、-p選項[[email protected] home]# ll /hometotal 4drwx------. 2 nagios nagios 4096 Mar  4 04:36 nagios[[email protected] home]# cp -rp /home/nagios /tmp/[[email protected] home]# ll -d /tmp/nagiosdrwx------. 2 nagios nagios 4096 Mar  4 04:36 /tmp/nagios  #保留了屬主、屬組、時間及許可權==================================================================================


mv

作用:move (rename) files 移動(重新命名)檔案

文法:mv [選項] 源檔案/目錄 目標檔案/目錄

選項:

    -f force 覆蓋檔案時不提示

====================================================================================#1、-f選項[[email protected] dir4]# ll test*-rw-r--r--. 1 root root 0 Mar  5 04:35 test3-rw-r--r--. 1 root root 0 Mar  5 04:53 test4[[email protected] dir4]# mv test3 test4mv: overwrite `test4‘? n                     #因為test4已存在,所以會提示是否覆蓋[[email protected] dir4]# mv -f test3 test4[[email protected] dir4]# ll test*-rw-r--r--. 1 root root 0 Mar  5 04:35 test4 #查看結果,test4已被覆蓋====================================================================================


文檔命令)


touch

作用:可以修改檔案時間參數,當touch目標檔案不存在時會建立它。

文法:touch filename

PS:時間參數包含

    atime:accesstime 訪問時間;

    mtime:modifytime 修改內容時間;

    ctime:changetime 改變檔案許可權時間

===============================================================================#1、修改時間參數[[email protected] ~]# stat test11       #查看test11檔案的狀態資訊  File: `test11‘  Size: 3               Blocks: 8          IO Block: 4096   regular fileDevice: 802h/2050d      Inode: 12121       Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2015-03-05 04:44:01.088979285 +0800Modify: 2015-03-05 04:43:53.537979166 +0800Change: 2015-03-05 04:43:53.537979166 +0800[[email protected] ~]# touch test11      #touch一下[[email protected] ~]# stat test11       #再看一下,發現三個時間改變了吧  File: `test11‘  Size: 3               Blocks: 8          IO Block: 4096   regular fileDevice: 802h/2050d      Inode: 12121       Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2015-03-05 05:26:11.701977204 +0800Modify: 2015-03-05 05:26:11.701977204 +0800Change: 2015-03-05 05:26:11.701977204 +0800#2、建立普通檔案[[email protected] ~]# ll test*-rw-r--r--. 1 root root 3 Mar  5 05:26 test11-rw-r--r--. 1 root root 6 Mar  5 04:44 test22[[email protected] ~]# touch test33[[email protected] ~]# ll test*-rw-r--r--. 1 root root 3 Mar  5 05:26 test11-rw-r--r--. 1 root root 6 Mar  5 04:44 test22-rw-r--r--. 1 root root 0 Mar  5 05:28 test33================================================================================

 

cat

作用:查看文檔內容並在終端介面輸出

文法:cat filename

PS:可以通過cat > file的方式向file中輸入鍵盤上敲打的字元

================================================================================[[email protected] ~]# cat > test22hahahahagood                           #按下ctrl+d退出[[email protected] ~]# cat test22hahahahagood================================================================================

 

tac

作用:與cat輸出的內容順序上下顛倒

文法:tac filename

 

more

作用:分屏輸出文檔內容,可向下翻頁查看。

文法:more filename

操作方式:按下空格鍵,向下翻屏

 

less

作用:分屏輸出文檔內容,可上下翻頁或上下翻行查看。

文法:less filename

操作方式:

    按下空格鍵,向下翻屏;

    按上下箭頭翻行; 

    按j鍵,向下移動一行,按k鍵,向上移動一行;

    按ctrl+f,向下翻頁;

    按ctrl+b,向上翻頁;

    按shift+G,前往文檔最上面;

    按shift+g,前往文檔最下面。

 

head

作用:標準輸出文檔頭部N行

文法:head [選項] filename

選項:

    -n 輸出文檔頭部n行(例如head -n 行數 filename / head -行數 filename)

PS:沒有-n參數的話,預設輸出前十行。

 

tail

作用:標準輸出文檔尾部N行

文法:tail [選項] filename

選項:

    -n 輸出文檔頭部n行(例如tail -n 行數 filename / tail -行數 filename)

    -f 動態顯示(查看文檔時,如果文檔內容發生改變,tail的輸出會動態改變)

    -F 在-f的基礎上增加一個 -retry,不常用。

PS:沒有-n參數的話,預設輸出後十行。


本文出自 “三零妖人” 部落格,請務必保留此出處http://301ren.blog.51cto.com/8887653/1617374

linux基礎:7、基礎命令介紹(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.