combining commands on the terminal on Mac OS X

I would like to write the following on one line in the terminal or if there is a shorter way to create a file and set the permissions then please do comment.

sudo touch .htaccess
sudo chmod 766 .htaccess

Much appreciated


Solution 1:

Use '&&' to conditionally run the second command if the first is successful.

sudo touch .htaccess && sudo chmod 766 .htaccess

Solution 2:

Semicolons will let you fit multiple commands on a single line like this:

sudo touch .htaccess; sudo chmod 766 .htaccess

Solution 3:

No, it is not.

The only thing you can make, you can combine these two commands within one sudo:

sudo sh -c 'touch .htaccess && chmod 766 .htaccess'

Another solution (witho ony one external call, but also with two commands):

sudo sh -c 'umask 011 && touch .htaccess'