问题
i have downloaded several pdf files(with various names) and stored them in a specific directory (for example, Downloads/directory1
).
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.
for example, for a file named maths.pdf
, i want to create the folder maths
and store the pdf in it.
i made several attempts creating a script using commands as basename
and for
, but i didn't have any luck.
回答1:
You can do:
Assuming you're getting:
filename='Downloads/directory1/math.pdf'
f="${filename##*/}"
dir="${f%.*}"
mkdir -p "$dir"
will create math
directory
回答2:
try with:
cd Downloads/directory1
for f in *.pdf; do
fname=${echo $f | sed "s/.pdf//" }
echo "Creating directory [$fname]"
mkdir "$fname"
done
来源:https://stackoverflow.com/questions/19633452/create-multiple-folders-using-existing-file-names-in-linux