linux核心基础-文件管理-20240616复习

关于命令提示符

[zhiwei01@fjh001 ~]$ 
	$  表示普通用户,身份提示符

[root@fjh001 ~]#       
	最后一个#  表示是用户身份提示符,root则是#

关于ssh命令

windows
ssh root@123.206.16.61 56717  

#  linux怎么写 
ssh -p 56717 root@123.206.16.61

history

#清空历史记录
history -c  #清空本次内存中的历史记录
history -w #覆盖写入 .bash_history中

 #清空.bash_history
> bash_history

关于w命令,显示系统登录用户

stat命令,查看文件,文件夹状态

tree 命令

file命令查看文件类型

touch

#一次性创建多个文件
[root@fjh001 ~]# touch /opt/王者/坦克/{老夫子,廉颇,吕布,妲己}

alias命令(别名命令)

alias 命令只对当前终端有效,当终端关闭之后,我们所设置的别名全部失效。

  alias在系统中是怎么用的呢?

1.查看系统的默认别名,alias
[root@fjh001 快乐风男]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@fjh001 快乐风男]# 


2.修改关于rm的 别名
你可以自由修改rm的别名,如修改语法
[root@fjh001 快乐风男]# alias  rm='rm -i'
[root@fjh001 快乐风男]# 


3.你可以自己去定义这样的,好用的别名

定义永久别名

alias lp='cd /home/pei'   #在配置文件/etc/profile 末行追加写入
source /etc/profile
##去掉环境变量下一次生效

.bashrc  #个人用户变量在配置文件
.bash_peofile #个人用户变量在配置文件

利用nginx创建简单的网页

nginx的html文件
/usr/share/nginx/html

关闭防火墙
iptables -F

find命令

find 目录 -选项 动作
find / -size +26M -name '*.txt'   #查找小于26M文件后缀为txt文件
find / -size -26M -name '*.txt'
find / -size 26M -name '*.txt'

-type -f  #文本
-type -d  #目录
-perm  文件权限
-maxdepth 搜索深度,以用户指定的 搜索路径为起点

find 搜索路径 -maxdepth 深度  -type f  -name '*.log'
-perm用法
-perm 664 #查找权限为664的文件,不是的不会查找出来
-perm -664 #查找符合此条件的文件rw*rw*r**  (*代表任意)
-perm -g+w,-u+w  查找同时可以被owner和group写入的文件

-perm -444 -perm /222 ! -perm /111 
-perm -a+r -perm /a+w  ! -perm /a+x
##以上两个命令效果相同,都是查找可以被任何人读取,且至少可以被人(owner或group或others)写入,但任何人都不可以执行的文件。

date

 %F	完整日期格式,等价于 %Y-%m-%d
 %T	时间,等于%H:%M:%S

[root@muserver ~]# date +%F
2024-06-16
[root@muserver ~]# date +%T
14:33:58
[root@muserver ~]# date
20240616日 星期日 14:32:50 CST

wc命令

wc 【option】【file
-l --lines
-w --words 显示字数
-m --chars 显示字符数
-c --bytes 显示字节数


• UTF-8编码:
一个英文字符等于一个字节
一个中文(含繁体)等于三个字节
1字符=3字节
#使用  echo $LANG 查看当前编码

1、计算机存储信息的最小单位,称之为位(bit),音译比特,二进制的一个“0”或一个“”叫一位。
2、计算机存储容量基本单位是字节(Byte),音译为拜特,8个二进制位组成1个字节。
3、计算机存储容量大小以字节数来度量,1024进位制:
1024B=1K (千) B
1024KB=1M (兆) B
1024MB=1G(吉)B
1024GB=1T (太) B
4、字符是一种符号,同以上说的存储单位不是一回事。如:'#'

xargs

xargs实现批量备份

[root@muserver home]# touch ceshi{1..15}.txt
[root@muserver home]# ll
总用量 8
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi10.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi11.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi12.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi13.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi14.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi15.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi1.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi2.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi3.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi4.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi5.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi6.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi7.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi8.txt
-rw-r--r-- 1 root      root         0 5月  16 23:10 ceshi9.txt
drwx------ 2 ops01     ops01     4096 3月  22 21:54 ops01
drwx------ 2 peizhibin peizhibin 4096 4月  29 18:45 peizhibin
[root@muserver home]# find ./ -name '*.txt' |xargs -i cp {} {}.bak

xargs实现批量重命名

#补充:rename用法  rename 源字符串 新字符串 文件对象
[root@muserver mulu]# ls
ceshi1.log  ceshi2.log  ceshi3.log  ceshi4.log
[root@muserver mulu]# ls | xargs -i rename log txt {}
[root@muserver mulu]# ls
ceshi1.txt  ceshi2.txt  ceshi3.txt  ceshi4.txt
[root@muserver mulu]#

