DEV Community

Cover image for Useful Linux Command Line Tricks and commands
PRUTHVIRAJ SONAWANE
PRUTHVIRAJ SONAWANE

Posted on • Updated on

Useful Linux Command Line Tricks and commands

When I first started using Linux and, I was using Ubuntu with Graphical User Interface, Using
GUI I see Linux same as windows OS. but when I jump to the use of the Linux terminal, I truly hated the Linux
Terminal, because there is no option to click on icons and use them. and remembering the all
required commands and proper use is hard. With the practice, I realized the flexibility and
usability of command. Today, I would like to share some useful tricks and commands with you

Show the previous command or execute them

Most of the time you will need to execute previous commands again and again, while you can
press the Up-Down arrow keys to find relevant command instead of using arrow keys us history
command.

# history
Enter fullscreen mode Exit fullscreen mode

As you will see the last executed commands with numbers, so we just need to execute the
command with the given number

!#
Enter fullscreen mode Exit fullscreen mode

for example

!1
Enter fullscreen mode Exit fullscreen mode
Where # should be replaced with the actual number of common that we want to execute.
Enter fullscreen mode Exit fullscreen mode

Show the Information of Users

many times we need to check the available users on the server/system using the following
a simple command we can get the basic details of all available users.

# lslogins
Enter fullscreen mode Exit fullscreen mode

Copy Console/Terminal Output into the text file

Some time while executing some command it generates a long trail of output in that case we can
copy all generated output on terminal store into the text files. even using the tee command we
can store the operational output into the files.

# tee [options] ... [file]
Enter fullscreen mode Exit fullscreen mode

for example

# sudo apt update | tee update.txt
Enter fullscreen mode Exit fullscreen mode

SSH to the remote Servers

While working on the different servers the SSH performs a major role in the IT department. I
would share the simplest way to configure SSH and login to the Server using SSH. follow the
following steps.

Step 1: Generate the Key

# ssh-keygen
Enter fullscreen mode Exit fullscreen mode

Step 2: Copy the Key to the Server

# ssh-copy-id username@Server-IP
Enter fullscreen mode Exit fullscreen mode

Step 3: login from the Client to Server

# ssh username@Server-IP
OR
ssh -l username server-IP
OR
ssh username@Server-IP -p port
Enter fullscreen mode Exit fullscreen mode
The -p port option for if ssh is not configured on default (22) port.
Enter fullscreen mode Exit fullscreen mode

Rollback Updates and Patches

As the working of a System administrator or use of Linux in Daily uses we have to update the
Linux and some packages. But sometimes the updated packages have compatibility issues, so
in that case, we need to downgrade the package version on downgrade the update, I would
share the following steps to roll back the updates and patches.

Rollback the Package

  • Install a Package or Patches
# yum install git
validate the installed git version
# git --version
Enter fullscreen mode Exit fullscreen mode
  • Check the Yum package history
# yum history
Enter fullscreen mode Exit fullscreen mode
  • Rollback the install package
# yum history undo <ID>
example
# yum history undo 2
the package will be removed
Enter fullscreen mode Exit fullscreen mode

Rollback the Updates

  • Install a Package or Patches
# yum update
Enter fullscreen mode Exit fullscreen mode
  • Check the yum History
# yum history
Enter fullscreen mode Exit fullscreen mode

Rollback the Updates

# yum history undo <ID>
# yum history undo 1
Enter fullscreen mode Exit fullscreen mode

This is all about some useful Linux tricks and commands, We can find more useful resources for
Linux. We can say Linux is all about Knowledge hub, we find more, you learn more !!!

Top comments (0)