[ACCEPTED]-mkdir command for a list of filenames paths-ubuntu
Accepted answer
This can be done in native bash
syntax without 3 any calls to external binaries:
while read line; do mkdir -p "${line%/*}"; done < infile
Or perhaps 2 with a just a single call to mkdir
if you have 1 bash 4.x
mapfile -t arr < infile; mkdir -p "${arr[@]%/*}"
How about...
for p in $(xargs < somefile.txt);
do
mkdir -p $(dirname ${p})
done
0
xargs -n 1 dirname <somefile.txt | xargs mkdir -p
0
It can be done without loop also (provided 1 input file not huge):
mkdir -p $(perl -pe 's#/(?!.*/).*$##' file.txt)
If you have file "file1" with filenames 3 you could try this oneliner:
cat file1 |xargs -I {} dirname "{}"| sort -u | xargs -I{} mkdir -p "{}"
Use of:
xargs -I{} mkdir -p "{}"
ensures 2 that even path names with spaces will be 1 created
Using a perl one-liner and File::Path qw(make_path)
:
perl -MFile::Path=make_path -lne 'make_path $_' dirlist.txt
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.