linux基础命令3-文件属性

文件的属性

查看文件详细属性

ls 查看文件详细信息
参数

  • -t //按照时间排序
  • -r //逆序排序
[root@yjxuniji ~]# ls -lrt
total 8
-rw-------. 1 root root 1500 Apr 13 14:02 anaconda-ks.cfg
-rw-r--r--. 1 root root  118 Apr 20 10:04 aa.txt
drwxr-xr-x. 2 root root    6 Apr 20 15:01 old
-rw-r--r--. 1 root root    0 Apr 22 16:30 12.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 11.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 10.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 23.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 22.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 21.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 24.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 25.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 26.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 27.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 28.txt
drwxr-xr-x. 7 root root  128 Apr 25 16:12 aa
[root@yjxuniji ~]# 

如何查看linux中的文件或目录

使用颜色分辨
使用后缀名 ll(查看)
使用命令来辨别

文件属性每列的含义

在这里插入图片描述

[root@yjxuniji ~]# ls -l
total 8
-rw-r--r--. 1 root root    0 Apr 22 16:30 10.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 11.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 12.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 21.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 22.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 23.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 24.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 25.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 26.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 27.txt
-rw-r--r--. 1 root root    0 Apr 22 16:30 28.txt
drwxr-xr-x. 7 root root  128 Apr 25 16:12 aa
-rw-r--r--. 1 root root  118 Apr 20 10:04 aa.txt
-rw-------. 1 root root 1500 Apr 13 14:02 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Apr 20 15:01 old
[root@yjxuniji ~]# 

1.文件类型

.txt 普通文件
.sh shell脚本
.rmp 安装包
.jpg 图片
.py python脚本

文件类型分类:
-普通文件 使用echo、vim、vi查看看
-二进制文件
-数据文件 .rmp包 压缩包

d 目录

l 软连接文件

c 字符设备文件

[root@yjxuniji ~]# ll /dev/urandom
crw-rw-rw-. 1 root root 1, 9 Apr 28 14:21 /dev/urandom

tr 替换或者删除字符的命令

参数

  • -c 取反
  • -d 删除

/dev/urandom 生成随机数,打印前5位

[root@yjxuniji ~]# tr -cd "a-z0-9A-Z" < /dev/urandom|head -c5
KXRw2[root@yjxuniji ~]# 

注解:tr命令是替换或者删除字符的命令
-head命令的作用就是取多少字符
-c指的是取多少字节,5可以自定义,这样就定义了密码的长度。

[root@yjxuniji ~]# ll /dev/null
crw-rw-rw-. 1 root root 1, 3 Apr 28 14:21 /dev/null
[root@yjxuniji ~]# 

/dev/null 系统中的黑洞 把任意输出内容都可以定向到null
在运行文件是不想看见运行过程,把过程放在null里,直接检验结果
把ping的结果放入黑洞null 使用$?来判定是否ping的通 上一条命令是否执行成功 0为成功 非0失败

[root@yjxuniji ~]# ping -c4 -W1 www.baidu.com > /dev/null
[root@yjxuniji ~]# echo $?
0

正确输出重定向

1> 正确重定向 PS: 1 只接收命令返回的正确的结果 错误的结果扔到屏幕
1>> 正确追加重定向 PS: 加1和不加1 都是只接收正确的结果
1> ======= >
1>> ====== >>

标准错误输出重定向

2> 错误重定向 # 只接收错误的结果 不接收正确的结果
2>> 错误追加重定向 # 只追加接收错误的结果 不接收正确的结果

/dev/zero 生成大文件

b 块设备 硬件设备 磁盘 光驱 U盘
s 网络套接字
p 管道文件

2.文件相关的命令

which //查看命令的全路径

[root@yjxuniji ~]# which mkdir
/usr/bin/mkdir

whereis // 查看命令的全路径和命令的帮助文件位置 了解

[root@yjxuniji ~]# whereis mkdir
mkdir: /usr/bin/mkdir /usr/share/man/man1/mkdir.1.gz
[root@yjxuniji ~]# 

file //查看文件的类型

[root@yjxuniji ~]# file ok.txt
ok.txt: ASCII text

find //按照文件的类型进行查找文件 用来查找文件 不支持查找文件中的内容

find 在哪里找 类型 特点
find ./ -type f

-type的类型
f 普通文件
d 目录
l 软链接
b 块设备
c 字符设备

1.找当前目录的所有普通文件 默认会显示隐藏的文件

[root@yjxuniji ~]# find ./ -type f
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history
./aa/1/a.txt
./aa/{name1.txt...name10.txt}
./aa/.txt

2. 查找当前目录下所有的目录文件

[root@yjxuniji ~]# find ./ -type d
./
./aa
./aa/1
./aa/1/old
./aa/2
./aa/3
./aa/4
./aa/5
./old
[root@yjxuniji ~]# 

3. 查找当前目录下的oldboy.txt

-name #按照名称查找

[root@yjxuniji ~]# find ./ -type f -name "a.txt"
./aa/1/a.txt
[root@yjxuniji ~]# 

-name #按照名称模糊查找

[root@yjxuniji ~]# find ./ -type f -name "*.txt"
./aa/1/a.txt
./aa/.txt
./aa/10.txt
./b.txt
./c.txt
./1.txt
[root@yjxuniji ~]# 

-iname 不区分大小来查找文件

[root@yjxuniji ~]# find ./ -type f -iname "*.txt"
./aa/1/a.txt
./aa/.txt
./aa/10.txt
./b.txt
./c.txt
./1.txt
[root@yjxuniji ~]# 

find 默认的是查找所有的目录及目录下面的所有文件
-maxdepth 深度等级

[root@yjxuniji ~]# find ./ -maxdepth 1 -type f

按照文件的大小查找

-size -k -M -G 文件大小

[root@yjxuniji ~]# find ./ -type f -size +1M
./all.txt

[root@yjxuniji ~]# find ./ -type f -size +500k
./services
./all.txt

[root@yjxuniji ~]# find ./ -type f -size +1G
./1G

查找/root目录下 大于1M并且小于2G的文件

[root@yjxuniji ~]# find /root/ -type f -size +1M -and  -size -3G
/root/3/all.txt
/root/1G
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值