linux學習命令總結⑤

來源:互聯網
上載者:User

標籤:cccccc   linux   style   資訊   

#stat命令:查看檔案資訊

[[email protected]_168_102_centos ~]# stat test.log  File: `test.log‘  Size: 0             Blocks: 0          IO Block: 4096   regular empty fileDevice: ca01h/51713d    Inode: 483339      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (  500/ wanghan)Access: 2014-08-11 14:27:24.000000000 +0800Modify: 2014-08-11 14:27:24.000000000 +0800Change: 2014-08-11 14:27:24.000000000 +0800

說明:

Access:訪問時間 Modify:修改時間 Change:狀態改變時間

stat *:查看目前的目錄下所有檔案資訊

[[email protected]_168_102_centos ~]# ls2014-05-16  test.log[[email protected]_168_102_centos ~]# stat *  File: `2014-05-16‘  Size: 4096          Blocks: 8          IO Block: 4096   directoryDevice: ca01h/51713d    Inode: 483336      Links: 2Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2014-05-16 15:01:40.000000000 +0800Modify: 2014-05-16 15:01:40.000000000 +0800Change: 2014-05-16 15:01:40.000000000 +0800  File: `test.log‘  Size: 0             Blocks: 0          IO Block: 4096   regular empty fileDevice: ca01h/51713d    Inode: 483339      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (  500/ wanghan)Access: 2014-08-11 14:27:24.000000000 +0800Modify: 2014-08-11 14:27:24.000000000 +0800Change: 2014-08-11 14:27:24.000000000 +0800[[email protected]_168_102_centos ~]#

#touch命令:修改檔案時間戳記,或者建立一個不存在的檔案(檔案大小、塊資訊、檔案許可權、時間戳記)

建立一個檔案:

[[email protected]_168_102_centos ~]# ls2014-05-16[[email protected]_168_102_centos ~]# touch test.log[[email protected]_168_102_centos ~]# ls2014-05-16  test.log[[email protected]_168_102_centos ~]#

touch –c:不建立空檔案

一般使用touch命令更新檔案時間戳記,如果檔案不存在,touch命令會自動建立指定檔案。如果不想因使用touch命令而建立任何空檔案,使用touch -c命令。

[[email protected]_168_102_centos ~]# clear [[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 0             Blocks: 0          IO Block: 4096   regular empty fileDevice: ca01h/51713d    Inode: 483339      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (  500/ wanghan)Access: 2014-08-11 15:00:56.000000000 +0800Modify: 2014-08-11 15:00:56.000000000 +0800Change: 2014-08-11 15:00:56.000000000 +0800[[email protected]_168_102_centos ~]# touch -c test.log [[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 0             Blocks: 0          IO Block: 4096   regular empty fileDevice: ca01h/51713d    Inode: 483339      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (  500/ wanghan)Access: 2014-08-11 15:03:34.000000000 +0800Modify: 2014-08-11 15:03:34.000000000 +0800Change: 2014-08-11 15:03:34.000000000 +0800[[email protected]_168_102_centos ~]# ls      0812080808  2014-05-16  test.log[[email protected]_168_102_centos ~]# touch -c ceshi.sh[[email protected]_168_102_centos ~]# ls0812080808  2014-05-16  test.log[[email protected]_168_102_centos ~]#

touch -t:將時間戳記修改為修改指定的日期時間

