1.根据txt的文本 批量创建文件夹和创建文件

[root@localhost tmp]# cat name.txt
Jacquelyn 杰奎琳
Leilani 莉兰妮
Fiona 菲奥娜
Kelly 凯利
Larissa 兰瑞莎
Karen 卡伦
Irene 艾琳
Caiden 凯登
....
#脚本编写
#创建文件夹#!/bin/bash
for dir in `cat name.txt | awk '{print $1}'`
domkdir /tmp/$dir
done
[root@localhost tmp]# sh -x mkdir.sh  #sh -x 可以查看脚本的执行过程
++ cat name.txt
++ awk '{print $1}'
+ for dir in '`cat name.txt | awk '\''{print $1}'\''`'
+ mkdir /tmp/Jacquelyn
+ for dir in '`cat name.txt | awk '\''{print $1}'\''`'
+ mkdir /tmp/Leilani
+ for dir in '`cat name.txt | awk '\''{print $1}'\''`'
+ mkdir /tmp/Fiona
.....root@localhost tmp]# ll
总用量 8
drwxr-xr-x 2 root root   6 6月  18 15:21 Aidan
drwxr-xr-x 2 root root   6 6月  18 15:21 Albert
drwxr-xr-x 2 root root   6 6月  18 15:21 Alfredo
drwxr-xr-x 2 root root   6 6月  18 15:21 Caiden
drwxr-xr-x 2 root root   6 6月  18 15:21 Chelsea
drwxr-xr-x 2 root root   6 6月  18 15:21 Destiny
.....
#创建文件#!/bin/bash
for file in `cat name.txt | awk '{print $2}'`
dotouch /tmp/${file}-student.txt
done
[root@localhost tmp]# sh -x touch.sh
++ cat name.txt
++ awk '{print $2}'
+ for file in '`cat name.txt | awk '\''{print $2}'\''`'
+ touch /tmp/杰奎琳-student.txt
+ for file in '`cat name.txt | awk '\''{print $2}'\''`'
+ touch /tmp/莉兰妮-student.txt
+ for file in '`cat name.txt | awk '\''{print $2}'\''`'
+ touch /tmp/菲奥娜-student.txt
+ for file in '`cat name.txt | awk '\''{print $2}'\''`'
+ touch /tmp/凯利-student.txt
+ for file in '`cat name.txt | awk '\''{print $2}'\''`'
+ touch /tmp/兰瑞莎-student.txt
.....[root@localhost tmp]# ll
总用量 12
-rw-r--r-- 1 root root   0 6月  18 15:47 阿尔弗雷多-student.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾伯特-student.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾登-student.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾琳-student.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 黛丝缇妮-student.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 菲奥娜-student.txt

2.批量修改文件名

将上面所有的student修改为teacher

#脚本实现将所有的student替换为teacher
#!/bin/bash
for file in `ls *s*.txt`
domv $file ${file/student/teacher}
done
[root@localhost tmp]# sh -x change-name.sh
++ ls 阿尔弗雷多-student.txt 艾伯特-student.txt 艾登-student.txt 艾琳-student.txt 黛丝缇妮-student.txt 菲奥娜-student.txt 哈丽特-student.txt....
+ for file in '`ls *s*.txt`'
+ mv 阿尔弗雷多-student.txt 阿尔弗雷多-teacher.txt
+ for file in '`ls *s*.txt`'
+ mv 艾伯特-student.txt 艾伯特-teacher.txt
+ for file in '`ls *s*.txt`'
+ mv 艾登-student.txt 艾登-teacher.txt
+ for file in '`ls *s*.txt`'
+ mv 艾琳-student.txt 艾琳-teacher.txt
+ for file in '`ls *s*.txt`'
+ mv 黛丝缇妮-student.txt 黛丝缇妮-teacher.txt
.....[root@localhost tmp]# ll
总用量 16
-rw-r--r-- 1 root root   0 6月  18 15:47 阿尔弗雷多-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾伯特-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾登-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 艾琳-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 黛丝缇妮-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 菲奥娜-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 哈丽特-teacher.txt
-rw-r--r-- 1 root root   0 6月  18 15:47 杰奎琳-teacher.txt
.....

修改文件后缀名

#修改后缀txt为docx
#!/bin/bash
for ed in `ls *.txt`
domv ${ed} ${ed/.txt/.docx}
done
[root@localhost tmp]# sh -x houzui.sh
++ ls name.txt 阿尔弗雷多-teacher.txt 艾伯特-teacher.txt 艾登-teacher.txt 艾琳-teacher.txt 黛丝缇妮-teacher.txt 菲奥娜-teacher.txt 哈丽特-teacher.txt.....
+ for ed in '`ls *.txt`'
+ mv name.txt name.docx
+ for ed in '`ls *.txt`'
+ mv 阿尔弗雷多-teacher.txt 阿尔弗雷多-teacher.docx
+ for ed in '`ls *.txt`'
+ mv 艾伯特-teacher.txt 艾伯特-teacher.docx
+ for ed in '`ls *.txt`'
+ mv 艾登-teacher.txt 艾登-teacher.docx
+ for ed in '`ls *.txt`'
+ mv 艾琳-teacher.txt 艾琳-teacher.docx
+ for ed in '`ls *.txt`'
+ mv 黛丝缇妮-teacher.txt 黛丝缇妮-teacher.docx
...[root@localhost tmp]# ll
总用量 20
-rw-r--r-- 1 root root   0 6月  18 15:47 阿尔弗雷多-teacher.docx
-rw-r--r-- 1 root root   0 6月  18 15:47 艾伯特-teacher.docx
-rw-r--r-- 1 root root   0 6月  18 15:47 艾登-teacher.docx
-rw-r--r-- 1 root root   0 6月  18 15:47 艾琳-teacher.docx
-rw-r--r-- 1 root root   0 6月  18 15:47 黛丝缇妮-teacher.docx
...
#!/bin/bash
#([0-9]{1,3}\.){3}[0-9]{1,3}
filename=/tmp/sshtest/ssh-deny.txt
ip=$(cat secure.txt | grep Failed | awk '{print $11}' | sort | uniq -c | sort -n | awk '$1>2{print $2}')for i in `echo $ip`docat $filename | grep $i >/dev/nullif [ $? -ne 0 ];thensed -i "/no/a $i is deny" $filenameelseecho "已经拉黑了!"exitfi
done
#!/bin/bash
#file=/var/log/secure
file=/tmp/666/secure
destfile=/etc/hosts.deny#ipaddr=$(tail -100 ${file} | grep "Failed password for invalid" | awk '{print $13}' | sort | uniq -c | sort -n | awk '$1>20{print $2}')
ipaddr=$(cat ${file} | grep "^May" | grep "Failed password for invalid" | awk '{print $13}' | sort | uniq -c | sort -n | awk '$1>20{print $2}')for i in `echo "${ipaddr}"`
docat ${destfile} | grep ${i} >/dev/nullif [[ $? -ne 0 ]]; thenecho "sshd:${i}:deny" >> ${destfile}elseecho "已经拉黑了!"fi
done

for循环 shell批量修改文件名,创建文件相关推荐

  1. 可以批量修改文件名、文件后缀的实用工具

    本篇文章主要讲解,批量修改文件名.文件后缀的实用工具操作方法 作者:任聪聪 批量修改文件名称工具 下载地址:https://download.csdn.net/download/hj960511/70 ...

  2. shell 批量修改文件名

    shell 批量修改文件名 tags: 任务 文章目录 shell 批量修改文件名 1. 添加 2. 修改 3. 删除 1. 添加 $ ls file1 file2 file3 file4 $ cat ...

  3. power shell 批量修改文件名

    power shell 批量修改文件名 # 替换 ls | Rename-Item -NewName {$_.name -replace 'trip',''} # 截取名称 ls | Rename-I ...

  4. linux shell中怎样批量修改文件名为 文件夹_文件名

    如何将 多个目录下的文件 批量修改文件名 比如 abc目录下的test1.txt,text2.txt ... 修改为 abc_test.txt abc_test2.txt ... def目录下的tes ...

  5. 用shell批量修改文件名

    在一个文件夹中如果文件名有固定形式,而希望实现批量修改文件名时,可以使用shell脚本 代码如下 将文件名中的a替换成b for i in *.txt; do mv $i  `echo $i | se ...

  6. Python批量修改文件名,文件再多也只要一秒,省时又不闹心

    前言 嗨喽!大家好,这里是魔王 对于电脑中的文件夹啊,我们那是新建一个又一个啊,有时候,我们整理资料的时候就会发现,文件夹那是一个杂乱无章, 一个一个的去修改太浪费时间,咋今天就来分享一个小技巧:批量 ...

  7. shell 批量修改多个文件中的内容

    文章目录 前言 场景 ==备注== 最新脚本 操作如下 思路: 第一个版本: 第二版本: 参考文献 小结 前言 现在会议很多都是双盲评,然而又需要上传材料/实验结果,这时候需要把材料中和自己名字相关的 ...

  8. 批量修改文件名,文件更名软件REN软件

    说明: 两个批处理文件: 1.批量删除当前文件夹内所有文件名中的空格. 2.在当前文件夹内,批量在文件名前加上字条"ABC",你想增加其它字条,更换ABC即 可,或把ABC移到原文 ...

  9. 批量修改文件名,文件名称是小写字母如何一键转换为大写字母

    怎么批量将文件名称修改为大写?假如现在有大量文件,这些文件的名称为小写字母,现在需要将所有文件中的小写字母改为大写字母,你会使用什么方法?很多小伙伴可能不知道该如何操作,小编今天就来分享操作方法,感兴 ...

