linux命令之目录操作(四)

权限操作相关:chmod、chown、chgrp

chmod

这个命令跟改变文件权限的是一样的,意义也一样,我一般喜欢用数字的方式,如果是要增加或者减少某几个属性,我就用ugo+/-的形式,这样会更加简便

[jack@VM-0-14-centos testdir]$ ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxr-x  2 jack jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile

[jack@VM-0-14-centos testdir]$ chmod 700 thatFileBox/
[jack@VM-0-14-centos testdir]$ ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwx------  2 jack jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile

[jack@VM-0-14-centos testdir]$ chmod 777 thatFileBox
[jack@VM-0-14-centos testdir]$ ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxrwx  2 jack jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile
[jack@VM-0-14-centos testdir]$ chmod o-xw thatFileBox
[jack@VM-0-14-centos testdir]$ ls  -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxr--  2 jack jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile

chown

这个命令跟改变文件权限的是一样的,意义也一样,用来改变文件夹所有者的,也可以同时改变组别,我一般用来改变所有者多点,毕竟这更符合这个命令的英文表面意思。

[root@VM-0-14-centos testdir]# chown  root  thatFileBox
[root@VM-0-14-centos testdir]# ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxr--  2 root jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile

chgrp

这个命令跟改变文件权限的是一样的,意义也一样,用来改变文件夹用户组别的

[root@VM-0-14-centos testdir]# ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxr--  2 root jack 4096 Jan 27 18:16 thatFileBox
-rw-rw-r--  1 jack jack    0 Jan 27 18:22 thisIsAFile

[root@VM-0-14-centos testdir]# chgrp root thatFileBox
[root@VM-0-14-centos testdir]# ls -l
total 8
drwxr-xr-x 70 root root 4096 Jan 24 16:41 etc
drwxrwxr--  2 root root 4096 Jan 27 18:16 thatFileBox

目录搜索

find、locate

这两个命令跟用在文件的意义是类似的。这两个命令中,功能强大的是find,不过慢些,查找速度快的是locate。之所以会有这个区别是因为,find的选项多,是直接从硬盘查找,而locate是从一个内建的数据库里面查找。虽然locate的速度快,但如果数据库没有更新,那么就会出现找不到的情况,所以在使用locate查找的时候,最好先用updatedb更新下数据库,以免漏了。

find

这命令是在太强大了,可以通过名字来搜索,还可以通过权限、所有者、时间、大小、类型、uid、guid来搜索,还可以通过比较,比如大于某个时间,大于某个尺寸等等来搜索,因此,我一般就通过名字来搜索,其他功能需要时就查下man手册或者查度娘。

find path -name filename

locate

这个命令的选项很多,我比较常用-b '\name'这个选项,这个选项只搜索完全符合name的内容,否则,只要路径上出现name,这个程序都会搜索出来,比如你不带选项搜索locate,就会出现一堆你不想要的东:

[root@VM-0-14-centos ~]# locate locate
/etc/cron.daily/mlocate.cron
/etc/postfix/relocated
/etc/selinux/targeted/modules/active/modules/slocate.pp
/root/bbb/etc/cron.daily/mlocate.cron
/root/bbb/etc/postfix/relocated
/root/bbb/etc/selinux/targeted/modules/active/modules/slocate.pp
/usr/bin/fallocate
/usr/bin/locate
/usr/share/doc/mlocate-0.22.2
/usr/share/doc/mlocate-0.22.2/AUTHORS
/usr/share/doc/mlocate-0.22.2/COPYING
/usr/share/doc/mlocate-0.22.2/NEWS
/usr/share/doc/mlocate-0.22.2/README
/usr/share/locale/bg/LC_MESSAGES/mlocate.mo
/usr/share/locale/ca/LC_MESSAGES/mlocate.mo
/usr/share/locale/cs/LC_MESSAGES/mlocate.mo
/usr/share/locale/da/LC_MESSAGES/mlocate.mo
/usr/share/locale/de/LC_MESSAGES/mlocate.mo
/usr/share/locale/es/LC_MESSAGES/mlocate.mo
/usr/share/locale/fr/LC_MESSAGES/mlocate.mo
/usr/share/locale/hu/LC_MESSAGES/mlocate.mo
/usr/share/locale/it/LC_MESSAGES/mlocate.mo
/usr/share/locale/ja/LC_MESSAGES/mlocate.mo
/usr/share/locale/ms/LC_MESSAGES/mlocate.mo
/usr/share/locale/nl/LC_MESSAGES/mlocate.mo
/usr/share/locale/pl/LC_MESSAGES/mlocate.mo
/usr/share/locale/pt/LC_MESSAGES/mlocate.mo
/usr/share/locale/pt_BR/LC_MESSAGES/mlocate.mo
/usr/share/locale/sr/LC_MESSAGES/mlocate.mo
/usr/share/locale/sr@latin/LC_MESSAGES/mlocate.mo
/usr/share/locale/sv/LC_MESSAGES/mlocate.mo
/usr/share/locale/zh_CN/LC_MESSAGES/mlocate.mo
/usr/share/man/man1/fallocate.1.gz
/usr/share/man/man1/locate.1.gz
/usr/share/man/man5/mlocate.db.5.gz
/usr/share/man/man5/relocated.5.gz
/usr/share/selinux/devel/include/apps/slocate.if
/usr/share/selinux/targeted/slocate.pp.bz2
/var/lib/mlocate
/var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db.UH6Xs1
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/checksum_data
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/checksum_type
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/command_line
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/from_repo
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/from_repo_revision
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/from_repo_timestamp
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/installed_by
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/reason
/var/lib/yum/yumdb/m/6061182acf387981ef5182255e3e3b6362e48458-mlocate-0.22.2-6.el6-x86_64/releasever
[root@VM-0-14-centos ~]# 

加了-b '\locate'就可以马上找到你要的东西:

[root@VM-0-14-centos ~]# locate -b '\locate'
/usr/bin/locate
[root@VM-0-14-centos ~]# 

打包、压缩

tar

  • 压 缩:tar -jcv -f filename.tar.bz2 要被压缩的目录名称

  • 查 询:tar -jtv -f filename.tar.bz2

  • 解压缩:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录

这里的j代表用bzip2技术进行压缩或者解压

c代表打包

x达标解包

f代表后面要跟的文件名,即指定的结果的文件名

v表示要输出处理过程

另外,j有可能被z代替,表示用gzip技术来压缩

最后,可以通过-C来指定解压的目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值