构建一个shell脚本,可以读取文件夹内的文件名,并且在一个新的路径下生成同名文件夹
时间: 2023-02-08 14:25:14 浏览: 101
以下是一个示例 shell 脚本,它可以读取文件夹内的文件名,并在一个新的路径下生成同名文件夹:
```
#!/bin/bash
# 源文件夹路径
src_dir="/path/to/src"
# 目标文件夹路径
dst_dir="/path/to/dst"
# 遍历源文件夹内的文件夹
for dir in $(ls $src_dir)
do
# 在目标路径下创建同名文件夹
mkdir -p "$dst_dir/$dir"
done
```
需要注意的是,在上面的代码中,请替换"/path/to/src" 和 "/path/to/dst" 为您自己的源文件夹和目标文件夹路径。
相关问题
用shell脚本写一个用户输入文件夹路径,自动将文件名小写
#!/bin/bash
# 提示用户输入文件夹路径
echo "请输入文件夹路径:"
read folder_path
# 判断文件夹是否存在
if [ ! -d "$folder_path" ]; then
echo "文件夹不存在,请重新输入路径!"
exit 1
fi
# 将文件名转为小写
cd "$folder_path"
for file in *
do
if [ -f "$file" ]; then
mv "$file" "$(echo "$file" | tr '[A-Z]' '[a-z]')"
fi
done
echo "文件名已经全部转换为小写!"
shell脚本调用文件夹下另外一个shell脚本
要调用文件夹下的另一个shell脚本,可以使用以下命令:
```
sh /path/to/another_script.sh
```
其中,`/path/to/another_script.sh`是另一个脚本的路径。
如果当前目录下有另一个脚本,可以使用相对路径:
```
sh ./another_script.sh
```