linux频繁使用命令3

1date命令

date:

可以用来显示或设定系统的日期与时间,在显示方面,使用者可以设定欲显示的格式,格式设定为一个加号后接数个标记,其中可用的标记列表如下 :

时间方面 :

% : 印出

% %n : 下一行

%t : 跳格

%H : 小时(00…23)

%I : 小时(01…12)

%k : 小时(0…23)

%l : 小时(1…12)

%M : 分钟(00…59)

%p : 显示本地 AM 或 PM

%r : 直接显示时间 (12 小时制,格式为 hh:mm:ss [AP]M)

%s : 从 1970 年 1 月 1 日 00:00:00 UTC 到目前为止的秒数 %S : 秒(00…61)

%T : 直接显示时间 (24 小时制)

%X : 相当于 %H:%M:%S

%Z : 显示时区

日期方面 :

%a : 星期几 (Sun…Sat)

%A : 星期几 (Sunday…Saturday)

%b : 月份 (Jan…Dec)

%B : 月份 (January…December)

%c : 直接显示日期与时间

%d : 日 (01…31)

%D : 直接显示日期 (mm/dd/yy)

%h : 同 %b

%j : 一年中的第几天 (001…366)

%m : 月份 (01…12)

%U : 一年中的第几周 (00…53) (以 Sunday 为一周的第一天的情形)

%w : 一周中的第几天 (0…6)

%W : 一年中的第几周 (00…53) (以 Monday 为一周的第一天的情形)

%x : 直接显示日期 (mm/dd/yy)

%y : 年份的最后两位数字 (00.99)

%Y : 完整年份 (0000…9999)

案例:

[root@runtime ~]# date -S ‘1988-10-1 8:00:00’
Sat Oct1 08:00:00 CST 1988
[root@runtime ~]# date
Sat Oct1 08:00:01 CST 1988
[root@runtime ~]# date -S’ 2020-10-6 14:21 :00’
Tue Oct6 14:21 :00 CST 2020
[ root@runtime ~] # date
Tue Oct6 14:21:02 CST 2020
[ root@runtime ~] # date’+%Y’
2020
[root@runtime ~]# date’ +%m ’
10
[root@runtime ~]# date ’ +%d ’
06
[root@runtime ~]# date
‘+%H’
14
[root@runtime ~]# date
+%M ’
21
[root@runtime ~]# date
+%S
42
[root@runtime ~]# date + %Y%m%d
20201006


2 which命令

which命令:

用来查找系统***PATH目录下***的可执行文件。说白了就是查找那些我们已经安装好的可以直接执行的命令,比如
swq123459@swq123459PC:~$ which ls
/bin/ls

案例:

[root@runtime ~] # which b
/usr/bin/which:_ no bc in (/usr/local/sbin: /usr/1ocal/bin: /usr/sbin:/usr/bin:/root/bin)

[ root@runtime ~] # mount /dev/cdrom / mnt
mount: /mnt: WARNING: device wri te-protected, mounted read-only .
[root@runtime ~]# rpm -ivh /mnt/BaseOS/ Packages/bc-1.07.1-5.el8. x86_ _64. rpm

warni ng: /mnt/ Base0S/Packages/bc-1.07.1-5.e18.x86_ _64. rpm: Header V3 RSA/ SHA256 Si gnature ,key ID fd431d51: NOKEY

Verifying…

#################################

[ 100%]

Preparing…:

Updating / insta1ling…

#################################

[ 100%]

1:bc-1.07.1-5.e 18

################################# [100%]

[ root@runtime ~]# 5/2

bash: 5/2: No such file or_ di rectory

[root@runtime ~]# echo "scale=2;5/2"Ibc

2.50

[root@runtime ~]# echo “scale=4;5/2” I bc

2.5000

[root@runtime ~]#


3grep命令

grep:

一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。

格式及主要参数:

grep [options]
主要参数: grep --help可查看
-c:只输出匹配行的计数。
-i:不区分大小写。
-h:查询多文件时不显示文件名。
-l:查询多文件时只输出包含匹配字符的文件名。
-n:显示匹配行及 行号。
-s:不显示不存在或无匹配文本的错误信息。
-v:显示不包含匹配文本的所有行。
–color=auto :可以将找到的关键词部分加上颜色的显示。
pattern正则表达式主要参数:
\: 忽略正则表达式中特殊字符的原有含义。
^:匹配正则表达式的开始行。
$: 匹配正则表达式的结束行。
<:从匹配正则表达 式的行开始。
>:到匹配正则表达式的行结束。
[ ]:单个字符,如[A]即A符合要求 。
[ - ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。
.:所有的单个字符。
*:所有字符,长度可以为0。
案例:

[root@runtime ~] # grep ‘^graphical ’ anaconda-ks.cfg
graphical
[root@runtime ~]# grep_ -B 1’ ^graphical ‘anaconda-ks.cfg
#.Use .graphical install
graphi cal
[root@runtime ~]# grep -A 1’ ^graphical ’ anaconda-ks . cfg
graphi cal
#.UseCDROM instal lation media
[root@runtime ~]#grep_ -C 1 ’ ^graphical’anaconda-ks.cfg
#.Use graphical install
graphi ca
#.UseCDROM installation media
[root@runtime ~] #

[root@runtime ~]# lslgrep ‘^…$’

abc
ABC
def

[root@runtime ~]#ls|grep ‘^…$’

hehe xixi

[root@runtime ~]#lslgrep ‘^… l . . . . l^.... l....

[root@runtime ~]# ls lgrep -E ‘^… ∣ . . . . |^.... ....
abc
ABC
def
hehe
xixi

[root@runtime ~]#lslgrep ‘^… ∥ . . . . \|^.... ....
abc


4find命令

find命令:

find的主要用来查找文件,查找文件的用法我们比较熟悉,也可用它来查找文件夹,用法跟查找文件类似,只要在最后面指明查找的文件类型 -type d,如果不指定type类型,会将包含查找内容的文件和文件夹一起输出。

在/admin目录下查找以.txt结尾的文件名:

find /admin -iname “*.txt”

当前目录及子目录下查找所有以.txt和.pdf结尾的文件:

find . -name “.txt" -o -name ".pdf”

匹配文件路径或者文件:

find /admin/ -path “user

搜索最近五天内被访问过的所有文件:

find . -type f -atime -5

搜索五天前被访问过的所有文件:

find . -type f -atime 5


5touch命令

touch命令:

=用于改变文件或目录的访问时间和修改时间

touch [-am] [-t<日期时间>] [目录|文件]

如果指定目录文件不存在,则会直接创建一个空文件,所以touch也常用来创建一个空白文件

#创建一个新文件aa.txt
touch aa.txt

选项说明:

-a: 只修改访问时间
-m : 只修改 修改时间
-t : 使用指定日期时间,而非系统时间 。例如要修改为2019年10月20日16:38分13秒。参数就是:‘20191020163813’


7上传文件工具

从本地windows上传一些文件到远程Linux服务器可以通过xshell的xftp也可以通过下面这个小工具lrzsz,使用更加方便。

yum install lrzsz #安装工具

常用命令:
sz dist.zip #下载文件dist.zip到本地
rz #会打开窗口,上传文件到远程服务器

猜你喜欢

转载自blog.csdn.net/qq_47945825/article/details/108953881