码迷,mamicode.com
首页 > 其他好文 > 详细

二周第五次课(2月2日)

时间:2018-02-02 20:10:41      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:man   bak   ati   分享   $path   mtime   绝对路径   atime   path   

2.23/2.24/2.25 find命令

2.26 文件名后缀



2.23 find命令(上)


!!回顾

#which ls

查找命令的绝对路径

#echo $PATH

which所找的东西都会在环境变量$PATH里寻找。


#whereis ls 查找文件在哪儿

ls:/usr/bin/ls /usr/share/man/man1/ls.1.gz


#yum install -y mlocate 安装#locate命令


#locate 模糊搜索

用#locate之前先手动#updatedb(手动更新数据库,数据库每天会在4:00AM自动更新)

用法 #locate 123 

此用户会把123相关的文件和目录都会搜索出来。


ctrl d 退出终端,exit;logout

ctrl c 退出当前窗口

ctrl u 光标前的都删掉

ctrl n 把光标摞到最后

ctrl a 前把光标摞到最前


#find 用法

#find /etc/ -name "sshd_config"  精确搜索

#find /etc/ -name "sshd*" 迷糊搜索

#find /etc/ type d -name "sshd*" 目录迷糊搜索

#find /etc/ type f -name "sshd*"文件迷糊搜索


d目录 

f(-)二进制、普通文件 

s stick

c 字符串 鼠标、键盘

b 块状存储设备。硬盘,u盘

l 链接文件 软硬链接。



2.24 find命令(中)


#find / -type -name -(mtime,ctime,atime)


mtime 表示写入时间大于或小于n天的文件,该参数用得最多。

atime 表示访问或执行大于或小于n天的文件。

ctime 表示写入、更改inode属性(如更改所有者、权限或者链接)的时间大于或小于n天的文件。


#stat 2.txt

技术分享图片

可以看到最近访问时间(atime)、最近更改时间(mtime)、最近改动时间(ctime)


#chmod 700 2.txt

#stat 2

可以发现2.txt的改动时间被改了

技术分享图片

#echo"12121212" >> 2.txt

#stat 2.txt

可以发现2.txt的更改时间被改了。


知识点*

如果更改了文件的内容,ctime一定会变,因为ctime记录了文件的大小(标红)、时间、内容、权限:所有者、所属组。此时,增加了文字内容,那么大小就会变了,所以ctime也跟着变。


用法

#find / -type f -mtime +1或者-1

解析:mtime 后面接的是时间,+增-减,时间默认单位是天。

例如

查找在/etc/在一天以内发生更改的文件,

#find /etc/ -type f -mtime -1

那么,一天之前(+1)的用法是

#find /etc/ -type f -mtime +1


并且(增加条件)的用法

#find /etc/ -type f -ctime -1 -name "*.conf" 


或者的用法(-o)

#find /etc/ -type f -o -mtime -1 -o -name "*.conf" 


关于#find常用参数:-type -name -mtime -o



2.25 find命令(下)


硬链接文件如何找?

test0,

先把硬链接文件放到/tmp下 并改名1.txt.bak

# ln 1_heard.txt /tmp/1.txt.bak

再查看 1_heard.txt的 inode号

#ls -i 1_heard.txt

......395 1_heard.txt

#find / -inum  ....395

/root/1_heard.txt

/tmp/1.txt.bak


在/root下find一个小时内修改过的文件。-mmin后面带分钟,-60 代表60分钟。

#find /root/ -type f -mmin -60


在/root下find一个小时内修改过的文件(-mmin 60),并且ls -l 显示其中一个。(-exec 连接语段,{}表示其中一个,如果两个是{}{},\;连着用。exec一般是-exec 命令{}\;)。

#find /root/ -type f -mmin -120 -exec ls -l {} \;


test

找出mtime 150的文件,并修改他们的后缀为.bak

#find /root/ -type f -mmin -150

#find /root/ -type f -mmin -150 -exec mv {}{}.bak \;


test 2

找出大于10k的文件

#find /root/ -type f -size +10k -exec ls -lh {}{} \;



2.26 文件名后缀


Linux的命令和文件,是区分大小写的。

Linux的文件是有后缀名的,但并不是不同后缀就代表不同文件,加与不加都是无所谓的。

但是为了便于区分,我们习惯在定义文件名时加一个后缀名。这样当用户看到这个文件名时,就会很快知道它到底是一个什么文件,例如1.sh、2.tar.gz、my.cnf、test.zip等。

1.sh 脚本文件

2.tar.gz代表压缩包

my.cnf 配置文件

test.zip 压缩文件。


二周第五次课(2月2日)

标签:man   bak   ati   分享   $path   mtime   绝对路径   atime   path   

原文地址:http://blog.51cto.com/13578154/2068263

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