linux – 使用“touch”创建目录?

1)在“A”目录中:
find . -type f > a.txt

2)在“B”目录中:

cat a.txt | while read FILENAMES; do touch "$FILENAMES"; done

3)结果:2)“创建文件”[我的意思是只有相同的文件名,但0字节大小]好的.但是如果在“A”目录中有子目录,则2)无法创建子目录中的文件,因为它中没有目录.

问题:有没有办法,那个触摸可以创建目录?

解决方法

由于find line每行输出一个文件
cat a.txt | while read file; do
    if [[ "$file" = */* ]]; then
        mkdir -p "${file%/*}";
    fi;

    touch "$file";
done

编辑:

如果在单独的步骤中创建的目录,这将稍微有效:

cat a.txt | grep / | sed 's|/[^/]*$||' | sort -u | xargs -d $'\n' mkdir -p

cat a.txt | while read file; do
    touch "$file";
done

而且,不,触摸不能自己创建目录.

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...