Anytime I want to move thousands of files to a new folder, I always encounter the same problem.> mkdir my_folder> mv * my_foldermv: cannot move 'my_folder to a subdirectory of itself 'my_folder'While I think that the error above is harmless (is it?) I am wondering if there is a way of avoiding it.In case it matters, I am interested in a solution in zsh or one that works well across various shells.
mv * folder (avoiding 'cannot move' error)
zsh;rename
In zsh, with the extended_glob option enabled, you can use ~ to exclude patterns from globs, so you could use:setopt extended_globmv -- *~my_folder my_folderOr use the negation operator (still with extended_glob):mv -- ^my_folder my_folderUse braces to avoid typing the directory name twice:mv -- {^,}my_folderIn bash (for other answer-seekers using it), you can use Ksh-style extended globs:# If it's not already enabledshopt -s extglobmv -- !(my_folder) my_folderYou can also use that syntax in zsh if you enable the ksh_glob option.