I have a folder A which has files and directories, I want to move all those files and directories to another folder B, except file, file2, directory, and directory2.
How can this be done?
I have a folder A which has files and directories, I want to move all those files and directories to another folder B, except file, file2, directory, and directory2.
How can this be done?
With zsh:
setopt extendedglob # best in ~/.zshrc
mv A/^(file|directory)(|2)(D) B/
(the (D) to include dot (hidden) files).
With bash:
shopt -s extglob dotglob failglob
mv A/!(@(file|directory)?(2)) B/
With ksh93
(FIGNORE='@(.|..|@(file|directory)?(2))'; mv A/* B)
what i usually do
cd A
ls > a
(assuming you have no 'a' file).
vi a
remove whatever file or directory to be kept in place.
mv $(<a) B
You can use find with excluded expressions:
find . ! -name . -prune ! -path ./file \
! -path ./file2 \
! -path ./directory \
! -path ./directory2 \
-exec mv {} your_destination \;
This solution is inspired by this question.
If ./A and ./B are on the same filesystem and if these files do not already exist in ./B:
file file2 directory directory2
...then this operation should just be atomic:
cd ./A; mv * ../B
for mv in file file2 directory directory2
do mv ../B/"$mv" .
done
If they are not, then there are at least 8 additional cross-device copies done with the above set of commands.
$ sudo mv (source folder name) A B(destination foldername)
ex: create empty dir some sub folder a 1)sudo mkdir -p A/{b/{a,b,c},c,d}
2)ls A/
b c d
3) sudo mkdir B
5)sudo mv a(folder) b(folder)