有些时间没发表文章了,之前用到过,这是我总结出来关于ftp相关操作一些方法,网上也有很多,但是没有那么全面,我的这些仅供参考和借鉴,希望能够帮助到大家,代码和相关引用我都复制粘贴出来了,希望大家喜欢 using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net;using System.Text.RegularExpressions; namespa
本文需要实现的功能如下:某文件夹下具有由按数字编号命名的文件夹,需要删除除最大编码外的文件. 具体实现 大致思路:循环遍历该文件夹下所有文件,正则匹配出最大编码文件:然后循环文件,删除除最大编码外的文件. 实现代码如下: #!/bin/bash function getdir(){ max= DATEPATTERN="^[0-9]*$" ` do if [[ "$element" =~ $DATEPATTERN ]] then ] then max=$element
1.通过位置变量创建linux系统账户及密码 $1 是执行脚本的第一个参数,$2 是执行脚本的第二个参数 #!/bin/bash #创建用户与密码 declare -i c=0 if [ -z $1 ] || [ -z $2 ];then echo "请输入用户名和密码!" fi for i in $(cat /etc/passwd|cut -d: -f1);do if [ $1 == $i ];then let c=1 fi done if [ $c -ne 1 ];then use
一.if else if 语法格式 if condition then command1 command2 ... commandN fi 写成一行(适用于终端命令提示符): if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi 末尾的fi就是if倒过来拼写,后面还会遇到类似的. if else 语法格式 if condition then command1 command2 ... command
Shell也使用 break 和 continue 来跳出循环. break命令 下面的例子中,脚本进入死循环直至用户输入数字大于5,使用break跳出这个循环. #!/bin/bash while : do echo -n "Input a number between 1 to 5: " read aNum case $aNum in ||||) echo "Your number is $aNum!" ;; *) echo "You do not s