Anz Anz - 5 months ago 9
Linux Question

How to move all the type file file1.ext, .file2ext and .anotherext from folder to another folder with linux (debian) command line?

I use the following command to move all files from one folder to another. In this case I move a file from folder1 to folder2 as the following command:

# mv -v /path2dir/subdir/folder1/* /var/www/folder2

Of course folder2 been made before.
The problem is not all the files moved successfully, some files like .file2ext , .anotherext or files starting with character (.) like .htaccess and .error_log not succeed on the move

how to resolve this issue?

Thanks in advance...


Bash offers a more flexible way to specify path tokens:

mv -v /path2dir/subdir/folder1/{.*,*} /var/www/folder2

Inside curly brackets you can specify a comma separated list of tokens. The shell will expend them by iterating over them, so handling all matches of all of them.

A shorter, but otherwise equivalent alternative is this:

mv -v /path2dir/subdir/folder1/{.,}* /var/www/folder2

Both alternatives will give you a warning about entries that will be skipped due to good reasons (. and ..). You can suppress those by redirecting the error output of the command, but you should be careful with such thing, since you might miss important details that way:

mv -v /path2dir/subdir/folder1/{.,}* /var/www/folder2 2>/dev/null