shell对文件的操作

shell脚本编写中,时常会用到对文件的相关操作,比如增加内容,修改内容,删除部分内容,查看部分内容等,但是上述举例的这些操作一般都是需要在文本编辑器中才能操作,常用的文本编辑器如:gedit、vim、nano等又是交互式文本编辑器,脚本无法自己独立完成,必须有人参与才可以完成。如果这样的话又违背了我们编写脚本的意愿(全部由机器来完成,减少人的工作压力,提升工作效率)。emm…如何才能让这些操作全部脚本自己就搞定,而不需要人的参与,而且又能按照我们的脚本预案来完成呢?

为了解决上述问题,linux为大家提供了一些命令,比如Perl、sed等命令,今天我就着重为大家介绍一下sed命令。

一、sed介绍

sed是linux中提供的一个外部命令,它是一个行(流)编辑器,非交互式的对文件内容进行增删改查的操作,使用者只能在命令行输入编辑命令、指定文件名,然后在屏幕上查看输出。它和文本编辑器有本质的区别

代码语言:javascript代码运行次数:0运行复制

区别是:文本编辑器: 编辑对象是文件行编辑器:编辑对象是文件中的行

也就是前者一次处理一个文本,而后者是一次处理一个文本中的一行。这个是我们应该弄清楚且必须牢记的,否者可能无法理解sed的运行原理和使用精髓。

sed数据处理原理

shell对文件的操作

二、sed语法

sed 命令语法:

sed [options] ‘{command}[flags]’ [filename]

代码语言:javascript代码运行次数:0运行复制

#命令选项-e script 将脚本中指定的命令添加到处理输入时执行的命令中  多条件,一行中要有多个操作-f script 将文件中指定的命令添加到处理输入时执行的命令中-n        抑制自动输出-i        编辑文件内容-i.bak    修改时同时创建.bak备份文件。-r        使用扩展的正则表达式!         取反 (跟在模式条件后与shell有所区别)#command   对文件干什么sed常用内部命令a   在匹配后面添加i   在匹配前面添加d   删除s   查找替换  字符串c   更改y   转换   N D P p   打印#flags数字             表示新文本替换的模式g:             表示用新文本替换现有文本的全部实例p:             表示打印原始的内容w filename:     将替换的结果写入文件

2.1)sed内部命令说明

演示实例文档

代码语言:javascript代码运行次数:0运行复制

[root@zutuanxue ~]# cat data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

文件内容增加操作,将数据追加到某个位置之后,使用命令a。

演示案例

代码语言:javascript代码运行次数:0运行复制

在data1的每行后追加一行新数据内容: append data "haha"[root@zutuanxue ~]# sed 'aappend data "haha"' data11 the quick brown fox jumps over the lazy dog.append data "haha"2 the quick brown fox jumps over the lazy dog.append data "haha"3 the quick brown fox jumps over the lazy dog.append data "haha"4 the quick brown fox jumps over the lazy dog.append data "haha"5 the quick brown fox jumps over the lazy dog.append data "haha"在第二行后新开一行追加数据: append data "haha"[root@zutuanxue ~]# sed '2aappend data "haha"' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.append data "haha"3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.在第二到四行每行后新开一行追加数据: append data "haha"[root@zutuanxue ~]# sed '2,4aappend data "haha"' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.append data "haha"3 the quick brown fox jumps over the lazy dog.append data "haha"4 the quick brown fox jumps over the lazy dog.append data "haha"5 the quick brown fox jumps over the lazy dog.匹配字符串追加: 找到包含"3 the"的行,在其后新开一行追加内容: append data "haha"[root@zutuanxue ~]# sed '/3 the/aappend data "haha"' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.append data "haha"4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.//开启匹配模式  /要匹配的字符串/

文件内容增加操作,将数据插入到某个位置之前,使用命令i。

演示案例

代码语言:javascript代码运行次数:0运行复制

