50个最常用的Unix/Linux命令

这些命令基本上都是需要掌握的:

tar

grep

find

ssh

sed

awk

vim

diff

sort

export

args

ls

pwd

cd

gzip

bzip2

unzip

shutdown

ftp

crontab

service

ps

free

top

df

kill

rm

cp

mv

cat

mount

chmod

chown

passwd

mkdir

ifconfig

uname

whereis

whatis

locate

man

tail

less

su

mysql

yum

rpm

ping

date

wget

1. tar

创建一个新的tar文件

$ tar cvf archive_name.tar dirname/

解压tar文件

$ tar xvf archive_name.tar

查看tar文件

$ tar tvf archive_name.tar

更多示例:The Ultimate Tar Command Tutorial with 10 Practical Examples

2. grep

在文件中查找字符串(不区分大小写)

$ grep -i "the" demo_file

输出成功匹配的行,以及该行之后的三行

$ grep -A 3 -i "example" demo_text

在一个文件夹中递归查询包含指定字符串的文件

$ grep -r "ramesh" *

更多示例:Get a Grip on the Grep! – 15 Practical Grep Command Examples

3. find

查找指定文件名的文件(不区分大小写)

$ find -iname "MyProgram.c"

对找到的文件执行某个命令

$ find -iname "MyProgram.c" -exec md5sum {} \;

查找home目录下的所有空文件

$ find ~ -empty

更多示例:Mommy, I found it! — 15 Practical Linux Find Command Examples

4. ssh

登录到远程主机

$ ssh -l jsmith remotehost.example.com

调试ssh客户端

$ ssh -v -l jsmith remotehost.example.com

显示ssh客户端版本

$ ssh -V

更多示例:5 Basic Linux SSH Client Commands

5. sed

当你将Dos系统中的文件复制到Unix/Linux后,这个文件每行都会以\r\n结尾,sed可以轻易将其转换为Unix格式的文件,使用\n结尾的文件

$ sed 's/.$//' filename

反转文件内容并输出

$ sed -n '1!G; h; p' filename

为非空行添加行号

$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

更多示例:Advanced Sed Substitution Examples

6. awk

删除重复行

$ awk '!($0 in array) { array[$0]; print}' temp

打印/etc/passwd中所有包含同样的uid和gid的行

$ awk -F ':' '$3=$4' /etc/passwd

打印文件中的指定部分的字段

$ awk '{print $2,$5;}' employee.txt

更多示例:8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

7. vim

打开文件并跳到第10行

$ vim +10 filename.txt

打开文件跳到第一个匹配的行

$ vim +/search-term filename.txt

以只读模式打开文件

$ vim -R /etc/passwd

更多示例:How To Record and Play in Vim Editor

8. diff

比较的时候忽略空白符

$ diff -w name_list.txt name_list_new.txt

9. sort

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值