Linux – Bash snippet to move all files in a directory into that directory

bashlinuxunix

I have a directory with lots of files and directories in it. In order to tidy it up, I'm going to put all those files into a directory, so I was going to do something like this:

$ ls | wc -l
123
$ mkdir new_directory
$ mv * ./new_directory

However that obviously won't work because then it'll try to move new_directory into new_directory. Is there some simple way to do what I want in one line without me having to copy and paste all the files and directories in that directory?

Best Answer

Your

mv * ./new_directory
command will actually work; it'll just print a warning that it can't move that directory into itself.