cd /media/movies
for dir in */
do
mkdir "/tmp/movies/$dir"
done
Or on one line:
cd /media/movies && for dir in */; do mkdir "/tmp/movies/$dir"; done
Question
I want to list all folders from /media/movies
and create folders with the same name in /tmp/movies
The following snippet works fine for me except for names with spaces, not sure how to quote here
mkdir /tmp/movies
cd /tmp/movies/
ls -1 -d /media/share/*/ | xargs mkdir
In the names are also parentheses (
and )
and single qutes '
You're Next (2011) (tt1853739)
Solution
cd /media/movies
for dir in */
do
mkdir "/tmp/movies/$dir"
done
Or on one line:
cd /media/movies && for dir in */; do mkdir "/tmp/movies/$dir"; done
OTHER TIPS
This should work:
find /media/movies -maxdepth 1 -type d -exec bash -c "mkdir /tmp/\"$(basename {})\"" \;
If you have still quoting issues try this:
find /media/movies -maxdepth 1 -type d -printf "%f" -exec mkdir "/tmp/{}" \;
You can use the -I
option in xargs
to set exactly where the output from ls -1
occurs. Then you can put the output inside quotes so that names with spaces are treated as a single word. Try this:
ls -1 /media/share/ | xargs -I % mkdir "%"