在data1的每行前插入一行新数据内容: insert data "haha"[root@zutuanxue ~]# sed 'iinsert data "haha"' data1insert data "haha"1 the quick brown fox jumps over the lazy dog.insert data "haha"2 the quick brown fox jumps over the lazy dog.insert data "haha"3 the quick brown fox jumps over the lazy dog.insert data "haha"4 the quick brown fox jumps over the lazy dog.insert data "haha"5 the quick brown fox jumps over the lazy dog.在第二行前新开一行插入数据: insert data "haha"[root@zutuanxue ~]# sed '2iinsert data "haha"' data11 the quick brown fox jumps over the lazy dog.insert data "haha"2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.在第二到四行每行前新开一行插入数据: insert data "haha"[root@zutuanxue ~]# sed '2,4iinsert data "haha"' data11 the quick brown fox jumps over the lazy dog.insert data "haha"2 the quick brown fox jumps over the lazy dog.insert data "haha"3 the quick brown fox jumps over the lazy dog.insert data "haha"4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.匹配字符串插入: 找到包含"3 the"的行,在其前新开一行插入内容: insert data "haha"[root@zutuanxue ~]# sed '/3 the/iinsert data "haha"' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.insert data "haha"3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

文件内容修改操作–替换,将一行中匹配的内容替换为新的数据,使用命令s。

演示案例

代码语言:javascript代码运行次数:0运行复制

从标准输出流中做替换,将test替换为text[root@zutuanxue ~]# echo "this is a test" |sed 's/test/text/'this is a text将data1中每行的dog替换为cat[root@zutuanxue ~]# sed 's/dog/cat/' data11 the quick brown fox jumps over the lazy cat.2 the quick brown fox jumps over the lazy cat.3 the quick brown fox jumps over the lazy cat.4 the quick brown fox jumps over the lazy cat.5 the quick brown fox jumps over the lazy cat.将data1中第二行的dog替换为cat[root@zutuanxue ~]# sed '2s/dog/cat/' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy cat.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.将data1中第二到第四行的dog替换为cat[root@zutuanxue ~]# sed '2,4s/dog/cat/' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy cat.3 the quick brown fox jumps over the lazy cat.4 the quick brown fox jumps over the lazy cat.5 the quick brown fox jumps over the lazy dog.匹配字符串替换:将包含字符串"3 the"的行中的dog替换为cat[root@zutuanxue ~]# sed '/3 the/s/dog/cat/' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy cat.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

文件内容修改操作–更改,将一行中匹配的内容替换为新的数据,使用命令c。

演示案例

代码语言:javascript代码运行次数:0运行复制

将data1文件中的所有行的内容更改为: change data "data"[root@zutuanxue ~]# sed 'cchange data "haha"' data1change data "haha"change data "haha"change data "haha"change data "haha"change data "haha"将data1文件第二行的内容更改为: change data "haha"[root@zutuanxue ~]# sed '2cchange data "haha"' data11 the quick brown fox jumps over the lazy dog.change data "haha"3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.将data1文件中的第二、三、四行的内容更改为:change data "haha"[root@zutuanxue ~]# sed '2,4cchange data "haha"' data11 the quick brown fox jumps over the lazy dog.change data "haha"5 the quick brown fox jumps over the lazy dog.将data1文件中包含"3 the"的行内容更改为: change data "haha"[root@zutuanxue ~]# sed '/3 the/cchange data "data"' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.change data "data"4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

文件内容修改操作–字符转换,将一行中匹配的内容替换为新的数据,使用命令y。

演示案例

代码语言:javascript代码运行次数:0运行复制

将data1中的a b c字符转换为对应的 A  B  C字符[root@zutuanxue ~]# sed 'y/abc/ABC/' data11 the quiCk Brown fox jumps over the lAzy dog.2 the quiCk Brown fox jumps over the lAzy dog.3 the quiCk Brown fox jumps over the lAzy dog.4 the quiCk Brown fox jumps over the lAzy dog.5 the quiCk Brown fox jumps over the lAzy dog.

文件内容删除,将文件中的指定数据删除,使用命令d。

演示案例

代码语言:javascript代码运行次数:0运行复制