最新文章

  1. 卡巴绿杀6 By Moshow魔手
  2. 公文字体字号标准2020_一文了解公文格式规范,图文并茂(建议收藏备用)
  3. 上下文信息 RpcContext
  4. SpringMvc三大组件详解
  5. VirtualBox复制虚拟机
  6. 对于模拟交易所引发的思考
  7. sqlmap教程(burpsuit辅助)
  8. 发票查验系统帮你轻松解决发票管理各种问题
  9. 爆肝一周,用Python在物联网设备上写了个智能语音助手-阿里云智能对话机器人
  10. 微信小程序中的常用布局方式(总结)
  11. Google Chrome OS
  12. Win10(winser2019)关闭驱动数字签名方法
  13. 数据可视化:基本图表
  14. 实战开发支付SDK —— 对接微信支付看这一篇文章就够啦(含源码)
  15. 【UI界面设计】PS基础学习笔记
  16. ICPC 沈阳M - United in Stormwind SOSDP+FWT+容斥
  17. 简单python数据分析项目实例-入门Python数据分析最好的实战项目(一)
  18. 嵌入式设计,硬件和软件哪个重要?
  19. java错误代码1061_异常求解 小白
  20. 的确,Java存在缺陷。但是……

热门文章

  1. 互联网金融的前世、今生和未来-系列二(前世):金融与技术的首次亲密接触之金融电子化...
  2. matlab 表示可整除,matlab 判断可以被2整除
  3. Html+css+js实现放大镜功能(详细完整代码)
  4. 相机和livox激光雷达外参标定:ROS功能包---livox_camera_lidar_calibration 使用方法
  5. Contextual Related Posts插件不起作用
  6. 中国PCTG行业研究与投资前景报告(2021版)
  7. 电脑主机启动,鼠标、键盘指示灯均有亮,屏幕显示无信号输入
  8. 将高程图导入Unity生成真实地形教程
  9. Python中的shelve模块
  10. 百度地图sdk---地图定位功能的错误has leaked ServiceConnection com.baidu.location.LocationClient