- What is the shortcut to allow new lines in linux terminal?
- Edit for a better understanding:
- How to Display Specific Lines of a File in Linux Command Line
- Display specific lines using head and tail commands
- Print a single specific line
- Print specific range of lines
- Use SED to display specific lines
- Use AWK to print specific lines from a file
- How to see more lines in the terminal
- 7 Answers 7
- View full (all) lines in terminal (ubuntu) when using journalctl/systemctl
- 2 Answers 2
- You must log in to answer this question.
- Related
- Hot Network Questions
- Subscribe to RSS
What is the shortcut to allow new lines in linux terminal?
I’m searching for the couple of shortcuts to allow to write multilines commands in the terminal.
I know it exist, I used it many times, but I can’t remberber them, and I don’t find them in google. The behavior it have:
Once in the middle of a line, it will «delete» the right part, and when we press the Enter button, it don’t execute the command, but go to a new line (that start with ‘>’ if I well remember).
When we are done, we press the second shortcut, and it paste the part that where deleted before, and the Enter key behavior come back as the original. (I tought it was something like Ctrl+j / ctrl+f, but it’s not, I also tried many combination but never succeed) Hoping you remember them, you’ll make my day. Thanks!
Edit for a better understanding:
rosservice call /operatorshift/updateProgramSteps "category: '' name: '' steps: - command: '' args: '' othersarg ''"
The steps argument is an array, and I want to provide more than one step, without deleting and rewriting the next lines.
The behavior is as follow:
I move my cursor at the end of the 5th line (args: » [HERE]), and I press the first shortcut. The command would look like:
rosservice call /operatorshift/updateProgramSteps "category: '' name: '' steps: - command: '' args: ''
and I press «enter», not to execute the command, but to add a new line (and the ‘>’ character appear on the left of my cursor, instead of my computer’s name). I can write my other «step», pressing «enter» many time if I want, so my terminal would look like this:
rosservice call /operatorshift/updateProgramSteps "category: '' name: '' steps: - command: '' args: '' > - command: 'example' > args: '' >
Then I’m done editing this command, so I press the second shortcut, that retrieve what the first have deleted, and the «enter» key get its default behavior (execute the command)
rosservice call /operatorshift/updateProgramSteps "category: '' name: '' steps: - command: '' args: '' > - command: 'example' > args: '' othersarg ''"
(not sure that ‘>’ stay on screen after pressing the second shortcut) I remember using it on Ubuntu 14.04, and on 16.04, with the default shell, without having to install a special package.
How to Display Specific Lines of a File in Linux Command Line
Here are several ways to display specific lines of a file in Linux command line.
How do I find the nth line in a file in Linux command line? How do I display line number x to line number y?
In Linux, there are several ways to achieve the same result. Printing specific lines from a file is no exception.
To display the 13th line, you can use a combination of head and tail:
head -13 file_name | tail +13
Or, you can use the sed command:
To display line numbers from 20 to 25, you can combine head and tail commands like this:
head -25 file_name | tail +20
Or, you can use the sed command like this:
A detailed explanation of each command follows next. I’ll also show the use of the awk command for this purpose.
Display specific lines using head and tail commands
This is my favorite way of displaying lines of choice. I find it easier to remember and use.
Print a single specific line
Both head and tails commands are used to display the contents of a file in the terminal.
Use a combination of head and tail command in the following function the line number x:
You can replace x with the line number you want to display. So, let’s say you want to display the 13th line of the file.
[email protected]:~$ head -13 lines.txt | tail +13 This is line number 13
Explanation: You probably already know that the head command gets the lines of a file from the start while the tail command gets the lines from the end.
The “head -x” part of the command will get the first x lines of the files. It will then redirect this output to the tail command. The tail command will display all the lines starting from line number x.
Quite obviously, if you take 13 lines from the top, the lines starting from number 13 to the end will be the 13th line. That’s the logic behind this command.
Print specific range of lines
Now let’s take our combination of head and tail commands to display more than one line.
Say you want to display all the lines from x to y. This includes the xth and yth lines also:
Let’s take a practical example. Suppose you want to print all the the lines from line number 20 to 25:
[email protected]:~$ head -25 lines.txt | tail +20 This is line number 20 This is line number 21 This is line number 22 This is line number 23 This is line number 24 This is line number 25
Use SED to display specific lines
The powerful sed command provides several ways of printing specific lines.
For example, to display the 10th line, you can use sed in the following manner:
The -n suppresses the output while the p command prints specific lines. Read this detailed SED guide to learn and understand it in detail.
To display all the lines from line number x to line number y, use this:
[email protected]:~$ sed -n '3,7p' lines.txt This is line number 3 This is line number 4 This is line number 5 This is line number 6 This is line number 7
Use AWK to print specific lines from a file
The awk command could seem complicated and there is surely a learning curve involved. But like sed, awk is also quite powerful when it comes to editing and manipulating file contents.
[email protected]:~$ awk 'NR==5' lines.txt This is line number 5
NR denotes the ‘current record number’. Please read our detailed AWK command guide for more information.
To display all the lines from x to y, you can use awk command in the following manner:
It follows a syntax that is similar to most programming languages.
I hope this quick article helped you in displaying specific lines of a file in Linux command line. If you know some other trick for this purpose, do share it with the rest of us in the comment section.
How to see more lines in the terminal
I’m installing a package and get a load of errors and need to be able to read through all the error messages that come up. Unfortunately the terminal will only display a finite number of lines. How do I go about viewing previous lines or changing the maximum number of lines that can be displayed?
7 Answers 7
Like David Purdue suggests, I myself too. I like to have unlimited scrolling.
You can also enable the scrollbar if you want; but I prefer it disabled and use Shift + Page Up and Shift + Page Down keys to change the output frames.
sorry @MycrofD can’t say about that, have not tried 1504.. you should check the script command and see if it fits to your needs. This was one of the adviced ones on my simillar post for TTY console terminal askubuntu.com/questions/487133/…
I tried both checking «unlimited» and setting the scrolling to 4096 lines. Neither works; the terminal insists on showing only 30 lines. I’m well aware of redirection, and Vim seems to do the right thing, but sometimes I just want to scroll. What could I be missing?
Is there a way to do it in the terminal? I want to do it on a Docker container and creating new files is unsupported on the Docker image I’m using so being able to scroll up farther instead of dumping the terminal output to a file would be beneficial.
Note that in modern versions of Ubuntu, it’s under Unnamed -> Scrolling -> uncheck «Limit scrollback to:». (Replace «Unnamed» with the name of your profile if you changed it.)
Your Enter key will take you down.
Sadly, this likely won’t work for OP’s «load of errors,» because those errors are likely going to stderr, not stdout, and | redirects only stdout. (I believe your_command 2>&1 | less will work in that case; see unix.stackexchange.com/questions/3514/… for more discussion.)
If you are using the standard Terminal program on a Desktop version of Ubuntu.
- Choose Edit -> Profile Preferences from the terminal windows global menu.
- Choose the Scrolling tab
- Set Scrollback to the desired number of lines (or check the Unlimited box).
Then you can use the scrollbar at the side of the terminal to scroll back through the lengthy command output.
It is in the menu bar for the Terminal program. This usually appears at the top of the screen when Terminal has focus, but you may have to move your mouse to the top of the screen for it to appear.
If you want to see the data and also run it to a file, use tee, e.g,
(spark-shell is just the example interactive program that you might want to capture output from.)
This will allow you to type commands in response to output from the program, but also capture the output to a file.
I recommend you to use output redirection. Type:
user@host:~# command >filename
Then you can read the file with a text editor for example less and browser through the output:
The question is quite specific about not wanting to do that and instead increasing the scroll buffer size
@PeterKionga-Kamau This question has 7 answers, 2 of which suggest increasing scroll buffer size and the other 5 are basically equivalent to my answer. The question is about reading previous lines and the above is one possible solution for that. Sometimes there exist multiple solutions to a problem. Collecting them is one purpose of this site.
You could start your command in a script session every action an command output would be saved without interfering with the execution unless |less or >file that forbid to have any interaction with the command.
$ script /tmp/command.out Script started, file is /tmp/command.out $ the_command . $ exit Script done, file is /tmp/command.out $ less /tmp/command.out
You could use | to output your command into more . For example, if I wanted to read an entire text file that wouldn’t fit on screen using cat , I would use:
cat /home/abcd/Downloads/fileName.txt | more
You can press enter to scroll down one line at a time, and q to exit. Press g to start over.
Hope this could be useful to you.
View full (all) lines in terminal (ubuntu) when using journalctl/systemctl
When I try to view something, in many cases I get a message saying lines X-Y/Y (END) and those are the only lines printed on my terminal. Here is an example from journalctl -xe : I see the same from systemctl -a and things like that. How can I view the remaining text?
That seems like less . Press h to get help or read man less . Using up/down arrows should work, as should PageUp/PageDown,
@choroba can you tell me a bit more? what you mean with less , as it I’ve given the example from journalctl -xe or systemctl -a or like that.
The remaining text? You are already seeing the bottom of the text that you are viewing. Please clarify.
2 Answers 2
I think what you are looking for is an output using —no-pager
You can use same by specifying a service also:
journalctl -u service-name —no-pager
It seems like your system is using less as a pager.
Press h when running less to get help. To learn more, run man less from the terminal.
TL;DR: PageUp , PageDown , ↑ , and ↓ should work in a standard way. q quits less .
You must log in to answer this question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.