linux shell脚本之lnmp的搭建

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
#this script is source packages installed lnmp for redhat or centos 6.xmal
yum -y  install  wget
#"============download  the source package=============="
wget http: //cloud .github.com /downloads/libevent/libevent/libevent-2 .0.21-stable. tar .gz
wget http: //nginx .org /download/nginx-1 .3.8. tar .gz
wget http: //www .cmake.org /files/v2 .8 /cmake-2 .8.6. tar .gz
wget http: //ftp .gnu.org /gnu/bison/bison-2 .5.1. tar .gz
wget http: //cdn .mysql.com /Downloads/MySQL-5 .5 /mysql-5 .5.30. tar .gz
wget http: //ncu .dl.sourceforge.net /project/qdbm/qdbm/1 .8.77 /qdbm-1 .8.77. tar .gz
wget http: //ftp .gnu.org /pub/gnu/libiconv/libiconv-1 .14. tar .gz
wget http: //fossies .org /linux/www/gd-2 .0.35. tar .gz
wget http: //sourceforge .net /projects/mcrypt/files/Libmcrypt/2 .5.8 /libmcrypt-2 .5.8. tar .bz2 /download
wget http: //sourceforge .net /projects/mhash/files/mhash/0 .9.9.9 /mhash-0 .9.9.9. tar .bz2 /download
wget http: //sourceforge .net /projects/mcrypt/files/MCrypt/2 .6.8 /mcrypt-2 .6.8. tar .gz /download
wget http: //cronolog .org /download/cronolog-1 .6.2. tar .gz
wget http: //cn2 .php.net /distributions/php-5 .4.14. tar .gz
wget http: //ncu .dl.sourceforge.net /project/pcre/pcre/8 .11 /pcre-8 .11. tar .gz
#"=============download all======================"
printf  "========install the compile tool=============\n"
yum -y  install  gcc gcc-c++ openssl-devel ncurses ncurses-devel zlib-devel   bzip2  bzip2 -devel curl-devel libjpeg-devel libxml2*  libpng* freetype* libxslt*
#yum -y groupinstall "Development" "Development Tools"        #or   use this command instead of the above
#tar the source package  解压源代码包到指定的目录
tar  zxvf pcre-8.11. tar .gz -C  /usr/local/src/
tar  zxvf libevent-2.0.21-stable. tar .gz -C  /usr/local/src/
tar  zxvf nginx-1.3.8. tar .gz -C  /usr/local/src/
tar  zxvf cmake-2.8.6. tar .gz -C  /usr/local/src/
tar  zxvf bison-2.5.1. tar .gz -C  /usr/local/src/
tar  zxvf mysql-5.5.30. tar .gz -C  /usr/local/src/
tar  zxvf libiconv-1.14. tar .gz -C  /usr/local/src/
tar  zxvf qdbm-1.8.77. tar .gz -C  /usr/local/src/
tar  zxvf gd-2.0.35. tar .gz -C  /usr/local/src/
tar  zxvf mcrypt-2.6.8. tar .gz -C  /usr/local/src/
tar  zxvf cronolog-1.6.2. tar .gz -C  /usr/local/src/
tar  zxvf php-5.4.14. tar .gz -C  /usr/local/src/
tar  jxvf libmcrypt-2.5.8. tar .bz2 -C  /usr/local/src/
tar  jxvf mhash-0.9.9.9. tar .bz2 -C  /usr/local/src/
#Compile the unpack the source code package  编译解压的源代码包
echo "===========nginx Relevant source package is installed========== "
echo  "##### pcre install#####"
cd  /usr/local/src/pcre-8 .11/
. /configure  --prefix= /usr/local/pcre  &&  make  &&  make  install
printf  "====pcre is ok====\n"
echo  "#####libevent install######"
cd  /usr/local/src/libevent-2 .0.21-stable/
. /configure  --prefix= /usr/local/libevent  &&  make  &&  make  install
printf  "====libevent is ok====\n"
echo  "####nginx install######"
groupadd -r nginx
useradd  -r -g nginx -s  /bin/false  -M nginx
cd  /usr/local/src/nginx-1 .3.8/
###before you configure,you can  see   "./configure –help"   see carefully "–with-pcre=DIR set path to PCRE library sources"在编译之前可以先help看看
. /configure  --prefix= /usr/local/nginx  --with-pcre= /usr/local/src/pcre-8 .11/ --sbin-path= /usr/local/nginx/sbin/nginx  --pid-path= /usr/local/nginx/logs/nginx .pid  \
--with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --user=nginx --group=nginx \
--http-proxy-temp-path= /var/tmp/nginx/proxy/  --http-fastcgi-temp-path= /var/tmp/nginx/fcgi/  --lock-path= /var/lock/nginx .lock --http-client-body-temp-path= /var/tmp/nginx/client/  \
  &&  make  &&  make  install
