shell script Move and Copy

2019-09-15 08:55发布

问题:

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?

回答1:

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


回答2:

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.