设为首页 收藏本站
查看: 1358|回复: 0

[经验分享] linux学习命令总结⑤

[复制链接]

尚未签到

发表于 2018-5-24 08:31:50 | 显示全部楼层 |阅读模式
  #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]#


  cp –d:当源为链接文件时,复制链接文件本身而非指向的源文件

[root@VM_168_102_centos etc]# cp /etc/rc /tmp
[root@VM_168_102_centos etc]# ls
-l /tmp
total
48
-rwxr-xr-x 1 root    wanghan 2617 Aug 12 09:14 rc
[root@VM_168_102_centos etc]# rm
-rf /tmp/rc
[root@VM_168_102_centos etc]# cp
-d /etc/rc /tmp/
[root@VM_168_102_centos etc]# ls
-l /tmp
total
44
lrwxrwxrwx
1 root    wanghan    7 Aug 12 09:15 rc -> rc.d/rc
[root@VM_168_102_centos etc]#


  cp –l:对源文件建立硬链接,而非复制文件

[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  ceshi  test  test.log  wanghan
[root@VM_168_102_centos
~]# cat test.log
sdswwwd
[root@VM_168_102_centos
~]# cp -l test.log abc.log
[root@VM_168_102_centos
~]# ls -l
total
24
-rw-r--r-- 1 root    wanghan    0 Aug 11 14:50 0812080808
drwxr
-xr-x 2 root    root    4096 Aug 12 09:20 2014-05-16
-rw-r--r-- 2 wanghan wanghan    8 Aug 11 15:30 abc.log
drwxr
-xr-x 2 root    wanghan 4096 Aug 11 15:55 ceshi
drwxr
-xr-x 2 root    wanghan 4096 Aug 11 15:46 test
-rw-r--r-- 2 wanghan wanghan    8 Aug 11 15:30 test.log
drwxr
-xr-x 4 root    wanghan 4096 Aug 11 15:56 wanghan
[root@VM_168_102_centos
~]# cat abc.log
sdswwwd


  cp -s:对源文件建立符号链接,而非复制文件

[root@VM_168_102_centos ~]# cp -s test.log ceshi.log
[root@VM_168_102_centos
~]# ls -l
total
24
-rw-r--r-- 1 root    wanghan    0 Aug 11 14:50 0812080808
drwxr
-xr-x 2 root    root    4096 Aug 12 09:20 2014-05-16
-rw-r--r-- 2 wanghan wanghan    8 Aug 11 15:30 abc.log
drwxr
-xr-x 2 root    wanghan 4096 Aug 11 15:55 ceshi
lrwxrwxrwx
1 root    wanghan    8 Aug 12 09:30 ceshi.log -> test.log
drwxr
-xr-x 2 root    wanghan 4096 Aug 11 15:46 test
-rw-r--r-- 2 wanghan wanghan    8 Aug 11 15:30 test.log
drwxr
-xr-x 4 root    wanghan 4096 Aug 11 15:56 wanghan
[root@VM_168_102_centos
~]#

  #mv命令:用来移动文件或者将文件改名
  文件改名:

[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  abc.log  ceshi  ceshi.log  test  test.log  wanghan
[root@VM_168_102_centos
~]# mv ceshi ceshi_1
[root@VM_168_102_centos
~]# ls
0812080808  2014-05-16  abc.log  ceshi.log  ceshi_1  test  test.log  wanghan
[root@VM_168_102_centos
~]#

  mv -b:若覆盖文件,则先备份目标文件

[root@VM_168_102_centos ~]# mv abc.log -b wanghan/test.log
mv: overwrite `wanghan
/test.log'? y
[root@VM_168_102_centos ~]# ls wanghan
ceshi  test  test.log  test.log
~

  mv –f 若目标文件已经存在,则不会询问直接覆盖

[root@VM_168_102_centos ~]# cat test_2.sh
12345678
[root@VM_168_102_centos
~]# cat wanghan/test.log
sdswwwd
[root@VM_168_102_centos
~]# mv -f test_2.sh wanghan/test.log
[root@VM_168_102_centos
~]# ls wanghan
ceshi  test  test.log  test.log
~
[root@VM_168_102_centos
~]# cat wanghan/test.log
12345678
[root@VM_168_102_centos
~]#

  #rm命令:删除一个目录中的一个或多个文件或目录

[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  ceshi.log  ceshi_1  test  wanghan
[root@VM_168_102_centos
~]# rm ceshi.log
rm: remove symbolic link `ceshi.log
'? y
[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  ceshi_1  test  wanghan

  rm –f 不询问直接删除,强制性无提示

[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  abc.log  ceshi_1  test  wanghan
[root@VM_168_102_centos
~]# rm -f abc.log
[root@VM_168_102_centos
~]# ls
0812080808  2014-05-16  ceshi_1  test  wanghan

  rm –r 递归删除非空目录

[root@VM_168_102_centos ~]# ls wanghan
ceshi  test  test.log  test.log
~
[root@VM_168_102_centos
~]# rm -r wanghan
rm: descend into directory `wanghan
'? y
rm: remove regular file `wanghan/test.log'? y
rm: remove directory `wanghan/ceshi'? y
rm: remove directory `wanghan/test'? y
rm: remove regular file `wanghan/test.log~'? y
rm: remove directory `wanghan'? y
[root@VM_168_102_centos ~]# ls
0812080808  2014-05-16  ceshi_1  test

  rm –rf 强制性递归删除非空目录,无确认

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480477-1-1.html 上篇帖子: Linux分区的认识 下篇帖子: linux mount 的常见用法:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表