Running Multiline Commands

Learn how to run multiline commands.

We'll cover the following


Let’s look at how we can run multiline commands on the shell. As soon as we press the “Enter” key, the shell executes the command. However, some commands have many options or are just very long and might not fit on our screen, and we’d like to break the command into multiple lines. We can do this by typing the \ character before pressing “Enter.”

In Creating Pipelines of Data, we saw this example, which lets us see the most used commands in our history:

$ history | awk '{c[$2]++}END{for(i in c){print c[i] " " i}}' | sort -rn | head

Breaking the command

We can break this command onto multiple lines by using the \ character, like this:

history \
| awk '{c[$2]++}END{for(i in c){print c[i] " " i}}' \
| sort -rn \
| head

Use the terminal below to practice these commands.

Get hands-on with 1200+ tech skills courses.