top of page

Advanced Linux Commands For The Power User



1. Checking Battery Status From The Terminal

One of the aspects of being a power user is to do even the simplest GUI-based tasks from the terminal. Sometimes, it is good practice to do even the simplest things from the terminal. Checking your battery might be something menial but you might need it while writing scripts or while configuring your system (for example to write polybar or i3-status scripts)


To view your current battery stats, type in the acpi command:

$ acpi -V
Battery 0: Full, 100%
Battery 0: design capacity 2800 mAh, last full capacity 1939 mAh = 69%
Adapter 0: on-line
Thermal 0: ok, 27.8 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 100.0 degrees C
Thermal 0: trip point 1 switches to mode active at temperature 71.0 degrees C
Thermal 0: trip point 2 switches to mode active at temperature 55.0 degrees C
Thermal 0: trip point 3 switches to mode active at temperature 50.0 degrees C
Thermal 0: trip point 4 switches to mode active at temperature 45.0 degrees C
Thermal 1: ok, 25.0 degrees C
Thermal 1: trip point 0 switches to mode critical at temperature 107.0 degrees C

This should give you comprehensive details about your battery stats, which you can later use in scripts!


2. Replace Ping And Traceroute With MTR

When it comes to network diagnostics, we all are familiar with the commands like ping and traceroute. However, many users might find mtr to be a much more utilitarian tool.


It investigates the network connection between the host mtr runs on and the target by sending packets with purposely low TTLs, so at to examine each node in the route.


It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to target.

MTR


3. Recursively List Files And Folders Tree

Another simple utility which can be greatly helpful is the tree command which is a recursive directory listing program that produces a depth indented listing of files.


It helps you view all the files and sub-folders in a directory in a clean way. This is useful especially during project management when you have a large number of files and doing ls every time proves to be too cumbersome.

$ tree
.
├── Program-1
│   ├── program-1
│   ├── program-1.rs
│   └── README.md
├── Program-2
│   ├── program-2
│   │   ├── Cargo.lock
│   │   ├── Cargo.toml
│   │   └── src
│   │       └── main.rs
│   └── README.md
├── Program-3
│   ├── program-3
│   │   ├── Cargo.toml
│   │   └── src
│   │       └── main.rs
│   └── README.md
├── Program-4
│   ├── program-4
│   │   ├── Cargo.toml
│   │   └── src
│   │       └── main.rs
│   └── README.md
└── README.md


4. Taking Screenshots From The Terminal

Adding to the list of CLI tools to replace their GUI alternatives, we have scrot, a CLI based screen capture utility which you can use to capture screenshots.


A very handy function of scrot is that it can be included in scripts and config files. For example, you can add the following line to your i3 config to capture a screenshot and store it in a folder ~/Pictures/Screenshots when the PrtScr button is pressed:

bindsym --release Print exec scrot 'Screenshot_%Y%m%d_%H%M%S.png' -e 'mkdir -p ~/Pictures/Screenshots && mv $f ~/Pictures/Screenshots && xclip -selection clipboard -t image/png -i ~/Pictures/Screenshots/`ls -1 -t ~/Pictures/Screenshots | head -1`'

Taking Screenshots With Scrot


5. Process Monitoring With Pstree

Process management has always been a cumbersome task for Linux users. The tracking of processes and their child process can be quite the task for the user.


This is where pstree comes into play. pstree shows running processes as a tree which let’s you view the child threads of a process which can be found under the parent process.


For integration with xterminal, you can also use pstree.x11 command. This command is especially useful as it gives you a comprehensive output which let’s you visualize the process tree in the terminal itself.

systemd─┬─NetworkManager───2*[{NetworkManager}]
        ├─bluetoothd
        ├─brave─┬─brave───brave───12*[{brave}]
        │       ├─brave───brave─┬─brave───5*[{brave}]
        │       │               ├─6*[brave───10*[{brave}]]
        │       │               ├─brave───15*[{brave}]
        │       │               ├─brave───4*[{brave}]
        │       │               ├─brave───14*[{brave}]
        │       │               └─brave───13*[{brave}]
        │       ├─brave───7*[{brave}]
        │       ├─brave───4*[{brave}]
        │       ├─brave───6*[{brave}]
        │       ├─plasma-browser-───2*[{plasma-browser-}]
        │       └─25*[{brave}]
        ├─crond
        ├─dbus-daemon
        ├─kitty─┬─fish───pstree
        │       └─6*[{kitty}]
        ├─kwalletd5
        ├─nm-applet───7*[{nm-applet}]
        ├─polkitd───7*[{polkitd}]
        ├─polybar───10*[{polybar}]
        ├─rtkit-daemon───2*[{rtkit-daemon}]
        ├─sddm─┬─Xorg───5*[{Xorg}]
        │      ├─sddm-helper───i3───{i3}
        │      └─{sddm}
        ├─systemd─┬─(sd-pam)
        │         ├─at-spi-bus-laun─┬─dbus-daemon
        │         │                 └─3*[{at-spi-bus-laun}]
        │         ├─at-spi2-registr───2*[{at-spi2-registr}]
        │         ├─dbus-daemon
        │         ├─dunst───2*[{dunst}]
        │         ├─gvfsd───2*[{gvfsd}]
        │         ├─gvfsd-fuse───5*[{gvfsd-fuse}]
        │         ├─kdeconnectd───3*[{kdeconnectd}]
        │         └─pulseaudio─┬─gsettings-helpe───3*[{gsettings-helpe}]
        │                      └─2*[{pulseaudio}]
        ├─systemd-homed
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        ├─systemd-userdbd───3*[systemd-userwor]
        ├─upowerd───2*[{upowerd}]
        ├─wpa_supplicant
        └─xss-lock───2*[{xss-lock}]


6. Make Your Shell Scripts Look More Professional With Whiptail

Whiptail is one of those programs which make your shell scripts look more professional and infact used very extensively. Whiptail lets you create a variety of questions or display messages using dialog boxes from a shell script.

  • Menu boxes

  • Input boxes

  • Message boxes

  • Text boxes

  • Password input boxes

  • Yes or no choices

  • Checklists

  • Radiolist boxes

  • Gauge boxes

  • Password boxes


Whiptree Prompt


For example, you can create a YES/NO box to control the flow of execution of your program. You can create a dialog box and store the result in a variable : 0 signifies YES while 1 signifies NO

#!/bin/bash
whiptail --yesno "Question ?" 10 40
choice=$?
if [ $choice = 0 ]; then
  --do stuff--
else
  --do other stuff--
fi


7. Generate Color Palettes With Pywal

Pywal is a tool that generates a color palette from the dominant colors in an image. It then applies the colors system-wide and on-the-fly in all of your favourite programs. It is highly customizable and can be integrated with a lot of applications, including window managers, text editors, utility applications, application launchers, terminal emulators, etc.



Resource: Linux, Wikipedia, journaldev.com


The Tech Platform

0 comments

Commentaires


bottom of page