Linux 150命令之 文件和目录操作命令 chattr lsattr find

chattr添加隐藏权限

lsattr查看隐藏权限

参数 a文件内容不能删除,只能追加 >>

  1. [root@mysql tmp]# chattr +a 1.txt
  2. [root@mysql tmp]# lsattr 1.txt
  3. -----a-------e- 1.txt
  4. [root@mysql tmp]# echo aaaa >> 1.txt
  5. [root@mysql tmp]# cat 1.txt
  6. 1234
  7. aaaa
  8. [root@mysql tmp]# echo bbbb > 1.txt
  9. -bash: 1.txt: Operation not permitted

删除原来内容报错

参数 i无法删除文件

  1. [root@mysql tmp]# chattr +i 1.txt
  2. [root@mysql tmp]# lsattr 1.txt
  3. ----ia-------e- 1.txt
  4. [root@mysql tmp]# rm 1.txt
  5. rm: remove regular file `1.txt'? y
  6. rm: cannot remove `1.txt': Operation not permitted

删除文件内容报错

find寻找文件或者目录

find 目录 类型 名字

参数:

-type f 普通文件

-name 文件名字或者类型

  1. [root@mysql tmp]# find / -type f -name "1.txt"
  2. /usr/bin/1.txt
  3. /tmp/1.txt
  4. /home/koorey/1.txt

-type d 目录文件

  1. [root@mysql /]# find / -type d -name "123"
  2. /mnt/123

- mtime 根据时间找出文件

+7 7天之前

  1. [root@mysql /]# find /var/log -type f -mtime +7
  2. /var/log/rsyncd.log
  3. /var/log/samba/log.smbd.old
  4. /var/log/samba/log.pc201710111954
  5. /var/log/samba/log.10.0.0.1
  6. /var/log/samba/log.smbd
  7. /var/log/messages-20171001

- 7 七天之内

  1. [root@mysql /]# find /var/log -type f -mtime -7
  2. /var/log/lastlog
  3. /var/log/wtmp
  4. /var/log/yum.log
  5. /var/log/secure
  6. /var/log/ConsoleKit/history
  7. /var/log/dmesg
  8. /var/log/messages
  9. /var/log/mysqld.log
  10. /var/log/boot.log

-maxdepth 目录最大深度

  1. [root@mysql /]# find /var -type d -maxdepth 1
  2. find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
  3.  
  4. /var
  5. /var/cvs
  6. /var/db
  7. /var/run
  8. /var/lib
  9. /var/account
  10. /var/log
  11. /var/local

*号 任意文件

  1. [root@mysql /]# find / -type f -name "*.txt"
  2. /lib/firmware/ivtv-firmware-license-oemihvisv.txt
  3. /lib/firmware/ivtv-firmware-license-end-user.txt
  4. /var/cache/yum/x86_64/6/timedhosts.txt
  5. /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg-info/SOURCES.txt
  6. /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg-info/top_level.txt
  7. /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg-info/dependency_links.txt
  8. /usr/lib/python2.6/site-packages/paramiko-1.7.5-py2.6.egg-info/SOURCES.txt
  9. /usr/lib/python2.6/site-packages/paramiko-1.7.5-py2.6.egg-info/top_level.txt
  10. /usr/lib/python2.6/site-packages/paramiko-1.7.5-py2.6.egg-info/requires.txt
  11. /usr/lib/python2.6/site-packages/paramiko-1.7.5-py2.6.egg-info/dependency_links.txt

!取反

  1. [root@mysql mnt]# find -type f ! -name "1.txt"
  2. ./6.txt
  3. ./5.txt
  4. ./4.txt
  5. ./3.txt
  6. ./2.txt

xargs 管道 (执行命令)

  1. [root@mysql tmp]# find -type f -name "1.txt" | xargs cat
  2. 1234
  3. aaaa

cat 查看文件内容

xargs 先找到文件然后执行 查看命令

-inum + inode号 查找inode号所属的文件

inode号 文件软链接

  1. [root@mysql /]# find / -inum 267356
  2. /tmp/1.txt

-exec 跟管道命令差不多

  1. [root@mysql /]# find / -type f -inum 267356 -exec cat {} \;
  2. 1234
  3. aaaa

rm 删除命令

 

  1. [root@mysql tmp]# rm 1.txt
  2. rm: remove regular file `1.txt'? y
  3. [root@mysql tmp]# ls
  4. yum_save_tx-2017-10-12-23-03CsKn4P.yumtx yyy

-r 递归 删除 目录

  1. [root@mysql tmp]# ls
  2. ttt yum_save_tx-2017-10-12-23-03CsKn4P.yumtx yyy
  3. [root@mysql tmp]# rm -r ttt
  4. rm: remove directory `ttt'? y
  5. [root@mysql tmp]# ls
  6. yum_save_tx-2017-10-12-23-03CsKn4P.yumtx yyy

-f 不提示删除

  1. [root@mysql tmp]# rm -rf yyy
  2. [root@mysql tmp]# ls
  3. yum_save_tx-2017-10-12-23-03CsKn4P.yumtx

tree查看目录

-d 查看文件目录

  1. [root@mysql sysconfig]# tree -d
  2. .
  3. ── cbq
  4. ── console
  5. ── modules
  6. ── networking
  7. │?? ── devices
  8. │?? └── profiles
  9. │?? └── default
  10. └── network-scripts

-L 查看几层目录

  1. [root@mysql sysconfig]# tree -L 2
  2. .
  3. ── acpid
  4. ── atd
  5. ── auditd
  6. ── authconfig
  7. ── cbq
  8. ── avpkt
  9. │ └── cbq-0000.example

查看 2层目录

posted @ 2017-11-12 18:56  jks巴顿  阅读(1366)  评论(0编辑  收藏  举报