Question

I have a directory which contains bunch of files. Now I want to move these files to another directory one by one and alphabetically. How can I do this in shell? could mv do this?

Was it helpful?

Solution

The glob * orders the file names 'alphabetically', so you could use:

target="/some/other/directory"
for file in *
do
    mv "$file" "$target"
done

It would be quicker to use:

mv * "$target"

and it does move the files one by one, but it does so in a single invocation of the move command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top