Day 41 - Some More Useful Commands

This is the 10th post in the Linux Series and may be the last if I didn't found anymore basic topics to learn that are specific to Linux and this post will be about some more Linux commands which can be useful if you want to be better at Linux.

Run Multiple Commands at Once

This can be very helpful if you want to run more than one command at once but dont want to wait for one command to finish and type the next command so you can just type all the commands and run them all one by one.

Press Ctrl (Control) Button and while pressing it also press X then E button to open an editor. Type commands in this editor press Ctrl+X enter Y and hit enter button twice and it will run all the commands in the file one by one.

root@User:~$ Ctrl+x+e
GNU nano 2.9            /tmp/bash-fc.zcF
echo "Hello From Command One"
echo "Hello From Command Two"
echo "Hello From Command Three"
echo "Hello From Command Four"
# These are all the commands that
# will run after I close the Editor
# by pressing Ctrl+X and type Y and hit
# Enter or Return button twice

root@User:~$
echo "Hello From Command One"
Hello From Command One
echo "Hello From Command Two"
Hello From Command Two
echo "Hello From Command Three"
Hello From Command Three
echo "Hello From Command Four"
Hello From Command Four
root@User:~$

Editing The Last Command

This command is simillar to the last commadn as it will aslo open an editor to write the command but this is used if you wrote a lenghty command and something in it was wrong and you have to change something in it.

To use it type fc after the the command you want to edit and it will open an editor which will let you chage it the way you want.

Navigating A File

Seeing the contents of a file to read it can be done with cat command but it will print out all the lines in the file which can be hard to navigate in the terminal so for this most the devs use less command. less command with the file name in front of it will open a file navigator which will help you read the file while scrolling up and down with the arrow keys.

Checking History Of Used Commands

To check what commands have been used in the current session of the terminal just type history command and it will print out the previous commands from the session.

root@User:~$ echo "One"
One
root@User:~$ touch file.txt
root@User:~$ history
echo "One"
touch file.txt

Avoid Getting A Command In History

To avoid getting a command getting recorded in the terminal session history, Add a single space before typing the command.

root@User:~$ echo "One"
One
root@User:~$ touch file.txt
root@User:~$ history
echo "One"
touch file.txt
root@User:~$  echo "Hidden"
Hidden
root@User:~$ history
echo "One"
touch file.txt

Making Multiple Directories

To make multiple directories with a single command just type the already know mkdir command with number of folders from starting number to finish number separated by two dots inside curly braces just like the following and it will create that many folders.

root@User:/tmp/temp$ mkdir {1..10}
root@User:/tmp/temp$ ls
1   10  2   3   4   5   6   7   8   9

Shutting Down System

This one may not seem useful at first because you can just click a button and it will shutdown your system but when you are getting used to a keyboard, going from keyboard to the mouse to click seems more difficult than just typing shutdown.


zainscizainsci