删除文件data1中的所有数据[root@zutuanxue ~]# sed 'd' data1删除文件data1中的第三行数据[root@zutuanxue ~]# sed '3d' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.删除文件data1第三到第四行的数据[root@zutuanxue ~]# sed '3,4d' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.删除文件data1中包含字符串"3 the"的行[root@zutuanxue ~]# sed '/3 the/d' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

文件内容查看,将文件内容输出到屏幕,使用命令p。

讯飞写作 讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

讯飞写作 56 查看详情 讯飞写作

演示案例

代码语言:javascript代码运行次数:0运行复制

打印data1文件内容[root@zutuanxue ~]# sed 'p' data11 the quick brown fox jumps over the lazy dog.1 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.打印data1文件第三行的内容[root@zutuanxue ~]# sed '3p' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.打印data1文件第二、三、四行内容[root@zutuanxue ~]# sed '2,4p' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.打印data1文件包含字符串"3 the"的行[root@zutuanxue ~]# sed '/3 the/p' data11 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog. 可以看得出,打印内容是重复的行,原因是打印了指定文件内容一次,又将读入缓存的所有数据打印了一次,所以会看到这样的效果,如果不想看到这样的结果,可以加命令选项-n抑制内存输出即可。

2.2)命令选项说明

sed语法 在sed命令中,命令选项是对sed中的命令的增强

在命令行中使用多个命令 -e

代码语言:javascript代码运行次数:0运行复制

将brown替换为green dog替换为cat[root@zutuanxue ~]# sed -e 's/brown/green/;s/dog/cat/' data11 the quick green fox jumps over the lazy cat.2 the quick green fox jumps over the lazy cat.3 the quick green fox jumps over the lazy cat.4 the quick green fox jumps over the lazy cat.5 the quick green fox jumps over the lazy cat.

从文件读取编辑器命令 -f 适用于日常重复执行的场景

代码语言:javascript代码运行次数:0运行复制

1)将命令写入文件[root@zutuanxue ~]# vim abcs/brown/green/s/dog/cat/s/fox/elephant/2)使用-f命令选项调用命令文件[root@zutuanxue ~]# sed -f abc data1 1 the quick green elephant jumps over the lazy cat.2 the quick green elephant jumps over the lazy cat.3 the quick green elephant jumps over the lazy cat.4 the quick green elephant jumps over the lazy cat.5 the quick green elephant jumps over the lazy cat.

抑制内存输出 -n

代码语言:javascript代码运行次数:0运行复制

打印data1文件的第二行到最后一行内容  $最后的意思[root@zutuanxue ~]# sed -n '2,$p' data1 2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

使用正则表达式 -r

代码语言:javascript代码运行次数:0运行复制

打印data1中以字符串"3 the"开头的行内容[root@zutuanxue ~]# sed -n  -r '/^(3 the)/p' data13 the quick brown fox jumps over the lazy dog.

从上述的演示中,大家可以看出,数据处理只是在缓存中完成的,并没有实际修改文件内容,如果需要修改文件内容可以直接使用-i命令选项。在这里我需要说明的是-i是一个不可逆的操作,一旦修改,如果想复原就很困难,几乎不可能,所以建议大家在操作的时候可以备份一下源文件。-i命令选项提供了备份功能,比如参数使用-i.bak,那么在修改源文件的同时会先备份一个以.bak结尾的源文件,然后再进行修改操作。

代码语言:javascript代码运行次数:0运行复制

1)查看文件列表,没有发现data1.bak[root@zutuanxue ~]# lsabc  apache  data1  Dobby  file  node-v10.14.1  Python-3.7.1  soft1  vimset2)执行替换命令并修改文件[root@zutuanxue ~]# sed -i.bak 's/brown/green/' data13)发现文件夹中多了一个data1.bak文件[root@zutuanxue ~]# lsabc     data1      Dobby  node-v10.14.1  soft1apache  data1.bak  file   Python-3.7.1   vimset4)打印比较一下,发现data1已经被修改,data1.bak是源文件的备份。[root@zutuanxue ~]# cat data11 the quick green fox jumps over the lazy dog.2 the quick green fox jumps over the lazy dog.3 the quick green fox jumps over the lazy dog.4 the quick green fox jumps over the lazy dog.5 the quick green fox jumps over the lazy dog.[root@zutuanxue ~]# cat data1.bak 1 the quick brown fox jumps over the lazy dog.2 the quick brown fox jumps over the lazy dog.3 the quick brown fox jumps over the lazy dog.4 the quick brown fox jumps over the lazy dog.5 the quick brown fox jumps over the lazy dog.

