Reputation: 5755
Say I have a folder with many files and directories (NOT actual filenames, this is like a trash can directory, so the filenames are completely random, and some files are without extension):
dir1/
dir2/
...
dirN/
file1
file2
...
fileM
Now I need to move all the files in this directory into the dir1/
. That is, move file1
, file2
... fileM
into dir1/
. What's the easiest way to do that?
If they are all files with extension then the problem is simple, just mv *.* dir1/
. But I don't know what to do if there are files without extensions.
Upvotes: 0
Views: 1015
Reputation: 780994
One way:
mv $(find * -maxdepth 0 -type f) dir1
Another:
for file in *; do
if [ -f "$file" ]
then mv "$file" dir1
fi
done
Upvotes: -2
Reputation: 3838
Although find
is a good solution, here is another solution using bash only :
for file in *; do [[ -f $file ]] && mv "$file" dir1; done
Upvotes: 1
Reputation: 26545
Bash does not have a direct way to select only regular files. You have to use find
for that.
Maybe zsh
is also an option for you. With zsh
you could simply write
mv *(.) dir1/
Upvotes: 0