Secret Lesser known useful Linux commands

Secret Lesser known useful Linux commands

tree

The tree command will list you directory, files and sub folders contents in an easy to see way. No need for repeated ls commands. This can be useful to get an overview of all subfolders of the target directory.

tree /var/log/
tree rex.red/
rex.red/
├── folder-4
├── folder-5
├── folder-6
│   ├── folder7
│   │   ├── eeefolder_3333
│   │   │   ├── nine
│   │   │   │   └── testfile1
│   │   │   └── testfile2
│   │   ├── folder
│   │   ├── folder_33
│   │   │   └── nine
│   │   ├── folder_3333
│   │   │   └── nine
│   │   └── folder_8
│   │       └── nine
│   └── testfile3
├── folder-one
├── folder-three
└── folder-two

  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.


[dragos@localhost ~]$ tree -pughs rex.red/
rex.red/
├── [drwxrwxr-x dragos   dragos       6]  folder-4
├── [drwxrwxr-x dragos   dragos       6]  folder-5
├── [drwxrwxr-x dragos   dragos      38]  folder-6
│   ├── [drwxrwxr-x dragos   dragos      94]  folder7
│   │   ├── [drwxrwxr-x dragos   dragos      35]  eeefolder_3333
│   │   │   ├── [drwxrwxr-x dragos   dragos      23]  nine
│   │   │   │   └── [-rw-rw-r-- dragos   dragos       0]  testfile1
│   │   │   └── [-rw-rw-r-- dragos   dragos       0]  testfile2
│   │   ├── [drwxrwxr-x dragos   dragos       6]  folder
│   │   ├── [drwxrwxr-x dragos   dragos      18]  folder_33
│   │   │   └── [drwxrwxr-x dragos   dragos       6]  nine
│   │   ├── [drwxrwxr-x dragos   dragos      18]  folder_3333
│   │   │   └── [drwxrwxr-x dragos   dragos       6]  nine
│   │   └── [drwxrwxr-x dragos   dragos      18]  folder_8
│   │       └── [drwxrwxr-x dragos   dragos       6]  nine
│   └── [-rw-rw-r-- dragos   dragos       0]  testfile3
├── [drwxrwxr-x dragos   dragos       6]  folder-one
├── [drwxrwxr-x dragos   dragos       6]  folder-three
└── [drwxrwxr-x dragos   dragos       6]  folder-two

16 directories, 3 files
[dragos@localhost ~]$

pstree

[dragos@localhost ~]$ pstree

Tree but for precesses. Shows what processes originate from other processes.

kill -15 SIGTERM

Sends the SIGTERM signal to the process and allows it to exit gracefully. That process might hang so the next one is more drastic.

sudo kill -15 PID
[dragos@localhost ~]$ sudo kill -15 3778529
[sudo] password for dragos:
[dragos@localhost ~]$

sudo kill -9 KILL

Stop the process, end it now and don’t wait for anything.

kill -9 PID

[dragos@localhost ~]

$ sudo kill -9 3778526

ps -aux | grep log

List processes piped into grep to find a hanging process. Extremely useful for finding what is happening with a process that is still running but takes much longer than expected. You can get some hints about what is wrong using this command combination.

sudo !!

yum update 
sudo !!
[dragos@localhost ~]$ yum update
Error: This command has to be run with superuser privileges (under the root user on most systems).
[dragos@localhost ~]$ sudo !!
sudo yum update
[sudo] password for dragos:
Last metadata expiration check: 2:55:04 ago on Tue 31 Aug 2021 13:10:23 EEST.
Dependencies resolved.
Nothing to do.
Complete!
[dragos@localhost ~]$

Get public ip

curl ifconfig.io Public ip.

[dragos@localhost ~]$ curl ifconfig.io
111.222.333.444


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.