How can I move files from multiple subdirectories into their parent directory?

0
0
Asked By CleverTurtle27 On

I'm trying to move files from various 'docs' directories located inside a main 'DOCS' directory. For example, I want to move all the files from ~/DOCS/docs/* into ~/DOCS/* and then delete the now-empty 'docs' folder. I have over 1000 of these directories, each with different names, and some directories shouldn't change. Sorry if I'm being unclear!

2 Answers

Answered By BashWhiz15 On

If your 'docs' folder only contains regular files, you could simply run:

`mv $HOME/DOCS/docs/* $HOME/DOCS/ && rmdir $HOME/DOCS/docs`

But, if there are hidden files (like `.env` or `.gitignore`), try using:

`shopt -s dotglob nullglob && mv $HOME/DOCS/docs/* $HOME/DOCS/ && rmdir $HOME/DOCS/docs`

Just to note, `shopt` is specific to Bash and if you're using zsh, you'd type `mv $HOME/DOCS/docs/{*,.*} $HOME/DOCS/` to grab hidden files as well, but make sure to exclude `.` and `..`.

Answered By TechieGuru01 On

It sounds like you want to use the `mv` command. You can do it like this:

`mv -r ~/DOCS/docs/ ~/DOCS/`

Just remember that `mv` stands for move and `-r` means recursive, so it'll handle everything inside 'docs' and any subdirectories. This should work for your case!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.