Home > Mobile >  BASH: copy all the files of a folder to other folder
BASH: copy all the files of a folder to other folder

Time:11-26

I want to copy notebooks with extension .ipynb from one folder to other. And I am writing my first bash script.sh

CURRENT=${PWD}
cp "$CURRENT/notebooks/*.ipynb" "/home/jovyan/shared/public/whatever"

result:

cp: cannot stat '/home/name/utils/notebooks/*.ipynb': No such file or directory

but '/home/name/utils/notebooks/ EXISTS and it has notebooks.

Where is the error in the command here?

is it possible to build also a command telling "all the notebooks that which name starts by py"

Thanks

CodePudding user response:

You can simply write

cp notebooks/*.ipynb "/home/jovyan/shared/public/whatever"

CodePudding user response:

Quoted globs will not expand.

all the notebooks that which name starts by py

This moves the files to a path in the current home directory:

cp ./notebooks/py*.ipynb ~/shared/public/whatever/

If you need the home directory of one specific user (regardless of who is running the command), you can use:

cp ./notebooks/py*.ipynb ~jovyan/shared/public/whatever/

You may also need full paths:

cp ~/utils/notebooks/py*.ipynb ~/shared/public/whatever/

An explanation of tilde expansion: ~ (unquoted) expands to the home directory of the current user, whilst ~jovyan expands to the home directory of user jovyan, even if you are logged in as a different user. Tilde expansion is a feature of the POSIX shell, and not bash specific.

  • Related