Useful Tools for Linux
Useful Tools
System Info
- Info about Hardware, Network, OS (Kernel…), even benchmarks.
sudo apt-get install hardinfo
- For Benchmarks (Cross-Platform, Free at this moment, but not Open Source)
curl -O https://cdn.geekbench.com/Geekbench-6.2.2-Linux.tar.gz #https://www.geekbench.com/download/linux/
tar -xzf Geekbench-6.2.2-Linux.tar.gz
cd Geekbench-6.2.2-Linux
./geekbench_x86_64
You will get something like: https://browser.geekbench.com/v6/cpu/your_id_number which will tell you single core and multi core scores. I got ~1100 and ~3300 with a laptop
- Terminal Based:
sudo apt install neofetch
#neofetch
- For Open Source: https://github.com/akopytov/sysbench
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt -y install sysbench
Hardware Monitor
CPU Freq
Adjusting CPU Freq in Laptops with AUto-CPUFreq:
#sudo snap install auto-cpufreq
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
cd auto-cpufreq && sudo ./auto-cpufreq-installer
Mission Center
A Windows like Task Manager for Linux.
flatpak install flathub io.missioncenter.MissionCenter
System Monitor
sudo apt-get install htop
#htop
sudo snap install btop
#btop
sudo snap install bashtop #https://github.com/aristocratos/bashtop
#bashtop
Network Monitor
Net Tools
sudo apt install net-tools -y
Get your public ip:
curl ifconfig.me
Get your local ip:
ip address
#ip a
Testing DNS
sudo apt install dnsutils
#example
#nslookup google.com
#ping google.com
#dig google.com
#host google.com
Worth to have a look: https://weberblog.net/benchmarking-dns-namebench-dnseval/
#cat /etc/resolv.conf
systemd-resolve --status | grep "DNS Servers"
#nmcli dev show | grep 'IP4.DNS'
You can see the DNS of each Network in your PC with:
resolvectl status #see which one you want to change, ex: enp2s0
#resolvectl dns enp2s0 9.9.9.9 149.112.112.112
#resolvectl status enp2s0
Quad9 is a good start point
How to choose a DNS for a specific App/Domain
General Ubuntu
Crontab Tasks
Make sure to install and Open crontab:
# apt install cron
# systemctl start cron
# systemctl status cron
crontab -e
Update it every midnight and every restart:
0 0 * * * #sudo apt update && sudo apt upgrade
@reboot #sudo apt update && sudo apt upgrade
You can create different schedule expressions
If your script isn’t executing, check the system log for cron events: grep cron /var/log/syslog
If you’d wish to view your scheduled tasks without editing you can use:
crontab -l
#crontab -u particularusername -l
What happens with CronTab when PC Shutdown?
Example - Install GIT and sync a Github Repository
sudo apt install git &&
git clone https://github.com/jalcocert/RPi.git &&
cd RPi &&
git pull #to make sure its up to date (a cron task could be scheduled)
If you want to add a cron task for this, simply edit, as explained:
0 0 * * * cd RPi && git pull
@reboot cd RPi && git pull
Example - Sync all your Gitea Repositories when PC Turn on
Now your imagination is the limit.
Let’s create a script that when your PC is booting, it will sync a given list of repositories from your Gitea instance.
nano git_sync.sh
If you want to add a cron task for this, simply edit, as explained:
Make it executable:
chmod +x /home/jalcocert/Desktop/GIT_SYNC/git_sync.sh
#@reboot /home/jalcocert/Desktop/GIT_SYNC/git_sync.sh >> /home/jalcocert/Desktop/GIT_SYNC/git_sync.log 2>&1
@reboot /home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.sh http://192.168.3.200:3033/fossengineer/FOSSENGINEER FOSSENGINEER http://192.168.3.200:3033/fossengineer/Py_Stocks Py_Stocks >> /home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.log 2>&1
#crontab -l #verify its added
How to Manage Cron Tasks with UI
CronTasks Status with UptimeKuma
With the Passive Monitor - Push:
Together with this python script and the crontab:
@reboot /home/jalcocert/Desktop/GIT_SYNC/git_sync_uptimekuma.py
Create users
#simple:
useradd pruebecita
#with sudo rights:
useradd -g users -G sudo -s /bin/bash -m -c "Your name" user_desired_name
#without sudo rights:
useradd -g user -s /bin/bash -m -c "Your name" user_desired_name
To make the home folders only visible but the specific users, just do:
chmod -R go-rwx /home/user_name_1
chmod -R go-rwx /home/user_name_2
chmod -R go-rwx /home/user_name_3
How to Create your own mount points
Lets first check the storages connected to the machine and identify their current path:
sudo fdisk -l
#lsblk
With this information we can create an automount entry in fstab:
sudo mkdir /mnt/data_mounted \
mount /dev/sdb1 /mnt/data_mounted/ #example
Depending on the file system, this might be needed:
mount -t ntfs /dev/sdb1 /mnt/data_mounted
If we know the UUID of the device, we can simply:
sudo mount UUID=92C269FAC269E2C9 /mnt/data_mounted
To do it automatically for a specific external device that we would have we need to find the UUID (Universal Unique Identifier) of the particular drive:
Option 1:
sudo blkid | grep /dev/sda2 | grep UUID= #example
Check what is mounted and where with:
df -h
#sudo snap install dust #to see what takes most space
lets add the automount entry in:
sudo nano /etc/fstab
#UUID=14D82C19D82BF81E_example /mnt/data_mounted auto nosuid,nodev,nofail,x-gvfs-show 0 0
Then we have to simply execute to mount as per our guidelines:
sudo mount -a
Always remember to unmount your external storeges safely with:
sudo umount /my_volume
Option 2: Another option would be to set a cron task with:
@reboot mount /dev/sdb1 /mnt/data_mounted/ #example
Power Management
How to lower CPU consumption?
To lower CPU power consumption on an Ubuntu system, you can install and configure various tools and utilities designed to manage and optimize power usage.
Some effective tools and techniques
TLP: TLP is an advanced power management tool that optimizes battery life on laptops and power usage on desktops. It comes with default settings tailored for saving power and can be customized according to your needs.
- Install TLP using the following command:
sudo apt install tlp tlp-rdw
- After installation, TLP will start automatically. However, you can start it manually and enable it to start at boot with:
sudo tlp start
- Install TLP using the following command:
cpufrequtils or cpupower: These tools allow you to adjust the CPU frequency scaling and governor settings. The CPU governor controls the scaling of the CPU frequency according to the current load, allowing you to balance between performance and power consumption.
- Install cpufrequtils with:
sudo apt install cpufrequtils
- Or, for more recent versions of Ubuntu, cpupower might be available:
sudo apt install linux-cpupower
- You can then set the CPU governor to a power-saving mode, like
powersave
, using:sudo cpufreq-set -r -g powersave
- Install cpufrequtils with:
Powertop: Powertop is a tool developed by Intel that shows you the power consumption of your device and suggests optimizations to reduce power usage.
- Install Powertop with:
sudo apt install powertop
- To see the current power usage and suggestions, run:
sudo powertop
- Powertop can also automatically apply its optimization suggestions at startup by creating a service or script that runs
powertop --auto-tune
.
- Install Powertop with:
Auto-cpufreq: This tool automatically adjusts CPU frequency and power modes in real-time based on system load and power source. It’s useful for those who prefer a more “set it and forget it” approach.
- Since Auto-cpufreq isn’t available directly from the standard Ubuntu repositories, it can be installed via a snap or its GitHub repository. To install it using snap, use:
sudo snap install auto-cpufreq
- To monitor and automatically adjust the CPU settings, you may need to run it with:
sudo auto-cpufreq --live
- To enable persistent changes, consider installing it as a service through its GitHub instructions.
- Since Auto-cpufreq isn’t available directly from the standard Ubuntu repositories, it can be installed via a snap or its GitHub repository. To install it using snap, use:
Remember, while these tools and settings can help reduce power consumption, they might also impact the performance of your system under certain workloads.
Power Management with Linux
- https://askubuntu.com/questions/83685/scheduling-startup-and-shutdown
- https://www.baeldung.com/linux/auto-suspend-wake
How to Setup WakeOnLan (WoL)
- https://www.reddit.com/r/CommercialAV/comments/xcfgyr/is_wakeonlan_still_your_goto_or_are_there_better/
- https://www.reddit.com/r/sysadmin/comments/s3uv8y/wake_on_lan_wol_for_dummies/
Networking
Network Monitor
Net Tools
sudo apt install net-tools -y
Get your public ip:
curl ifconfig.me
Get your local ip:
ip address
#ip a
Testing DNS
- What it is my DNS on Linux?
resolvectl status
- What it is the DNS of a particular Network Interface:
ifconfig
resolvectl dns wlp0s20f3
#change it with
#resolvectl dns wlp0s20f3 9.9.9.9 149.112.112.112
- And now, lets test a DNS:
sudo apt install dnsutils
#example
#nslookup google.com
#ping google.com
Worth to have a look: https://weberblog.net/benchmarking-dns-namebench-dnseval/
cat /etc/resolv.conf
You can see the DNS of each Network in your PC with:
resolvectl status #see which one you want to change, ex: enp2s0
#resolvectl dns enp2s0 9.9.9.9 149.112.112.112
#resolvectl status enp2s0
Quad9 is a good start point
- DNS Benchmark with namebench:
sudo snap install namebench-snap
How to Test the network card?
iperf3 -c 192.168.3.200
How to Install & use TMUX
Install TMUX with:
apt install tmux
#tmux #CTRL+B CTRL+D to detacht and CTRL+A to attach again
Cleaning the System with UI: clean cache, monitor processes, snap packages installed, apt repositories..
sudo add-apt-repository ppa:oguzhaninan/stacer
sudo apt-get update
sudo apt-get install stacer
#stacer
FAQ
Must know CLI’s
What’s taking that much disk space?
du -h --max-depth=1 ~/ | sort -rh
#sudo apt-get install ncdu
#ncdu /
- For Power Management:
How to turn off
systemctl suspend
- For Networking:
How to know my local IP?
hostname -I
What if I need to add my IPv6 address too?
You can check your raspberry IPV6 with:
ifconfig
How to get UID and GUI
id pi #id <your username>
How to use mac in Linux
Install Sosumi
#https://snapcraft.io/install/sosumi/ubuntu
sudo snap install sosumi
#CTRL+ALT+G #to get out of the VM
#sudo snap remove sosumi
Interested in VMs? Check this out.
How to Clone a SSD?
Clone your drives with Clonezilla
Save and restores only used blocks in a hard drive with Clonezilla
apt update
apt install clonezilla
You can also download the ISO, boot clonezilla from usb and select: device to device
Be carefull with the options you choose (source device, destination…)
How to Benchmark Linux
- Phoronix Test Suite
- MemTest
- prime95
Screen Share with Linux
With RustDesk
Install RustDesk with Flatpak:
sudo apt install flatpak
flatpak --version
#flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
wget https://github.com/rustdesk/rustdesk/releases/download/1.2.3-1/rustdesk-1.2.3-x86_64.flatpak
flatpak install rustdesk-1.2.3-x86_64.flatpak
flatpak run com.rustdesk.RustDesk
- Remmina, Vinagre, TigerVNC
- Guacamole with Docker
How to Create Custom Aliases
Lets edit this file:
nano ~/.bash_aliases
Add this line to know your public ip address by typing myip on the terminal:
alias myip='curl ipinfo.io/ip' #public ip address
Use this command to be able to use the new alias already in the current session
source ~/.bashrc
How to recognize and mount usb ex-fat
#sudo apt-get install exfat-fuse exfat-utils
sudo apt install exfatprogs
sudo mkdir /mnt/usb
sudo mount /dev/sda1 /mnt/usb #lsblk will tell you which name it has sda1/2....
A better Linux Terminal - Fish vs Tabby
Have a look to Fish Shell:
sudo apt install fish
#fish -v
fish #use it
#chsh -s $(which fish) #make it default
Or Tabby:
wget https://github.com/Eugeny/tabby/releases/download/v1.0.205/tabby-1.0.205-linux-x64.deb
sudo dpkg -i tabby-1.0.205-linux-x64.deb
sudo apt-get install -f