码迷,mamicode.com
首页 > 系统相关 > 详细

linux学习命令总结⑤

时间:2014-08-11 18:15:14      阅读:527      评论:0      收藏:0      [点我收藏+]

标签:cccccc   linux   style   信息   

#stat命令:查看文件信息

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

说明:

Access:访问时间 Modify:修改时间 Change:状态改变时间

stat *:查看当前目录下所有文件信息

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

#touch命令:修改文件时间戳,或者新建一个不存在的文件(文件大小、块信息、文件权限、时间戳)

新建一个文件:

[root@VM_168_102_centos ~]# ls
2014-05-16
[root@VM_168_102_centos ~]# touch test.log
[root@VM_168_102_centos ~]# ls
2014-05-16  test.log
[root@VM_168_102_centos ~]#

touch –c:不创建空文件

一般使用touch命令更新文件时间戳,如果文件不存在,touch命令会自动创建指定文件。如果不想因使用touch命令而创建任何空文件,使用touch -c命令。

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

touch -t:将时间戳修改为修改指定的日期时间

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

touch –a:只修改访问时间

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

touch -m:只修改修改时间

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

#cp命令:复制文件或目录

复制单个文件

说明:如果目标是一个文件并且不存在,创建文件

[root@VM_168_102_centos tmp]# ls
2014-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
[root@VM_168_102_centos tmp]# cp test.sh openstack
[root@VM_168_102_centos tmp]# ls
2014-08-04-212053  agent_cmd.sock  ap_1004.pid  ap_1007.pid  ap_1014.pid  openstack  test.sh    wanghan
a                  ap_1002.pid     ap_1005.pid  ap_1008.pid  ceshi        test       test_1.sh  wanghan110
[root@VM_168_102_centos tmp]#

说明:如果目标是一个文件并且存在,会提示是否覆盖

[root@VM_168_102_centos tmp]# cat test_1.sh
123
[root@VM_168_102_centos tmp]# cat wanghan/test.sh
Main: load logconfig, logpath /usr/local/sa/agent/log, prefix sap1002, lognum 10, logsize 10, loglevel 2
[root@VM_168_102_centos tmp]# cp test_1.sh wanghan/test.sh
cp: overwrite `wanghan/test.sh‘? y
[root@VM_168_102_centos tmp]# cat wanghan/test.sh
123

说明:如果目标存在且是个目录,复制文件至目标目录,并保持原名

[root@VM_168_102_centos tmp]# cp test_1.sh wanghan/
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid  ceshi  test  test.sh  test_1.sh
[root@VM_168_102_centos tmp]#

复制多个文件

说明:如果目标存在且是一个文件,复制无法进行

[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid  ceshi  test  test.sh  test_1.sh
[root@VM_168_102_centos tmp]# cp test.sh test_1.sh wanghan/test.sh
cp: target `wanghan/test.sh‘ is not a directory

说明:如果目标存在且是一个目录,复制各文件至目标目录中,并保持原名

[root@VM_168_102_centos tmp]# cp test.sh test_1.sh wanghan/ceshi
[root@VM_168_102_centos tmp]# ls wanghan/ceshi
123  test.sh  test_1.sh

说明:如果目标不存在,复制无法进行

[root@VM_168_102_centos tmp]# cp test_1.sh test.sh lianxi
cp: target `lianxi‘ is not a directory
[root@VM_168_102_centos tmp]#

复制单独目录

说明:如果目标存在且是一个文件,复制无法进行

[root@VM_168_102_centos tmp]# cp -r test wanghan/test.sh
cp: cannot overwrite non-directory `wanghan/test.sh‘ with directory `test‘

说明:如果目标不存在,创建新目录

[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid  ceshi  test  test.sh  test_1.sh
[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid  ceshi  openstack  test  test.sh  test_1.sh
[root@VM_168_102_centos tmp]# ls wanghan/openstack/

说明:如果目标存在且是一个目录,复制源目录至目标目录中且保持原名

[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan/openstack
test
[root@VM_168_102_centos tmp]#

cp -r:递归处理,将指定目录下的文件与子目录一并处理

[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan/openstack
test
[root@VM_168_102_centos tmp]#

linux学习命令总结⑤,布布扣,bubuko.com

linux学习命令总结⑤

标签:cccccc   linux   style   信息   

原文地址:http://putongren.blog.51cto.com/9086263/1538595

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!