本文介绍了在Linux中使用现有文件名创建多个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经下载了几个具有不同名称的pdf文件,并将它们存储在特定目录中(例如,Downloads/directory1
).
i have downloaded several pdf files(with various names) and stored them in a specific directory (for example, Downloads/directory1
).
我想使用原始文件的名称创建文件夹,以将这些文件存储在同一目录下,但不带pdf扩展名.
i would like to create folders to store these files under the same directory, using the names of the original files, but without the extension pdf.
例如,对于名为maths.pdf
的文件,我想创建文件夹maths
并将pdf存储在其中.
for example, for a file named maths.pdf
, i want to create the folder maths
and store the pdf in it.
我曾尝试使用basename
和for
命令创建脚本,但是我没有任何运气.
i made several attempts creating a script using commands as basename
and for
, but i didn't have any luck.
推荐答案
尝试使用:
cd Downloads/directory1
for f in *.pdf; do
fname=${echo $f | sed "s/.pdf//" }
echo "Creating directory [$fname]"
mkdir "$fname"
done
这篇关于在Linux中使用现有文件名创建多个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!