printf  "======nginx is ok!!======\n"
mkdir  -pv  /var/tmp/nginx/
#write startup nginx files by yourself   自己手动写nginx的启动脚本
cat  >>  /etc/init .d /nginx  << EOF
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: – 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd= /usr/local/nginx/sbin/nginx
nginx_config= /usr/local/nginx/conf/nginx .conf
nginx_pid= /usr/local/nginx/logs/nginx .pid
RETVAL=0
prog= "nginx"
# Source function library.
/etc/rc .d /init .d /functions
# Source networking configuration.
/etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} =  "no"  ] &&  exit  0
[ -x $nginxd ] ||  exit  0
# Start nginx daemons functions.
start() {
if  [ -e $nginx_pid ]; then
echo  "nginx already running…."
exit  1
fi
echo  -n $ "Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] &&  touch  /var/lock/subsys/nginx
return  $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo  -n $ "Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] &&  rm  -f  /var/lock/subsys/nginx  /usr/local/nginx/logs/nginx .pid
}
reload() {
echo  -n $ "Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case  "$1"  in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo  "Usage: $prog {start|stop|restart|reload|status|help}"
exit  1
esac
exit  $RETVAL
EOF
chmod  +x  /etc/init .d /nginx
chkconfig --add nginx
chkconfig --level 35 nginx on
service nginx restart
echo "===========mysql Relevant source package is installed========== "
useradd  -M -s  /sbin/nologin   mysql
echo  "##### cmake install#####"
cd  /usr/local/src/cmake-2 .8.6
. /bootstrap  && gmake && gmake  install
printf  "====cmake is ok====\n"
echo  "##### bison install#####"
cd  /usr/local/src/bison-2 .5.1/
. /configure  &&  make  &&  make  install
printf  "====bison is ok====\n"
echo  "##### mysql install#####"
cd  /usr/local/src/mysql-5 .5.30/
cmake -DCMAKE_INSTALL_PREFIX= /usr/local/mysql  -DMYSQL_UNIX_ADDR= /tmp/mysql .sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR= /var/mysql/data  &&  make  &&  make  install
printf  "====mysql is ok====\n"
#set up the mysql configuration file and initialize the database  建立mysql的配置文件和初始化数据库
#cp usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf  ##if you memory is greater than 2G,please choose this   内存大于2G就copy这个配置文件
cp  /usr/local/mysql/support-files/my-medium .cnf  /etc/my .cnf
cp  /usr/local/mysql/support-files/mysql .server   /etc/init .d /mysqld
/usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir= /usr/local/mysql/   --datadir= /var/mysql/data
/usr/local/mysql/bin/mysqld_safe  --user=mysql
chmod  -R 755  /usr/local/mysql
chown  -R mysql:mysql  /usr/local/mysql
chown  -R mysql:mysql  /var/mysql/data
chkconfig --add mysqld
chkconfig --level 35 mysqld on
service mysqld restart
read  -p  "please set up password for mysql:"  pwd
/usr/local/mysql/bin/mysqladmin  -u root password $ pwd
export  PATH=$PATH: /usr/local/mysql/bin/
echo  "PATH=$PATH:/usr/local/mysql/bin"  >>  /etc/profile
ln  -s  /usr/local/mysql/bin/ /usr/local/bin/
ln  -s  /usr/local/mysql/lib/ /usr/lib
ln  -s  /usr/local/mysql/include/mysql/ /usr/include/
echo "===========php Relevant source package is installed========== "
echo  "####libiconv install####"
cd  /usr/local/src/libiconv-1 .14/
. /configure  --prefix= /usr/local/libiconv  &&  make  &&  make  install
printf  "====libiconv is ok====\n"
echo  "####qdbm install#####"
cd  /usr/local/src/qdbm-1 .8.77/
. /configure  --prefix= /usr/local/qdbm  -- enable -devel -- enable -zlib -- enable -iconv &&  make  &&  make  install
printf  "====qdbm is ok====\n"
echo  "####gd install####"
cd  /usr/local/src/gd-2 .0.35/
. /configure  --prefix= /usr/local/gd2  --with-jpeg --with-png --with-zlib --with-freetype &&  make  &&  make  install
printf  "====gd is ok====\n"
sed  -i  '/\*gd_free/a\void (*data);'  /usr/local/gd2/include/gd_io .h
echo  "/usr/local/gd2/lib"  >>  /etc/ld .so.conf
ldconfig
echo  "####libmcrypt and libltdl install####"
cd  /usr/local/src/libmcrypt-2 .5.8/
. /configure   --prefix= /usr/local/libmcrypt   &&  make  &&  make  install
ldconfig
cd  /usr/local/src/libmcrypt-2 .5.8 /libltdl
. /configure  --prefix= /usr/local/libltdl  -- enable -ltdl- install  &&  make  &&  make  install
ln  -sf  /usr/local/lib/libmcrypt .*  /usr/lib
ln  -sf  /usr/local/bin/libmcrypt-config  /usr/bin
printf  "====libmcrypt  and libltdl is ok====\n"
echo  "####mhash install####"
cd  /usr/local/src/mhash-0 .9.9.9/
. /configure   --prefix= /usr/local/mhash  &&  make  &&  make  install
ln  -sf  /usr/local/lib/libmhash .*  /usr/lib/
printf  "====mhash is ok====\n"
echo  "####mcrypt install####"
cd  /usr/local/src/mcrypt-2 .6.8/
/sbin/ldconfig
  . /configure  --prefix= /usr/local/mcrypt   &&  make  &&  make  install
printf  "====mcrypt is ok====\n"
echo  "####cronolog install####"
cd  /usr/local/src/cronolog-1 .6.2
. /configure  --prefix= /usr/local/cronolog   &&  make  &&  make  install
printf  "====cronolog is ok====\n"
echo  "####php install#####"
ln  -sf  /usr/local/mysql/lib/libmysqlclient .so.18  /usr/lib
ln  -sf  /usr/local/qdbm/lib/libqdbm .so*  /usr/lib
cd  /usr/local/src/php-5 .4.14
. /configure  --prefix= /usr/local/php5  --with-config- file -path= /usr/local/php5/etc  --with-mysql= /usr/local/mysql  \
--with-iconv= /usr/local/libiconv  --with-gd= /usr/local/gd2  --with-iconv- dir = /usr/local  --with-pdo-mysql= /usr/local/mysql   \
--with-libxml- dir = /usr  --with-qdbm= /usr/local/qdbm  --with-mime-magic= /usr/share/file/magic  --with-jpeg- dir  --with-png- dir  --with-freetype- dir  \
--with-bz2 --with-zlib  --without-pear  --with-xmlrpc --with-zlib- dir  --with-curl --with-curlwrappers --with-mcrypt= /usr/local/libmcrypt  --with-mhash \
--with-ttf --with-xsl --with-gettext --with-pear --with-openssl -- enable -discard-path -- enable -gd-native-ttf \
-- enable -bcmath -- enable -shmop -- enable -sysvsem -- enable -inline-optimization -- enable -mbregex -- enable -xml \
-- enable -soap -- enable -calendar -- enable -wddx -- enable -dba -- enable -gd-native-ttf-- enable -calendar -- enable -safe-mode \
-- enable - ftp  -- enable -fpm -- enable -zip -- enable -mbstring -- enable -bcmath -- enable -sockets -- enable -exif -- enable -magic-quotes --disable-rpath --disable-debug \
&&  make  &&  make  install
printf  "====php is ok====\n"
ln  -s  /usr/local/php5/bin/ /usr/local/bin/
ln  -s  /usr/local/php5/sbin/ /usr/local/sbin/
cp  /usr/local/src/php-5 .4.14 /php .ini-production  /usr/local/php5/php .ini
#Configure nginx support php  配置nginx支持php环境
cp  /usr/local/php5/etc/php-fpm .conf.default  /usr/local/php5/etc/php-fpm .conf
sed  -i  '/run/s/;//g'  /usr/local/php5/etc/php-fpm .conf
sed  -i  '/^ /d'  /usr/local/php5/etc/php-fpm .conf
sed  -i  's/nobody/nginx/g'  /usr/local/php5/etc/php-fpm .conf
sed  -i  '/start/s/2/20/'  /usr/local/php5/etc/php-fpm .conf
sed  -i  '/min/s/1/5/'   /usr/local/php5/etc/php-fpm .conf
sed  -i  '/max_spare/s/3/25/'  /usr/local/php5/etc/php-fpm .conf
sed  -i  '/max_children/s/5/35/'  /usr/local/php5/etc/php-fpm .conf
/usr/local/sbin/php-fpm    #启动php-fpm进程
#test nginx mysql php work tegether
sed  -i  '/\<user\>/a user nginx;'  /usr/local/nginx/conf/nginx .conf    #把user改为nginx用户
sed  -i  '/\<index\>/s/index.html index.htm/index.html index.htm index.php/g'  /usr/local/nginx/conf/nginx .conf   #添加支持index.php
#这下面的六句自己手动的添加到nginx的配置文件里面去/usr/local/nginx/conf/nginx.conf
#        location ~ \.php$ {
#            root           html;
#            fastcgi_pass   127.0.0.1:9000;
#            fastcgi_index  index.php;
#            include        fastcgi.conf;
#        }
cat  >>  /usr/local/nginx/html/test .php << EOF
<?php
$link=mysql_connect( 'localhost' , 'root' , '123456' );
if ($link)  echo  "<h1>lian jie mysql cheng gong!!</h1>" ;
mysql_close();
?>
EOF
service nginx restart
#done all  you can test lnmp http://ip(test nginx)  or http://ip/test.php(test nginx with mysql php)
                  ##############=========nginx and php-fpm Startup script##################
##############=========  #!/bin/bash
##############=========   # nginx and php-fpm Startup script for the Nginx HTTP Server
##############=========   # chkconfig: – 85 15
##############=========   nginxd=/usr/local/nginx/sbin/nginx
##############=========   nginx_config=/usr/local/nginx/conf/nginx.conf
##############=========   nginx_pid=/usr/local/nginx/logs/nginx.pid
##############=========   php_fpm=/usr/local/sbin/php-fpm
##############=========   php_fpm_config=/usr/local/php5/etc/php-fpm.conf
##############=========   php_fpm_pid=/usr/local/php5/var/run/php-fpm.pid
##############=========   RETVAL=0
##############=========   prog="nginx"
##############=========   prog1="php-fpm"
##############=========   # Source function library.
##############=========   . /etc/rc.d/init.d/functions
##############=========   # Source networking configuration.
##############=========   . /etc/sysconfig/network
##############=========   # Check that networking is up.
##############=========   [ ${NETWORKING} = "no" ] && exit 0
##############=========   [ -x $nginxd ] || exit 0
##############=========   # Start nginx daemons functions.
##############=========   start() {
##############=========   if [ -e $nginx_pid ];then
##############=========   echo "nginx already running…."
##############=========   exit 1
##############=========   fi
##############=========   echo -n $"Starting $prog: "
##############=========   RETVAL=$?
##############=========   echo
##############=========   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
##############=========   return $RETVAL
##############=========   }
##############=========   # Stop nginx daemons functions.
##############=========   stop() {
##############=========   echo -n $"Stopping $prog: "
##############=========   killproc $nginxd
##############=========   RETVAL=$?
##############=========   echo
##############=========   [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
##############=========   }
##############=========   reload() {
##############=========   echo -n $"Reloading $prog: "
##############=========   #kill -HUP `cat ${nginx_pid}`
##############=========   killproc $nginxd -HUP
##############=========   RETVAL=$?
##############=========   echo
##############=========   }
##############=========   # See how we were called.
##############=========   case "$1" in
##############=========   start)
##############=========   start
##############=========   $php_fpm -c $php_fpm_config
##############=========   echo  "starting $prog1:[ok]"
##############=========   ;;
##############=========   stop)
##############=========   stop
##############=========   echo  $"Stopping $prog1:[ok]"
##############=========   killproc $php_fpm
##############=========   RETVAL=$?
##############=========   ;;
##############=========   reload)
##############=========   reload
##############=========   ;;
##############=========   restart)
##############=========   stop
##############=========   echo  $"Stopping $prog1:[ok] "
##############=========   killproc $php_fpm
##############=========   RETVAL=$?
##############=========   start
##############=========   $php_fpm -c $php_fpm_config
##############=========   echo  "starting $prog1:[ok]"
##############=========   ;;
##############=========   status)
##############=========   status $prog
##############=========   RETVAL=$?
##############=========   ;;
##############=========   *)
##############=========   echo "Usage: $prog {start|stop|restart|reload|status|help}"
##############=========   exit 1
##############=========   esac
##############=========   exit $RETVAL
#把这个改成启动脚本的方法:1.先在linux上面vim /etc/init.d/nginx
#                          2.把以这个开头的且包括##############=========都copy到linux的/etc/init.d/nginx文件中
#                          3.用sed命令去掉##############=========这些,然后剩下来的就是nginx和php-fpm的启动脚本了
#                          4.用sed这样改  sed -i 's/##############=========   //g' /etc/init.d/nginx    直接copy这句,因为要注意#=这个的个数
#                          5.sed命令执行后,可以vim看一下,前面的那些已经去掉,然后加权限 chmod +x /etc/init.d/nginx
#                          6.然后就可以用 service nginx {start|stop|restart}命令了,执行这个命令时php-fpm也跟着start stop restart
copy所有的内容到linux新建的文件中,然后给文件赋予权限,然后执行,自动执行,漫长的过程,
自己运行这个脚本是木有出错的









本文转自 jie783213507 51CTO博客,原文链接:http://blog.51cto.com/litaotao/1248288,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
235
分享
相关文章
MySQL 备份 Shell 脚本:支持远程同步与阿里云 OSS 备份
一款自动化 MySQL 备份 Shell 脚本,支持本地存储、远程服务器同步(SSH+rsync)、阿里云 OSS 备份,并自动清理过期备份。适用于数据库管理员和开发者,帮助确保数据安全。
Linux 手动安装快速部署 LNMP 环境实战
本文详细记录了在阿里云ECS上手动搭建LNMP环境的过程,系统选用Ubuntu 24.04。主要内容包括:1) 使用`apt`安装Nginx和MySQL,并更新软件源;2) 编译安装PHP 8.4.5,配置PHP-FPM及环境路径;3) 配置MySQL root用户密码;4) 调整Nginx支持PHP解析并测试整体环境。通过此过程,重现手动配置服务器的细节,帮助熟悉各组件的安装与协同工作。
Linux云服务器如何搭建LNMP环境
LNMP环境是Linux系统中常用的Web服务架构,由Linux、Nginx、MySQL/MariaDB和PHP组成,适用于高效托管动态网站。本文以CentOS 7为例,详细介绍了LNMP环境的搭建步骤,包括Nginx、MariaDB和PHP的安装与配置,以及最终通过创建`index.php`文件验证环境是否成功部署。具体操作涵盖配置YUM仓库、安装服务、编辑配置文件、启动服务等关键步骤,确保用户能够顺利搭建并运行LNMP环境。
57 1
Linux云服务器如何搭建LNMP环境
定期备份数据库:基于 Shell 脚本的自动化方案
本篇文章分享一个简单的 Shell 脚本,用于定期备份 MySQL 数据库,并自动将备份传输到远程服务器,帮助防止数据丢失。
|
2月前
|
【linux】Shell脚本中basename和dirname的详细用法教程
本文详细介绍了Linux Shell脚本中 `basename`和 `dirname`命令的用法,包括去除路径信息、去除后缀、批量处理文件名和路径等。同时,通过文件备份和日志文件分离的实践应用,展示了这两个命令在实际脚本中的应用场景。希望本文能帮助您更好地理解和应用 `basename`和 `dirname`命令,提高Shell脚本编写的效率和灵活性。
127 32
|
6月前
|
一个用于添加/删除定时任务的shell脚本
一个用于添加/删除定时任务的shell脚本
181 1
多种脚本批量下载 Docker 镜像:Shell、PowerShell、Node.js 和 C#
本项目提供多种脚本(Shell、PowerShell、Node.js 和 C#)用于批量下载 Docker 镜像。配置文件 `docker-images.txt` 列出需要下载的镜像及其标签。各脚本首先检查 Docker 是否安装,接着读取配置文件并逐行处理,跳过空行和注释行,提取镜像名称和标签,调用 `docker pull` 命令下载镜像,并输出下载结果。使用时需创建配置文件并运行相应脚本。C# 版本需安装 .NET 8 runtime。
148 2
6种方法打造出色的Shell脚本
6种方法打造出色的Shell脚本
142 2
6种方法打造出色的Shell脚本
Linux 如何更改默认 Shell
Linux 如何更改默认 Shell
186 0
Linux 如何更改默认 Shell
|
5月前
|
Shell脚本要点和难点以及具体应用和优缺点介绍
Shell脚本在系统管理和自动化任务中扮演着重要角色。尽管存在调试困难、可读性差等问题,但其简洁高效、易于学习和强大的功能使其在许多场景中不可或缺。通过掌握Shell脚本的基本语法、常用命令和函数,并了解其优缺点,开发者可以编写出高效的脚本来完成各种任务,提高工作效率。希望本文能为您在Shell脚本编写和应用中提供有价值的参考和指导。
206 1

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等