2.3)标志

在sed命令中,标志是对sed中的内部命令做补充说明

代码语言:javascript代码运行次数:0运行复制

演示文档[root@zutuanxue ~]# cat data21 the quick brown fox jumps over the lazy dog . dog2 the quick brown fox jumps over the lazy dog . dog3 the quick brown fox jumps over the lazy dog . dog4 the quick brown fox jumps over the lazy dog . dog5 the quick brown fox jumps over the lazy dog . dog

数字标志:此标志是一个非零正数,默认情况下,执行替换的时候,如果一行中有多个符合的字符串,如果没有标志位定义,那么只会替换第一个字符串,其他的就被忽略掉了,为了能精确替换,可以使用数字位做定义。

代码语言:javascript代码运行次数:0运行复制

替换一行中的第二处dog为cat[root@zutuanxue ~]# sed 's/dog/cat/2' data21 the quick brown fox jumps over the lazy dog . cat2 the quick brown fox jumps over the lazy dog . cat3 the quick brown fox jumps over the lazy dog . cat4 the quick brown fox jumps over the lazy dog . cat5 the quick brown fox jumps over the lazy dog . cat

g标志:将一行中的所有符合的字符串全部执行替换

代码语言:javascript代码运行次数:0运行复制

将data1文件中的所有dog替换为cat[root@zutuanxue ~]# sed 's/dog/cat/g' data21 the quick brown fox jumps over the lazy cat . cat2 the quick brown fox jumps over the lazy cat . cat3 the quick brown fox jumps over the lazy cat . cat4 the quick brown fox jumps over the lazy cat . cat5 the quick brown fox jumps over the lazy cat . cat

p标志:打印文本内容,类似于-p命令选项

代码语言:javascript代码运行次数:0运行复制

[root@zutuanxue ~]# sed  '3s/dog/cat/p' data21 the quick brown fox jumps over the lazy dog . dog2 the quick brown fox jumps over the lazy dog . dog3 the quick brown fox jumps over the lazy cat . dog3 the quick brown fox jumps over the lazy cat . dog4 the quick brown fox jumps over the lazy dog . dog5 the quick brown fox jumps over the lazy dog . dog

w filename标志:将修改的内容存入filename文件中

代码语言:javascript代码运行次数:0运行复制

[root@zutuanxue ~]# sed  '3s/dog/cat/w text' data21 the quick brown fox jumps over the lazy dog . dog2 the quick brown fox jumps over the lazy dog . dog3 the quick brown fox jumps over the lazy cat . dog4 the quick brown fox jumps over the lazy dog . dog5 the quick brown fox jumps over the lazy dog . dog可以看出,将修改的第三行内容存在了text文件中[root@zutuanxue ~]# cat text 3 the quick brown fox jumps over the lazy cat . dog

三、练习案例

3.1、写一个初始化系统的脚本 案例需求 1)自动修改主机名(如:ip是192.168.0.88,则主机名改为server88.zutuanxue.cc)

a. 更改文件非交互式 sed

/etc/sysconfig/network

b.将本主机的IP截取出来赋值给一个变量ip;再然后将ip变量里以.分割的最后一位赋值给另一个变量ip1

2)自动配置可用的yum源

3)自动关闭防火墙和selinux

代码语言:javascript代码运行次数:0运行复制

1、关闭防火墙2、关闭selinux3、配置yum源4、ntp时间服务器 5、更新系统软件包

