Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I execute simple commands like

cp -pr /scripts/htdocs/sob/summaries/* /scripts/htdocs/sob/

cp -p /scripts/htdocs/sob/summaries/index.php /scripts/htdocs/sob/

rm -R cake.old nbproject

with a single command call?

share|improve this question
up vote 5 down vote accepted

Put the following into

cp -pr /scripts/htdocs/sob/summaries/* /scripts/htdocs/sob/
cp -p /scripts/htdocs/sob/summaries/index.php /scripts/htdocs/sob/
rm -R cake.old nbproject

Then make that file executable:

$ chmod +x

Then run it:

$ ./
share|improve this answer

If you're just copy/pasting this, separate the commands with semicolons.

cp -pr /scripts/htdocs/sob/summaries/* /scripts/htdocs/sob/; cp -p /scripts/htdocs/sob/summaries/index.php /scripts/htdocs/sob/; rm -R cake.old nbproject

Note that the first command you posted will copy the index.php file, so running your second copy directly after that is unnecessary.

share|improve this answer

You can either separate them with semicolons, as the others said, or with double ampersands (&&) like this:

cp -pr /scripts/htdocs/sob/summaries/* /scripts/htdocs/sob/ && cp -p /scripts/htdocs/sob/summaries/index.php /scripts/htdocs/sob/ && rm -R cake.old nbproject

The difference is that with the ampersands each command will be executed only if the previous one completed successfully while with the semicolon all commands will be executed regardless of the previous ones.

share|improve this answer

You should use rsync instead of cp as it's more efficient if any of the files or directories remain the same across runs. rsync also handles things like symlinks and oddities like sparse files better than cp. Use a text editor (pico is fine to start with) and create your ~/ file (this version also has some error checking):

rsync -av /scripts/htdocs/sob/summaries/* /scripts/htdocs/sob/ || \
  { echo "rsync failed" >&2 && exit 1; };
rm -rf /somedir/cake.old /somedir/nbproject || { echo "rm -rf failed" >&2 && exit 1; };

Save that file, and run chmod 755 to make it executable. Then typing ~/ will execute your script.

Note you want to put a absolute directory on that rm -rf command so you don't accidentally blow away the wrong directory in some other location. I also eliminated your second copy since it's covered in the first recursive copy.

rm -rf is a more standard idiom than rm -R. The -f forces removal of files/directories even if the permissions disallow it (but only for files or directories you already own).

share|improve this answer

You can separate them with semi-colons or put them in a script, mark it as executable, and just call the script.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.