编写脚本,将文件前30个字节删除后另存为一个文件

Author: Bruce Liu Posted on: 2023-06-03 14:09:25 Visited: 184

#!/bin/bash
echo "Please enter the filename:"
read oldfile
echo "Please enter the new filename:"
read newfile
dd if=$oldfile of=$newfile skip=30
echo "File saved as $newfile"

 

 

```
#!/bin/bash
echo "请输入原始文件名和新文件名:"
read original_file new_file
if [ ! -f $original_file ]; then
  echo "原始文件不存在"
  exit
fi
dd if=$original_file of=$new_file bs=1 skip=30
echo "文件已保存为$new_file"
```
注意事项:

1. 在脚本前面加上 `#!/bin/bash` 是告诉系统该脚本使用 bash 解释器执行。

2. 使用 `read` 命令从用户处获取输入的原始文件名和新文件名。

3. 使用 `if` 语句判断原始文件是否存在,如果不存在则输出错误信息并退出脚本。

4. 使用 `dd` 命令将原始文件的前30个字节删除后另存为一个新的文件。

5. 使用 `echo` 命令输出新文件的文件名。

 

 




Tags:


相关主题:

留言信息:

......期待您的留言!


增加留言、提问或者评论,不用注册,匿名提交,你提交的信息经过审核后才会显示:


© 2008-2022 CunYouLu存有录博客 村友录 存游录 鲁ICP备08005943号