📜 ⬆️ ⬇️

How to copy files and folders in linux console excluding some of them by regular expression

Hello.

Do not judge strictly, I am new to linux and this is my first post on Habré, but maybe someone like me will find it useful.

Faced with the need to solve the problem described in the title. I did not find a ready solution. I wrote a sh script (cpexclude.sh), which first copies everything and then deletes the extra:
')
#!/bin/bash if [ $# -lt 3 ] ; then echo "cpexclude usage: pathFrom pathTo excludeRegex" exit 0 fi pathFrom=$1 pathTo=$2 excludeRegex=$3 # Copy everything echo `cp -a $pathFrom/. $pathTo` # Delete by excludeRegex echo `find $pathTo -regex $excludeRegex -delete` 

Added it to ~ / .bashrc

 alias cpexclude='/path/to/cpexclude.sh' 

I use from time to time.
If anyone has a more acceptable solution on his mind, you are welcome.

Upd. I did not fully describe the task. There is also a need to preserve the structure of the subdirectories of the copied directory and that the subdirectories themselves be copied, and not just the files in them.

Upd2. The comments suggested:

Source: https://habr.com/ru/post/150813/


All Articles