linux操作系统命令2

cat文件的拼接
cat 拼接两个命令
在这里插入图片描述
cat -n 拼接两个命令 带行号
在这里插入图片描述
cat -b 拼接两个命令 不带空行的行号
在这里插入图片描述
cat -s 将多个空行显示为一个空行
在这里插入图片描述

cat -v识别特殊字符 ,在写脚本时候用 cat -v 查看是否出错 ,windows界面的文件在linux上打开会有特殊字符
在这里插入图片描述在这里插入图片描述

cat -E每行结束后 会加一个$符号 识别看不到的内容
在这里插入图片描述
cat -T识别tab符号
在这里插入图片描述

cat -e File #特殊符号$
cat -t file #特殊符号,识别TAB

**
2.diff**
diff file file1(向右尖括号表示右边的尖括号)
在这里插入图片描述
diff -y(表示两个一起对比)
在这里插入图片描述

vimdiff file1 file3 —vim(保存退出后 继续自动编辑第二个文件)
在这里插入图片描述
diff -W (调整对比的宽度)

3gerp
cp /etc/passwd ./(将该文件拷贝到当前目录)
cat passwd
grep ‘root’ passwd(在passwd中寻找带有root的)
在这里插入图片描述
grep -n 带行号打印
在这里插入图片描述
grep -w(以单词匹配)
在这里插入图片描述

grep -i(不区分大小写)
在这里插入图片描述

grep -o(只打印root)
在这里插入图片描述

[root@admin test]# grep -v ‘ROOT’ passwd #取反
在这里插入图片描述

[root@admin test]# grep -nB 2 ‘ROOT’ passwd #之前n行
[root@admin test]# grep -nA 2 ‘ROOT’ passwd #之后n行
[root@admin test]# grep -nC 2 ‘ROOT’ passwd #上下n行

4.touch 改变指定文件的访问时间和修改时间的命令
21)touch :默认文件存在,修改文件访问属性,文件不存在,创建文件
在这里插入图片描述

touch -a file2 #修改文件access时间
在这里插入图片描述
在这里插入图片描述

touch -c file4 #不创建文件
在这里插入图片描述

touch -d 19710101 file3 #指定时间创建文件
在这里插入图片描述

touch -r file8 file9 #按指定文件的时间创建文件
在这里插入图片描述

touch -t 197107010101 file9 #将时间修改为指定时间

access 表示最后一次访问(仅仅是访问,没有改动)文件的时间 —cat —vim
modify 表示最后一次修改文件的时间 —vim “123”
change 表示最后一次对文件属性改变的时间,包括权限,大小,属性等等 —vim —chmod +x file
[root@admin ~]# vim file1
[root@admin ~]# echo “” > file2在这里插入图片描述
du -h 查看文件大小
在这里插入图片描述

  1. 文件存储
    linux的文件系统:
    inode:文件的属性信息
    block:文件的内容
    superblock:inode和block的数量,使用量等
    在这里插入图片描述
    6.链接文件

硬链接: 链接到源文件的inode上;
软连接: 创建了一个文件,拥有自己的inode,对用的block中存放云文件的路径。

ln sourceFile destfile ==> 不能连接目录
删除源文件或者链接文件,互不影响
在这里插入图片描述
在这里插入图片描述

ln -s sourceFile destfile ==> 链接目录
删除链接文件,源文件不影响,删除源文件,链接文件就失效(存在)。
在这里插入图片描述

