如何使用dir $ n创建文件夹?

问题描述 投票:0回答:2

我正在创建文件夹并从Downloads文件夹中复制一些内容。我的问题是我想移动下载文件夹的内容而不是文件夹本身。所以我正在尝试这个

n=0
while ! mkdir dir$n
do
    n=$((n+1))

find /home/linaro/Downloads 1 -type f -exec mv -t /home/linaro/dir$n

done

错误就是这样

mkdir: cannot create directory ‘dir0’: File exists
find: ‘/home/linaro/Downloads’: No such file or directory
mv: missing file operand
Try 'mv --help' for more information.
mkdir: cannot create directory ‘dir1’: File exists
find: ‘/home/linaro/Downloads’: No such file or directory
mv: missing file operand
Try 'mv --help' for more information.
mkdir: cannot create directory ‘dir2’: File exists
find: ‘/home/linaro/Downloads’: No such file or directory
mv: failed to access '/home/linaro/dir3': No such file or directory
linaro@tinkerboard:~$

实际上命令无法检测新创建的文件夹(动态名称为dir $ n)。我试图访问上一个文件夹。但没有任何效果。如何工作?

bash
2个回答
0
投票

要从Downloads目录中复制所有文件/ Dirs吗?如果是这种情况,您使用下面的代码,

DirName=`date "+%Y-%m-%d-%H:%M:%S"`
mkdir $DirName
mv ~/Downloads/* ~/$DirName

0
投票

你很亲密,但我不确定1跟随你的/home/linaro/Downloads是什么。看来你真的想要:

find /home/linaro/Downloads -type f -exec mv '{}' /home/linaro/dir$n \;

虽然你可以合法地写dir$n,如果你写的是dir${n},它会更清楚,

find /home/linaro/Downloads -type f -exec mv '{}' /home/linaro/dir${n} \;

尝试一下,如果您有任何其他问题,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.