Bash – Inserting Newlines at the Bash Command Prompt

bashlinux

How can I add line breaks to a command at the prompt?

I know that when I copy a multiline command from the internet that has newlines it appears on the command line

$ something
> like
> this

Also I know that you can use \ to insert a newline at the very end of your command

$ like \
> this

But how can I add newlines in the middle of a command that I've already typed out?

For example, given

$ this long command that I want to split over multiple lines

How can I turn it into

$ this long command
> that I want to split
> over multiple lines

So far I've tried:

  • Using ctrl + v to insert a return character – just results in ^M being inserted
  • Typing \ return in the middle of the input (as you would do at the end of a line) – just results in \ being typed and then the command being executed.

Best Answer

Use Ctrl+V followed by Ctrl+J.

This inserts a linefeed character rather than a carriage return (which Ctrl+M or Enter would result in after Ctrl+V).

Related Question