Dev Corner

Software Developer’s Notepad

You can easily split long command line into multiple lines.

How to split long commands on multiple lines on Linux

Add a backslash character at the end of line to tell the Linux shell that the next line continues the current line.

   ls \
     -a

How to split long commands on multiple lines on Windows

Add a ^ character at the end of line to tell the Windows Command Interpreter that the next line continues the current line.

  dir ^
    -s

Discussion
In the Windows Command Prompt the ^ is used to escape the next character on the command line. (Like \ is used in strings.) Characters that need to be used in the command line as they are should have a ^ prefixed to them, hence that’s why it works for the newline.

For reference the characters that need escaping (if specified as command arguments and not within quotes) are: &|()

Add A Comment

You must be logged in to post a comment.