shell script Move and Copy

2019-09-15 09:01发布

I have a folder named rules in

/srv/www/htdocs/downloads

and I have another folder with the same name rules in here:

/srv/www/htdocs/didebansnort/core/snort/

I want to copy the folder rules in upper one to the second path

Also I want to know what is the syntax for moving?

2条回答
一夜七次
2楼-- · 2019-09-15 09:16

the same that you use when you copy/move things in shell. That's why they called shell scripts:)

Copying (from -> to)

cp -r /srv/www/htdocs/downloads/rules /srv/www/htdocs/didebansnort/core/snort/rules

we use cp -r to copy directory (r stands for recursive) and simple cp for copying of a single file.

Moving (from -> to)

mv /srv/www/htdocs/downloads/rules /srv/www/htdocs/didebansnort/core/snort/rules

This is for nix/mac/cygwin

P.S. While in the shell you can simply type in this to get a complete manual:

man command_name
查看更多
地球回转人心会变
3楼-- · 2019-09-15 09:16

If the directory /srv/www/htdocs/didebansnort/core/snort/rules is not empty you cannot just move /srv/www/htdocs/downloads/rules to /srv/www/htdocs/didebansnort/core/snort. You'll either need to delete the existing directory or devise some merging strategy. Fore example, copying over cp -r /srv/www/htdocs/downloads/rules /srv/www/htdocs/didebansnort/core/snort/rules (as nix showed) will result in overwriting all duplicate files.

查看更多
登录 后发表回答