Linux学习(四)

Linux学习(四)

1.输出重定向和追加

输出重定向会覆盖源文件内容 >

追加只会添加在原文件的尾部 >>

cal:可以输出当前日期

1.内容写入a.txt中

cal >a.txt cal创建日期信息

注意,如果没有a.txt,则先创建一个a.txt,再将内容放进去

2.将内容添加到指定文件的末尾

echo “内容” >> 文本 echo:字符串的输出

echo “hello world” >>a.txt 将hello world字符串输入到a.txt中

3.将文件1的内容覆盖到文件2

echo “这世界很酷” > b.txt

cat a.txt > b.txt 将a.txt文件覆盖到b.txt中

4.将列表内容写到文件中

ls -l > 文件

ls -l > /root/a.txt 将列表内容转到root 下的a.txt文件中

more a.txt 显示a.txt信息

​ more 可以文本查看信息

2.echo输出内容到控制台

1.输出当前环境路径

echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin;

2.直接输出文本

echo “hello world”

3.head用于显示文件开头部分内容,默认情况下显示文件前十行

1.看前十行内容

head 文件

2.看前五行内容

head -n 5 文件

4.tail显示文本后面内容,默认显示后十行

1.tail 文件

tail 文件

2.看后五行内容

tail -n 5 文件

注意

3.实时监控文件内容变化

tail -f 文件

5.ln 软连接 (这里是小写字母l)

相当于windows里面的快捷方式存放其他文件路径的基本语法

in -s [源文件或目录] [软连接名]

例如:

ln -s /home/lxz abc

ls -l (结果如下:)

1 root root 9 Jul 9 08:35 abc -> /home/lxz

2.删除软连接

rm -r abc

6.history (查看执行过的历史指令)

1.查看所有执行过的指令:

history

2.查看前十个指令

history 10

3.执行编号下的某个指令

[root@localhost home]# history 10
120 Ln -s /home/lxz abc
121 ln -s /home/lxz abc
122 ls -l
123 rm -r abc
124 ls -l
125 history
126 histroy 10
127 history 10
128 istory 10
129 history 10

执行:!124

[root@localhost home]# !124
ls -l
total 12
-rw-r–r--. 1 root root 0 Jun 29 02:14 hello.text
drwx------. 27 lxz lxz 4096 Jun 29 11:50 lxz
drwxr-xr-x. 2 root root 4096 Jun 29 11:50 test01
-rw-r–r--. 1 root root 145 Jul 9 02:48 test1.txt

7.date日期

1.当前日期

date

[root@localhost home]# date
Thu Jul 9 09:01:10 PDT 2020

2.显示当前时分秒

date “+%Y-%m-%d”

[root@localhost home]# date “+%Y-%m-%d”
2020-07-09
[root@localhost home]#

3.显示年月日时分秒

[root@localhost home]# date “+%Y年%m月%d日 %H:%M:%S”
2020年07月09日 09:05:10

4.设置日期

date -s 字符串时间

[root@localhost home]# date -s “2020-7-9 18:41:59”;
Fri Jul 10 11:07:05 PDT 2020

8.cal 查看日历时间

1.显示当月日历

cal

[root@localhost home]# cal
July 2020
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

2.显示某年日历

cal 2020

9.find指令(将递归的向下遍历其各个子目录,将满足条件的文件或者目录显示在终端)

find 【搜索范围】 【选项】

1.按照文件名查找指定文件

[root@localhost home]# find /home -name test1.txt (表示的是查找home目录下并且以name(名字)查找test1.txt文件)
/home/test1.txt

2.按照拥有者去查找用户名为XXX的用户

[root@localhost home]# find /opt -user root (表示查找opt下 root用户的文件 这里user代表的是拥有者)
/opt
/opt/rh

3.查找整个linux下大于20的文件

find / -size +20M (表示查找系统盘中文件大于20M的文件)其中+表示> -表示小于 不加符号表示 等于

10.locate快速定位文件路径

步骤如下:

1.首先创建一个数据库

updatedb

2.直接查找文件名字

locate 文件名

[root@localhost home]# updatedb
[root@localhost home]# locate test1.txt
/home/test1.txt

11.grep指令和管道符号 | 文件内部查找关键字

grep过滤

管道符号“|”

grep [选项] 查找内容 源文件

选项常用的有 :-n 显示匹配行及其行号

​ -i 忽略字母大小写

1.在text1.txt文件中查找找yes

[root@localhost home]# cat test1.txt | grep yes
yes
yes

2.在text1.txt文件中查找yes 并且显示行号

[root@localhost home]# cat test1.txt | grep -n yes
10:yes
16:yes

3.在text1.txt文件中查找yes 并且忽略大小写

[root@localhost home]# cat test1.txt | grep -i yes
yes
yes
Yes

4.在text1.txt文件中查找yes 忽略大小写并且编号

[root@localhost home]# cat test1.txt | grep -ni yes
10:yes
16:yes
18:Yes

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值