The following commands will make your life easier with the terminal.
CTRL + u
Deletes the current line quickly, so you don't have to manually remove chars one by one with your keyboard.
CTRL + z
/ foreground (fg
)
You can "minimize" the window with CTRL + z
(TSTP signal: 'terminal stop') and get it back with fg
:
nano ~/myfile.conf
# CTRL + z
fg # to go back to the edit
It's very handy and removes the hassle of opening a new tab or a new window.
head
head -7 myfile.txt
displays first 7 lines of a file. The command is helpful to quickly get info without opening the whole file.
cd -
You can use cd -
to go back to the previous directory. Simple & easy.
pushd
You can save paths in the terminal for later use with pushd
:
pushd /opt
Behind the scene, pushd
add the path to the top of the directory stack. If you don't specify a directory, it will take the current one.
It's even possible to play with positions:
pushd +3
pushd -4
+
starts from the top whereas -
starts from the bottom.
You can print the directory stack with dirs -l -v
.
popd
popd
allows returning to the path at the top of the directory stack:
pushd /opt
pushd /etc
popd # you'll go to /etc
It also removes this path from the stack. Indeed, the stack follows a LIFO model, so the last data to come in will be the first to come out.
popd
can be used with numbers, just like pushd
to :
popd +3
popd -4
Again, +
starts from the top whereas -
starts from the bottom. Don't forget dirs -l -v
to print the directory stack.
less
less
allows scrolling in files:
less mybigfile.txt
The top of the file is displayed in the terminal window, but you can scroll to go forward and backward through the text.
You can even use the space bar or Page Down key to move forward. Use the Page Up key to move backward.
To exit, just press q
.
N.B.: There are many more options you can use for effective viewing.