[[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-11 15:16:06.000000000 +0800Modify: 2014-08-11 15:16:06.000000000 +0800Change: 2014-08-11 15:16:06.000000000 +0800[[email protected]_168_102_centos ~]# touch -c -t 08080808 test.log          [[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-08 08:08:00.000000000 +0800Modify: 2014-08-08 08:08:00.000000000 +0800Change: 2014-08-11 15:16:30.000000000 +0800

touch –a:只修改訪問時間

[[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-11 15:26:48.000000000 +0800Modify: 2014-08-11 15:26:48.000000000 +0800Change: 2014-08-11 15:26:48.000000000 +0800[[email protected]_168_102_centos ~]# touch -c -a -t 08080808 test.log [[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-08 08:08:00.000000000 +0800Modify: 2014-08-11 15:26:48.000000000 +0800Change: 2014-08-11 15:27:44.000000000 +0800

touch -m:只修改修改時間

[[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-08 08:08:00.000000000 +0800Modify: 2014-08-11 15:26:48.000000000 +0800Change: 2014-08-11 15:27:44.000000000 +0800[[email protected]_168_102_centos ~]# touch -c -m -t 09090909 test.log [[email protected]_168_102_centos ~]# stat test.log   File: `test.log‘  Size: 8             Blocks: 8          IO Block: 4096   regular fileDevice: ca01h/51713d    Inode: 483343      Links: 1Access: (0644/-rw-r--r--)  Uid: (  500/ wanghan)   Gid: (  500/ wanghan)Access: 2014-08-08 08:08:00.000000000 +0800Modify: 2014-09-09 09:09:00.000000000 +0800Change: 2014-08-11 15:29:03.000000000 +0800

#cp命令:複製檔案或目錄

複製單個檔案

說明:如果目標是一個檔案並且不存在,建立檔案

[[email protected]_168_102_centos tmp]# ls2014-08-04-212053  a  agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  ceshi  test  test.sh  test_1.sh  wanghan  wanghan110[[email protected]_168_102_centos tmp]# cp test.sh openstack[[email protected]_168_102_centos tmp]# ls2014-08-04-212053  agent_cmd.sock  ap_1004.pid  ap_1007.pid  ap_1014.pid  openstack  test.sh    wanghana                  ap_1002.pid     ap_1005.pid  ap_1008.pid  ceshi        test       test_1.sh  wanghan110[[email protected]_168_102_centos tmp]#

說明:如果目標是一個檔案並且存在,會提示是否覆蓋

[[email protected]_168_102_centos tmp]# cat test_1.sh123[[email protected]_168_102_centos tmp]# cat wanghan/test.shMain: load logconfig, logpath /usr/local/sa/agent/log, prefix sap1002, lognum 10, logsize 10, loglevel 2[[email protected]_168_102_centos tmp]# cp test_1.sh wanghan/test.shcp: overwrite `wanghan/test.sh‘? y[[email protected]_168_102_centos tmp]# cat wanghan/test.sh123

說明:如果目標存在且是個目錄,複製檔案至目標目錄,並保持原名

[[email protected]_168_102_centos tmp]# cp test_1.sh wanghan/[[email protected]_168_102_centos tmp]# ls wanghanap_1014.pid  ceshi  test  test.sh  test_1.sh[[email protected]_168_102_centos tmp]#

複製多個檔案

說明:如果目標存在且是一個檔案,複製無法進行

[[email protected]_168_102_centos tmp]# ls wanghanap_1014.pid  ceshi  test  test.sh  test_1.sh[[email protected]_168_102_centos tmp]# cp test.sh test_1.sh wanghan/test.shcp: target `wanghan/test.sh‘ is not a directory

說明:如果目標存在且是一個目錄,複製各檔案至目標目錄中,並保持原名

[[email protected]_168_102_centos tmp]# cp test.sh test_1.sh wanghan/ceshi[[email protected]_168_102_centos tmp]# ls wanghan/ceshi123  test.sh  test_1.sh

說明:如果目標不存在,複製無法進行

[[email protected]_168_102_centos tmp]# cp test_1.sh test.sh lianxicp: target `lianxi‘ is not a directory[[email protected]_168_102_centos tmp]#

複製單獨目錄

說明:如果目標存在且是一個檔案,複製無法進行

[[email protected]_168_102_centos tmp]# cp -r test wanghan/test.shcp: cannot overwrite non-directory `wanghan/test.sh‘ with directory `test‘

說明:如果目標不存在,建立新目錄

[[email protected]_168_102_centos tmp]# ls wanghanap_1014.pid  ceshi  test  test.sh  test_1.sh[[email protected]_168_102_centos tmp]# cp -r test wanghan/openstack[[email protected]_168_102_centos tmp]# ls wanghanap_1014.pid  ceshi  openstack  test  test.sh  test_1.sh[[email protected]_168_102_centos tmp]# ls wanghan/openstack/

說明:如果目標存在且是一個目錄,複製來源目錄至目標目錄中且保持原名

[[email protected]_168_102_centos tmp]# cp -r test wanghan/openstack[[email protected]_168_102_centos tmp]# ls wanghan/openstacktest[[email protected]_168_102_centos tmp]#

cp -r:遞迴處理,將指定目錄下的檔案與子目錄一併處理

[[email protected]_168_102_centos tmp]# cp -r test wanghan/openstack[[email protected]_168_102_centos tmp]# ls wanghan/openstacktest[[email protected]_168_102_centos tmp]#

聯繫我們

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