xargs实现搜索‘xiake’关键词并显示下哪个目录下

[root@muserver mulu]# ls
ceshi1.txt  ceshi2.txt  ceshi3.txt  ceshi4.txt
[root@muserver mulu]# ls |xargs -i grep 'xiake' {}
xiake
[root@muserver mulu]# ls |xargs -i grep -l 'xiake' {}
ceshi1.txt
[root@muserver mulu]#

Linux grep (global regular expression) 命令用于查找文件里符合条件的字符串或正则表达式。
grep 指令用于查找内容包含指定的范本样式的文件,如果发现某文件的内容符合所指定的范本样式,预设 grep 指令会把含有范本样式的那一列显示出来
grep -l  -l:只打印匹配的文件名。

NDS配置

DNS服务器配置信息
1、windows:C:\Windows\System32\drivers\etc\hosts
2、linux:/etc/resolv.conf

需要记忆

变量

## 1. 变量的作用
[root@fjh001 ~]# cat hello.sh 
name="隔壁的老张"

echo "你好 $name"

echo "吃了吗 $name"

echo "你今天开心吗 $name"
echo "你今天开心吗 $name"


2.变量的取值
echo ${变量名}

2.系统内置变量

PATH,让你输入linux命令,系统优先去PATH中定义的目录,寻找,是否有该命令,有则执行,无则报错。
LANG ,系统中的变量,是有它的作用的,如这个LANG,可以修改系统的中英文字符集

LANG变量

echo ${LANG}
en_US.UTF-8  #英文
zh_CN.UTF-8  #中文
##修改方法
LANG='en_US.UTF-8'

md5sum

md5sum

md5sum 用于计算和校验文件的MD5值。
md5sum
常常被用来验证网络文件传输的完整性,防止文件被人篡改。在日常工作当中,我们可以用来判断系统中的重要文件是否被篡改。

linux最小文件大小为4kb,空白文件就是4kb

find

find -type -f 找出文本类型的文件
find -type-d 找出文件来了型的文件
*可以表示通配符,模糊搜索
-0 或者的意思
find./ -name '*.log' -o -name '* txt'

find的特殊用法

##-ok和-exec不能同时使用

[root@muserver1 pei]#   #找到文件并删除不提示 方法1
[root@muserver1 pei]# touch {1..5}.txt
[root@muserver1 pei]# ls
1.txt  2.txt  3.txt  4.txt  5.txt
[root@muserver1 pei]# find -name '*.txt' |xargs -i rm -f {}
[root@muserver1 pei]# ls
[root@muserver1 pei]#   #找到文件并删除不提示 方法2
[root@muserver1 pei]# touch {1..5}.txt
[root@muserver1 pei]# ls
1.txt  2.txt  3.txt  4.txt  5.txt
[root@muserver1 pei]# find -name '*.txt' -exec rm -f {} \;
[root@muserver1 pei]# ls
[root@muserver1 pei]#

[root@muserver1 pei]#   #找到文件并删除提示 方法1
[root@muserver1 pei]# touch {1..5}.txt
[root@muserver1 pei]# ls
1.txt  2.txt  3.txt  4.txt  5.txt
[root@muserver1 pei]# find -name '*.txt' -exec rm -i {} \;
rm:是否删除普通空文件 "./1.txt"?y
rm:是否删除普通空文件 "./2.txt"?y
rm:是否删除普通空文件 "./3.txt"?y
rm:是否删除普通空文件 "./4.txt"?y
rm:是否删除普通空文件 "./5.txt"?y
[root@muserver1 pei]# ls
[root@muserver1 pei]#   #找到文件并删除提示 方法2
[root@muserver1 pei]# touch {1..5}.txt
[root@muserver1 pei]# find -name '*.txt' -ok rm {} \;
< rm ... ./1.txt > ? y
< rm ... ./2.txt > ? y
< rm ... ./3.txt > ? y
< rm ... ./4.txt > ? y
< rm ... ./5.txt > ? y
[root@muserver1 pei]# ls
[root@muserver1 pei]#

stat

[root@muserver1 pei]# stat 1.txt
  File: ‘1.txt’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd02h/64770d	Inode: 143         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2024-05-16 22:43:48.952863889 -0400   #cat读取了会改变
Modify: 2024-05-16 22:43:48.952863889 -0400  #文件名/属性/内容更改了
Change: 2024-05-16 22:43:48.952863889 -0400  #内容更改
 Birth: -
[root@muserver1 pei]#

#更改modfiy时间:touch -d '2024-05-20' -m 文件名 
#更改access时间:touch -d '2024-05-20' -a 文件名 
#更改change时间:touch -d '2024-05-20' -c 文件名 


##结合 find命令
##找出5天前的日志
find . -name '*.log' -mtime +5  #mtime  modify time
-5 五天以内  5五天前那一天的日志
posted @   lipga  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示