3.2、写一个搭建ftp服务的脚本,要求如下: 案例需求 1)不支持本地用户登录local_enable=NO 2) 匿名用户可以上传 新建 删除 anon_upload_enable=YES anon_mkdir_write_enable=YES 3) 匿名用户限速500KBps anon_max_rate=500000

代码语言:javascript代码运行次数:0运行复制

仅供参考:#!/bin/bashipaddr=`ifconfig eth0|sed -n '2p'|sed -e 's/.*inet addr:(.*) Bcast.*/1/g'`iptail=`echo $ipaddr|cut -d'.' -f4`ipremote=192.168.1.10#修改主机名hostname server$iptail.zutuanxue.comsed -i "/HOSTNAME/cHOSTNAME=server$iptail.zutuanxue.com" /etc/sysconfig/networkecho "$ipaddr server$iptail.zutuanxue.cc" >>/etc/hosts#关闭防火墙和selinuxservice iptables stopsetenforce 0 >/dev/null 2>&1sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config#配置yum源(一般是内网源)#test networkping -c 1 $ipremote > /dev/null 2>&1if [ $? -ne 0 ];thenecho "你的网络不通,请先检查你的网络"exit 1elseecho "网络ok."ficat > /etc/yum.repos.d/server.repo </dev/null#备份配置文件conf=/etc/vsftpd/vsftpd.confcp $conf $conf.default#根据需求修改配置文件sed -ir '/^#|^$/d' $confsed -i '/local_enable/clocal_enable=NO' $confsed -i '$a anon_upload_enable=YES' $confsed -i '$a anon_mkdir_write_enable=YES' $confsed -i '$a anon_other_write_enable=YES' $confsed -i '$a anon_max_rate=512000' $conf#启动服务service vsftpd restart &>/dev/null && echo"vsftpd服务启动成功"#测试验证chmod 777 /var/ftp/pubcp /etc/hosts /var/ftp/pub#测试下载cd /tmplftp $ipaddr <<endcd pubget hostsexitendif [ -f /tmp/hosts ];thenecho "匿名用户下载成功"rm -f /tmp/hostselseecho "匿名用户下载失败"fi#测试上传、创建目录、删除目录等cd /tmplftp $ipaddr << endcd pubmkdir test1mkdir test2put /etc/grouprmdir test2exitendif [ -d /var/ftp/pub/test1 ];then    echo "创建目录成功"if [ ! -d /var/ftp/pub/test2 ];then    echo "文件删除成功"        fielseif [ -f /var/ftp/pub/group ];thenecho "文件上传成功"        else        echo "上传、创建目录删除目录部ok"        fi fi   [ -f /var/ftp/pub/group ] && echo "上传文件成功"

以上就是shell对文件的操作的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/459767.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
安迪不在家,不知火舞只能靠他了
上一篇 2025年11月8日 03:03:36
Windows暂停更新方法
下一篇 2025年11月8日 03:03:42

