linux 101 hacks 4 (Essential Linux Commands)

本文介绍了Linux中常用的命令,如grep、find等,用于搜索、排序、文件处理等任务,并详细解释了每个命令的参数选项及其应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1:grep command
# grep search_word filename
-v 不显示符合的行
-c 出现的次数
-r 在文件夹里面找
-i 忽略大小写
-l 显示符合条件的 文件名

2:find command
find path -name filename 以文件名查找
-type
-size (+100m:大于100m的)
-mtime (+60) 60天内未改动的 -2 2天内改动过的
-exec 找出来以后执行之后的命令
# find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
# find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;

3:抑制标准输出
> /dev/null
抑制 错误 输出
2 >/dev/null

4:join 连接两个文件
5:改变文件内容的大小写 tr a-z A-Z < filename (小写到达写)

6:Xargs Command
Xargs 把前一个命令的输出 当作后一个的输入
# find /etc -name "*.conf" | xargs ls –l 列出在。。。下 的符合。。。的文件
cat url-list.txt | xargs wget –c 一个文件里有你的url列表,你可以用这个一次下载下来
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz 找出所有jpg文件打包


7:Sort Command
以文本形式排序
sort filename
-r 倒序
$ sort -t: -k 2 names.txt -t(紧跟分隔符) -k(第几个域)
-u 排除重复项

8:Uniq Command
经常与sort一起排除重复的
sort namesd.txt | uniq
uniq -c 显示出现的次数
uniq -d 只显示重复了的

9:Cut Command
只显示文件的某一列
$ cut -d: -f 1,3 names.txt 以 : 分隔的文件 显示第一个 第三个 field
$ cut -c 1-8 names.txt 显示文件的每一行的前8个字符
cut -d: -f1 /etc/passwd Displays the unix login names for all the users in the system.

10:Stat Command
显示某个文件或文件夹的属性
stat /etc/my.cnf
-f 某个文件系统的属性

11:Diff Command
diff [options] file1 file2

12:ac Command
ac 统计用户的连接的统计时间
-p 每个人的总时间
-d username 某个用户的时间
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值