Posts tagged: mkdir

Move a file to a subdirectory of the same name

comments Comments Off on Move a file to a subdirectory of the same name
By , Tuesday 30th October 2012 1:15 pm

A quick bash one liner to create and move a set of files in a directory to a sub-directory of the same name:


IFS=$'\n'; for i in `find . -maxdepth 1 -type f`; do echo "$i"; dir=${i%.*}; \
echo "$dir"; mkdir "./$dir"; mv "./$i" ./"$dir"/; done;

If you know a better way please post in the comments :)

Panorama Theme by Themocracy

3 visitors online now
1 guests, 2 bots, 0 members
Max visitors today: 13 at 06:05 am UTC
This month: 16 at 18-07-2017 05:35 pm UTC
This year: 45 at 02-01-2017 10:28 pm UTC
All time: 130 at 28-03-2011 10:40 pm UTC