Move and Copy Files and Folders with Bash

InstructorCameron Nokes

Share this video with your friends

Send Tweet

In this lesson we’ll learn how to move and rename files (mv) and copy (cp) them.

Vitaly K.
Vitaly K.
~ 2 years ago

I'm not sure what's the default behaviour on MacOS for the mv / cp wildcards, but on the Ubuntu (I believe Linux systems in general) and Git bash on Windows (that comes with mv and cp tools) dot files (.editorconfig, .stylelint, etc.) will not be copied with cp lib/* src command as well as they won't be moved with the same mv command, at least by default.

You can enable dot files to be matched against wildcard * with the following command: shopt -s dotglob - it will turn the dotglob option allowing * to grab the dot files and the regular files at the same time.

Shaul Fridman
Shaul Fridman
~ 2 years ago

You said that you must put the full name of the target file with mv\cp. On my mac you don't. you can just 'mv some.txt src' and it will move it to 'src' folder.

Cameron Nokes
Cameron Nokes(instructor)
~ 2 years ago

Thanks Shaul, you're right, sorry for the inaccuracy -- that's like my greatest fear 😱. I'll look into fixing it.

Shaul Fridman
Shaul Fridman
~ 2 years ago

Anyway, it's a great course man :-) I wanted for a long time to get to know bash, and its a clear and simple way to start for me.

Cameron Nokes
Cameron Nokes(instructor)
~ 2 years ago

Thanks Shaul! ❤️

Andy Hu
Andy Hu
~ 2 years ago

Thanks for the great course! One thing I found a bit confusing is the cp -R src/* lib/ part. Looks like we don't need the -R flag to copy every file from src to lib, and if we do something like cp -R src lib then we also copied all the files from src to lib, so I think it may be clearer if you provided both two sample commands here.