相关推荐

  • 夸克AI怎么处理PDF文档_夸克AI PDF解析与批注功能教程

    使用夸克AI可解析PDF并添加批注,先通过“文档”模块导入PDF,点击“用AI读文档”生成摘要与要点,长按文字选择高亮或批注并分类标签,批注汇总至笔记面板,最后导出PDF时可选包含AI解析内容与批注,支持本地保存或分享。 ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 Deep…

    2026年8月28日
    000
  • Linux 基本操作命令总结

    下面给大家总结介绍linux 基本操作命令,希望对需要的朋友有所帮助,更多linux使用教程请访问linux视频教程进行学习! Linux 基本操作命令 文件和目录管理 创建和删除 创建:mkdir 删除:rm 删除非空目录:rm -rf file 目录 删除日志 rm log (等价: $find…

    2026年8月28日
    000
  • 如何解决邮件发送中的复杂格式问题?使用Composer安装PEAR/Mail_Mime库可以帮你轻松搞定!

    可以通过以下地址学习 Composer:学习地址 在开发一个需要发送格式复杂邮件的项目时,我遇到了一个棘手的问题:如何在邮件中正确处理多种格式的内容,如附件、嵌入图片和html内容。这些问题导致邮件发送效果不佳,甚至无法正常发送。为了解决这个问题,我决定使用 composer 来安装 pear/ma…

    用户投稿 2026年8月28日
    300
  • Laravel 环境搭建与基础配置(Windows/Mac/Linux)

    在不同操作系统上搭建 laravel 环境的步骤如下:1. windows:使用 xampp 安装 php 和 composer,配置环境变量,安装 laravel。2. mac:使用 homebrew 安装 php 和 composer,安装 laravel。3. linux:使用 ubuntu …

    2026年8月28日
    100
  • Linux expect详解

    随处可见的expect 第一次见expect这个命令还是我第一次参加全量上线的时候,那是公司的一个牛人用Shell脚本写的一套自动部署、MD5 比对、发布的全量上线工具,没事的时候,看了下其中的几个脚本,好多的expect命令。实在是看不懂这个expect命令的用法,所以就找时间总结了这篇关于exp…

    2026年8月28日
    000
  • 手把手教你们Python配置OpenCV环境,小白看一遍就会了

    手把手教你们Python配置OpenCV环境,小白看一遍就会了手把手教你们Python配置OpenCV环境,小白看一遍就会了手把手教你们Python配置OpenCV环境,小白看一遍就会了手把手教你们Python配置OpenCV环境,小白看一遍就会了

    ?️‍?1、简介?1.1、Opecv介绍 开课之前,我们先给大家讲讲opecv是一个基于bsd许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在linux、windows、android和mac os操作系统上。 [1] 它轻量级而且高效——由一系列 c 函数和少量 c++ 类构成,同时…

    2026年8月28日 用户投稿
    300
  • Spring Boot WebService服务发布失败:如何解决Jar包缺失导致的java.lang.NoClassDefFoundError异常?

    Spring Boot WebService部署失败:排查Jar包缺失问题 在Spring Boot中构建WebService服务时,部署和运行问题时有发生。本文分析一个常见的案例:“Spring Boot构建的WebService服务发布测试失败,提示找不到Jar包”。 问题描述: 运行程序时抛出…

    2026年8月28日
    000
  • React前端与PHP后端联调:高效定位与解决PHP错误

    本文针对React前端与PHP后端集成时,PHP错误难以追踪的问题,提供了两种高效调试策略。核心在于通过配置PHP服务器端错误日志,将详细错误信息记录到文件,以及利用浏览器开发者工具的网络面板直接检查API的原始响应,从而避免JSON解析错误并快速定位后端问题。 问题剖析:React前端下PHP错误…

    2026年8月28日
    000
  • Yii 框架执行数据库事务时遇到异常怎么处理?

    在 yii 框架中处理数据库事务异常时,应使用 try-catch 块捕获异常并回滚事务。具体方法包括:1) 使用 try-catch 块捕获 exception 和 throwable 异常,并在异常发生时回滚事务;2) 处理事务嵌套,确保只有最外层事务真正提交或回滚;3) 设置事务隔离级别以处理…

    2026年8月28日
    300
  • 使用Flag变量实现Java菜单循环与返回

    本文将介绍如何在Java程序中使用flag变量控制菜单的循环和返回。通过设置和判断flag变量的值,可以实现从子菜单返回主菜单的功能,避免不必要的菜单重复显示,提升用户体验。本文将提供代码示例,详细解释flag变量的工作原理,并给出使用注意事项。 在Java程序中,经常需要构建交互式的菜单界面,让用…

    2026年8月28日
    000
  • 投资领域掀起大模型“淘金热”,AI的“财商”有多高?

    ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ AI赋能财富管理:机遇与挑战并存 国产AI大模型的兴起,正深刻改变着财富管理行业的面貌。“AI理财”已成为投资者关注的焦点,但其可靠性及潜在风险也引发广泛讨论。本文将探讨AI在投资理财领域的应用…

    2026年8月28日
    000
  • Linux shell 脚本分享

    linux shell 脚本分享 Shell 是一个命令解释器,处于内核和用户之间,负责把用户的指令传递给内核并且把执行结果回显给用户,Shell 它是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁,同时,Shell 也可以作为一门强大的编程语言 推荐:【Linux视频教程】 理论 我…

    用户投稿 2026年8月28日
    100
  • 如何在 Yii 项目中引入 GraphQL?

    在 yii 项目中引入 graphql 可以通过以下步骤实现:1. 定义 schema,描述数据结构和查询操作;2. 实现解析器,映射查询到数据获取逻辑;3. 处理请求并生成响应。通过这些步骤,开发者可以在 yii 中集成 graphql api,提供灵活的数据获取方式。 引言 在现代 Web 开发…

    2026年8月28日
    300
  • 抖音店铺体验分受什么影响?体验分80分要多少单

    短视频平台抖音逐渐成为人们生活中不可或缺的一部分。抖音店铺作为抖音电商的重要组成部分,其店铺体验分的高低直接关系到店铺的销量和口碑。抖音店铺体验分受哪些因素影响呢?本文将为您揭秘影响抖音店铺体验分的关键因素。 一、商品质量 商品质量是影响抖音店铺体验分的首要因素。优质的产品能够满足消费者的需求,提高…

    2026年8月28日
    100
  • 清华大学2025年将适度扩招本科生 重点培养“AI+”拔尖创新人才

    ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 清华大学宣布将适度扩大本科招生规模,计划于2025年新增约150个本科招生名额。同时,学校将成立一所新的本科通识书院,专注培养人工智能与其他学科交叉融合的复合型人才,以满足国家战略需求和社会发展…

    2026年8月28日
    900
  • 嵌入式linux实时操作系统及应用编程

    《嵌入式linux实时操作系统及应用编程》是2011年清华大学出版社出版的图书,作者是熊茂华。本书是嵌入式linux实时操作系统及应用编程的一本实用指导书籍,通过案例详细介绍嵌入式linux实时操作系统的应用编程,案例中的程序都取自实际的项目,且对程序有详细注解。 本书的内容包括: (推荐学习:Li…

    2026年8月28日
    000
  • windows怎么重启日志查看

    使用事件查看器中的事件ID 41、6005、6006和1074筛选系统日志,结合可靠性监视器与蓝屏分析工具,可准确区分正常重启与意外崩溃。 要查看Windows系统的重启日志,最直接且信息最丰富的途径就是使用“事件查看器”(Event Viewer)。它详细记录了系统启动、关机以及各种异常事件,是追…

    2026年8月28日
    100
  • Linux下”/”与”~”的区别详细介绍

    首先: ”/“是根目录,”~“是家目录。Linux存储是以挂载的方式,相当于是树状的,源头就是”/“,也就是根目录。而每个用户都有”家“目录,也就是用户的个人目录,比如root用户的”家“目录就是/root,普通用户a的家目录就是/home/a.可以看到 用户创建完后,我们就可以在/home目录下看…

    2026年8月28日
    200
  • 黄仁勋:英伟达最后入局半导体但永远不晚,自己若今年毕业将爱上 AI

    7 月 16 日消息,根据新浪科技报道,英伟达 CEO 黄仁勋在今日下午的媒体采访中提到,英伟达是较晚成立的半导体公司之一,但他强调“入场虽晚,却从不嫌迟”。 黄仁勋说道:“我不是先行者,而是后来者,所以永远不会太晚。因为如果你是第一个进入市场的人,你有独特的优势;而作为最后一个进入的人,同样也能找…

    2026年8月28日
    100
  • ThinkPHP 性能优化:10个提升速度的技巧

    提升thinkphp应用性能的10个技巧包括:1.优化数据库查询,减少查询次数;2.使用缓存策略,降低数据库负载;3.实施延迟加载,减少初始加载时间;4.进行批量操作,减少数据库连接次数;5.避免n+1查询问题,使用关联查询;6.优化模板渲染,使用缓存模板;7.启用编译模式,提升启动速度;8.优化日…

    2026年8月28日
    100

发表回复

登录后才能评论
关注微信