Useful Linux Command Line Tricks and commands 
Tags: linux, devops, programming, beginners
Published: 2020-12-15 14:59:00

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
```
As you will see the last executed commands with numbers, so we just need to execute the
command with the given number

```
!#
```
for example

```
!1
```
```
Where # should be replaced with the actual number of common that we want to execute.
```

## 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
```
## 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]
```
for example

```
# sudo apt update | tee update.txt
```
## 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
```
Step 2: Copy the Key to the Server

```
# ssh-copy-id username@Server-IP
```
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
```
```
The -p port option for if ssh is not configured on default (22) port.
```

## 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
```

* Check the Yum package history

```
# yum history
```

* Rollback the install package

```
# yum history undo <ID>
example
# yum history undo 2
the package will be removed
```
Rollback the Updates

* Install a Package or Patches

```
# yum update
```

* Check the yum History

```
# yum history
```

### Rollback the Updates

```
# yum history undo <ID>
# yum history undo 1
```

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 !!!