I could (1) prepare a file with typed commands separated by end-line, (2) make it executable, (3) run it from a file-system manager or the terminal.

But this is ridiculous for not repeatable and every-time-other sets of commands.

Can I type those commands to the terminal in one request instead?

I don't know end-line character for the terminal - Ctrl, Shift or Alt with Enter doesn't work.  

  • 1
    On a command line, commands can be separated with a semicolon. – John1024 Feb 1 '14 at 2:55

You can separate commands with && or ;.

  • && only runs the next command if the previous one exited with status 0 (was successful) :

    command1 && command2 && command3
  • ; runs every commands, even if the previous one exits with a non zero status :

    command1; command2; command3

You can combine these separators as you wish.

  • 7
    for command1 && command2 command2 will only be executed if command1 is successful. – sourav c. Feb 1 '14 at 3:18
  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/… – gevang Feb 1 '14 at 4:04
  • @souravc : I made an edit, thanks, I learned something. – MrVaykadji Feb 1 '14 at 10:27
  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command? – Koen Jan 6 '19 at 21:09

If you are interested to type each command on its own line in one single request you can use the following method:

  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.

  • Type your commands, each one followed by Enter

  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something else
List current directory contents:
Backups            Desktop           forma3d  Public      Untitled txt.txt~
bin                Documente         Music    Templates   Videos
configuration.php  examples.desktop  passwd~  tmp~
Downloads          file~             Poze     Ubuntu One
Change current directory with root directory:
radu@Radu: / $
  • 1
    if true; then may be clearer to read if so desired. : may be confused with the ; at first glance. – kiri Feb 1 '14 at 10:45

First, put a { on its own line.
Then, insert your commands.
Then, put a } on a new line and press Enter. Your commands will be executed.


echo list
echo of
echo commands
echo to run at once

which will print (all at once, with no prompt in between):

to run at once

As a side note, { .. } is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)

  • Is that the same that if :; then already mentionned ? Or is it slightly different ? – MrVaykadji Feb 1 '14 at 10:38
  • 1
    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. { .. } just groups the commands together. I personally find { .. } easier to remember. – kiri Feb 1 '14 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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