如果连接的是目录:如果引入了对目录的硬连接就有可能在目录中引入循环,那么在目录遍历的时候系统就会陷入无限循环当中。也许您会说,符号连接不也可以引入循环吗,那么为什么不限制目录的符号连接呢?原因就在于在linux系统中,每个文件(目录也是文件)都对应着一个inode结构,其中inode数据结构中包含了文件类型(目录,普通文件,符号连接文件等等)的信息,也就是说操作系统在遍历目录时可以判断出符号连接,既然可以判断出符号连接当然就可以采取一些措施来防范进入过大的循环了,系统在连续遇到8个符号连接后就停止遍历,这就是为什么对目录符号连接不会进入死循环的原因了。但是对于硬连接,由于操作系统中采用的数据结构和算法限制,目前是不能防范这种死循环的。
rm -rf dir/ (错误)
rm -rf dir
Linux的目录是使用 / 之类的目录形式存放,rm 是Linux的删除命令,后面带的“-rf”,"-r"指的是 递归删除(意思是删除当前目录下所有文件和文件夹),而“-f”指的是 强制删除 。后方的/*指的是 根目录“/”下的所有文件。
****7linux操作系统不会以文件的后缀来识别文件类型
[root@admin ~]# file paramiko-2.7 #文件类型
[root@admin ~]# file /usr/bin/ls #识别编码格式 ----> x86_64
[root@admin opt]# file -Li file1 (i:查看文件的来源 l:查看文件的链接类型)
file -b 不带文件名
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
**7cp
**

[root@admin ~]# cp -r anliu anliu.abk1 #递归复制目录
在这里插入图片描述

[root@admin opt]# cp -d file1 file3 #复制链接
在这里插入图片描述
在这里插入图片描述

[root@admin tmp]# cp -p file file.bak3 #不修改源文件的文件属性(时间戳,文件属主属组(root))
在这里插入图片描述

[root@admin tmp]# cp -P /opt/file1 file6 #复制完整链接(普通用户保存不了其他用户的目录,cp谁发起的 ,保存权限就是谁的)
在这里插入图片描述
**8find
[root@admin ~]# find /etc/ -name passwd
[root@admin ~]# find /etc -name passwd -print(表示输出行与行的间隔数 print0无间隔)
/etc/passwd
/etc/pam.d/passwd
在这里插入图片描述

[root@admin ~]# find . -name file1 -exec rm -rf {} ;
在这里插入图片描述

[root@admin ~]# find . -name file2 -exec du -h {} ;(查看大小)
在这里插入图片描述

[root@admin ~]# find . -name file2 -exec ls -l {} ;

在这里插入图片描述

[root@admin ~]# find . -name file2 -ok rm -rf {} ;(提示是否确定)
在这里插入图片描述

chmod 777 File
[root@admin ~]# find . -perm 777
在这里插入图片描述
在这里插入图片描述
[root@admin tmp]# find . -user test01(文件属主查找)

[root@admin tmp]# find . -group test01(文件属组查找)
[root@admin ~]# find . -type l (按照文件类型查找)(查看链接文件)
[root@admin ~]# find . -type d(查找目录)
find / -size +50k -a -size -60k -exec ls -l {} ;(限制文件大小)
在这里插入图片描述
8.rm
删除原理: 本质删除的是文件名
[root@admin ~]# \rm -i file1.abk
[root@admin ~]# \rm -ir anliu.abk
[root@admin ~]# \rm -r anliu.abk
[root@admin ~]# rm -rf anliu.abk(r;递归删除 f:强制删除)
[root@admin ~]# rm -rvf 123/(提示已删除)
在这里插入图片描述

当系统根目录被打满时,该如何定位?
df -h 查看文件系统情况
在这里插入图片描述

(1)查看系统上的大文件
[root@admin mail]# find / -size +10M -exec ls -lh {} ;
(2)分析大文件是否有异常文件
日志文件,/var/spool/mail/username
(3)若能正常使用进程管理工具 ---->查看异常进程
若不能正常使用进程管理工具 ----> echo “” > 异常文件 -->查看异常进程
(4)分析问题原因
rsyslog : -----> rsyslogd —>""

[root@admin log]# vim /etc/rsyslog.conf

Provides UDP syslog reception

$ModLoad imudp
$UDPServerRun 514

Provides TCP syslog reception

$ModLoad imtcp
$InputTCPServerRun 514

. @@192.168.1.25:514 # tcp 协议
local7.info @192.168.1.25:514 # udp 协议,只发送用户的 info 级别日

[root@admin log]# systemctl restart rsyslog
在这里插入图片描述

在这里插入图片描述

9 split(将文件分割成多个)

[root@nebulalinux03 tmp]# dd if=/dev/zero of=date.file bs=100K count=1
在这里插入图片描述
-b:值为每一输出档案的大小,单位为 byte。

在这里插入图片描述
ll -h
在这里插入图片描述
[root@admin data]# split -b 1024k data.file -d -a 5
在这里插入图片描述
在这里插入图片描述
10.mv(mv是move的缩写,可移动文件或者将文件改名)
mv 若目录存在将文件移到到目录,若目录不存在,则将源文件改名
在这里插入图片描述
\mv -b file4 file3 #备份(file~是备份的内容)
在这里插入图片描述

\mv -i file4 file3 #交互
在这里插入图片描述
\mv -f file4 file3 #强制
在这里插入图片描述
mv file10 data/
在这里插入图片描述
在这里插入图片描述

11cut
cut -c (按字符分割)

[root@localhost datq]# cat file1 |cut -c 1,2
th
he
呵呵

cut -b(按字节分割)

[root@localhost datq]# cat file1 |cut -b 1,2
th
he

cat file |cut -b 1 -n #不以字节分割,多字节会输出

[root@localhost datq]# cat file1 |cut -b 1 -n
t
h
呵

cat passwd |cut -d : -f 1 自定义分隔符,默认为制表符

 [root@localhost datq]#  cat passwd |cut -d : -f 1,2 /etc/passwd
cat: passwd: 没有那个文件或目录
root:x
bin:x
daemon:x
adm:x
lp:x
sync:x
shutdown:x
halt:x
mail:x
operator:x
games:x
ftp:x
nobody:x

12.sort(将文本内容加以排序)

[root@admin ~]# cat file2 |sort

[root@localhost datq]# vim file2
[root@localhost datq]# cat file2
4.where are you
3.who are you
1.what is it
2.how are you
[root@localhost datq]# cat file2 |sort
1.what is it
2.how are you
3.who are you
4.where are you

[root@admin ~]# cat file2 |sort -t “;” -k3(-k Num :以第Num列排序)

[root@localhost datq]#  cat file2  |sort  -k3
1.what is it 222
4.where are you 666
2.how are you 669
3.who are you 888
[root@localhost datq]#  cat file2  |sort -t ";"  -k4
1.what is it ;222
2.how are you ;669
3.who are you ;888
4.where are you ;666

LANG=“en_US.UTF-8”
[root@admin test]# ll |sort -k6 -M #月份(系统识别)
在这里插入图片描述

[root@admin ~]# cat file2 |sort -k3 -n #数字排序 —(字符) 1,2,3 … 11 ,12,
[root@admin ~]# cat file2 |sort -k3 -nr #到序

[root@localhost datq]# cat file2  |sort -k1 -n
1.what is it ;222
2.how are you ;669
3.who are you ;888
4.where are you ;666
[root@localhost datq]# cat file2  |sort -k1 -nr
4.where are you ;666
3.who are you ;888
2.how are you ;669
1.what is it ;222

[root@admin ~]# cat file2 |sort -k5 -nu #去重(-u 意味着是唯一的(unique),输出的结果是去完重了的)

4.where are you ;666
3.who are you ;888
1.what is it ;222
2.how are you ;669
~                                                                                             
~                                                                                             
~                       
[root@localhost datq]# cat file2  |sort -k5 -nu
4.where are you ;666

[root@admin ~]# cat file2 |sort -k5 -nuo num #输出到文件 num中

13uniq命令 只去除相邻的行的重复,所以一般和sort连用**

sort [file] | uniq 等价于 sort -u [file]

[root@localhost /]# cat file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
[root@localhost /]# sort file1 | uniq
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you
[root@localhost /]# sort -u file1
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you

-c 在输出行前面加上每行在文件中出现的次数

[root@localhost /]# sort file1 |uniq -c
      1 1.this is a linux
      1 2.this is a java
      1 4.this is a linux
      1 5.this is a java
      2 6.how are you
      

-d 只显示去重后的行

[root@localhost /]# sort file1 |uniq -d
6.how are you

-f 去重前比较时跳过前N列

[root@localhost /]# sort file1 |uniq -f1
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you
[root@localhost /]# sort file1 |uniq -f2
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you

-i 去重前比较时忽略大小写

[root@localhost /]# cat file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
[root@localhost /]# sort file1 |uniq -i
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you

-s 去重前比较时跳过前N个字符

[root@localhost /]# sort file1 | uniq -s5
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
5.this is a javA
6.how are you

sort -u

[root@localhost /]# sort file1 |uniq -u
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
5.this is a javA

-w Num:重前比较前Num個字符之后的不做比較

[root@localhost /]# sort file1 |uniq -w5
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
6.how are you

-D显示所有重复的行

[root@localhost /]# sort -u file1
1.this is a linux
2.this is a java
4.this is a linux
5.this is a java
5.this is a javA
6.how are you
[root@localhost /]# sort file1 |uniq -D
5.this is a java
5.this is a java
6.how are you
6.how are you

14.wc (Word Count)命令的功能为统计指定文件中的字节数、字数、行数,并将统计结果显示输出
此UTF-8编码:一个英文字母占1个字节,1个控制符占1个字节,1个数字占1个字节,1个汉字占3个字节(此处的空格符,制表符,换行符各算一个字节)
`[root@localhost /]# wc -c file1

132 file1`
-l 统计行数

[root@localhost /]# wc -l file1
8 file1

-m 统计字符数。这个标志不能与 -c 标志一起使用

[root@localhost /]# wc -m file1
132 file1

-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串

-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串

-L 打印最长行的长度

[root@localhost /]# wc -l file1
8 file1

14、head 命令(head 命令可以显示指定文件前若干行的文件内容)
-n K:这里的 K 表示行数,该选项用来显示文件前 K 行的内容,等价于 -K
-n -K:使用 “-K” 作为参数,则表示除了文件最后 K 行外,显示剩余的全部内容。

[root@localhost /]# head -n 1 file1
1.this is a linux
[root@localhost /]# head -n 2 file1
1.this is a linux
2.this is a java
[root@localhost /]# head -n 3 file1
1.this is a linux
2.this is a java
4.this is a linux
[root@localhost /]# head -n -1 file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
[root@localhost /]# head -n -2 file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java

-c K:这里的 K 表示字节数,该选项用来显示文件前 K 个字节的内容
-c -K:使用 "-K"作为参数,则表示除了文件最后 K 字节的内容,显示剩余全部内容

2.[root@localhost /]# head -c 22 file1
1.this is a linux
2.th[root@localhost /]# 
[root@localhost /]# head -c -2 file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a jav[root@localhost /]#

-v显示文件名;注意,如不设置显示的具体行数,则默认显示 10 行的文本数据。

[root@localhost /]# head -v file1
==> file1 <==
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java

15.tail **** 命令和 head 命令正好相反,它用来查看文件末尾的数据****
-n K这里的 K 指的是行数,该选项表示输出最后 K 行,等价于-K

[root@localhost /]# tail -n 3 file1
5.this is a java
5.this is a javA
5.this is a java
[root@localhost /]# head -n 3 file1
1.this is a linux
2.this is a java
4.this is a linux

-n +K:表示从文件的第 K 行开始输出

[root@localhost /]# tail -n +1 file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java
[root@localhost /]# tail -n +4 file1
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java
[root@localhost /]# vim file1
[root@localhost /]# cat file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java

-c K这里的 K 指的是字节数,该选项表示输出文件最后 K 个字节的内容

[root@localhost /]# tail -c 5 file1
java
[root@localhost /]# tail -c 6 file1
 java
[root@localhost /]# tail -c 7 file1
a java

-c +K:表示从文件第 K 个字节开始输出

[root@localhost /]# tail -c +1 file1
1.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java
[root@localhost /]# tail -c +2 file1
.this is a linux
2.this is a java
4.this is a linux
6.how are you
6.how are you
5.this is a java
5.this is a javA
5.this is a java

-f 输出文件变化后新增加的数据
监听文件的新増内容。tail 命令可以使用 “-f” 选项来实时监听文件的新増内容

[root@localhost /]# tail -f  /etc/profile
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "


^C
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值