DEV Community

pO0q 🦄
pO0q 🦄

Posted on • Updated on

Next-level Commands for the terminal

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

+ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (2)

Collapse
 
goodevilgenius profile image
Dan Jones • Edited

Ctrl-z doesn't background an app. It suspends it, so that it actually stops doing anything.

If you want to background it, after Ctrl-z, you have to do bg to resume it in the background.

Collapse
 
po0q profile image
pO0q 🦄 • Edited

You're right. My wording was terrible.