Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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

share|improve this question

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

sudo touch .htaccess && sudo chmod 766 .htaccess

share|improve this answer
I prefer this solution for two reasons: 1. && is generally better than ; so that it stops if the first command fails, 2. it's generally better to only run the specific program needed with sudo, rather than trying to combine them into a single sudo invocation and running more code with elevated privileges than necessary. – Chris Page Jun 29 '12 at 12:14

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'
share|improve this answer
Good suggestions, but I would revise these to use && instead of ;, though. Also, in general I would just use two sudo commands, because it's overkill and riskier to run an entire shell with elevated privileges, rather than just the exact programs that need to run with them (in this case, touch and chmod). – Chris Page Jun 29 '12 at 12:12
Yes, you are right, it would be better – Igor Chubin Jun 29 '12 at 12:17

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

sudo touch .htaccess; sudo chmod 766 .htaccess

share|improve this answer
That's a good suggestion, though it's a good idea to get into the habit of using && instead of ; when running interdependent commands so that it stops if a command fails. – Chris Page Jun 29 '12 at 12:16

separate the commands with semicolon. (;)


echo firstname; echo lastname;
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .