List disks with fdisk without showing loopback disks created by snap apps

You might’ve noticed that Snap apps creates a loopback disk used for mounting the image file for the app. This clutters the UI of fdisk, df and other disk related tools.

A typical fdisk -l could show you this:

Since most regular drives starts as /dev/sd* you could simply grep the output:

sudo fdisk -l | grep "Disk /dev/sd"

Or even better, use sudo fdisk -l | grep -v "loop". The -v parameter means grep reverts the keyword so anything containing “loop” will not be shown.

Another example: df -h:

Now: df -h | grep -v loop

Note regarding grep: You only need to add quotation marks around the keyword if it’s a string which contains spaces. Single words don’t need quotes.

You can also pipe it several times through grep, like this:

sudo df -h | grep -v loop | grep -v tmp

Or take a look at this Stackoverflow thread for more grep variants

Missing the new community theme Yaru after upgrading from Ubuntu 18.04 to 18.10

I just upgraded from 18.04 to 18.10 yesterday, but to my dismay, the new fancy theme, Yaru, was nowhere to be found. Looked around in Gnome Tweaks to no avail. Turns out some of the theme packages were not properly installed, more specifically the yaru-theme-gtk package. 

Enter the command apt search yaru-* to see installation status of every package containing “yaru-*”. If they are installed they will state [Installed] inside the square brackets, like so:

If they’re not installed, you can simply fix the issue by running sudo apt install yaru-*. Once complete, log out and back in, and the theme files will be available in Gnome Tweaks

Voila! Remember to also set CursorIcons and Sound theme to Yaru in Gnome Tweaks if desired.

Fix twitchy/wobbling touchpad for Ubuntu based distributions

On two occasions I have experienced that my Dell Latitude laptops has twitchy touchpads. This has happened on both Ubuntu 18.04 and elementaryOS 0.4 some years ago.

The fix, so far, has simply been to reinstall the xserver driver plus some additional software:

sudo apt remove xserver-xorg-input-libinput

sudo apt install xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-synaptics

Then reboot computer.

Bash function to check if it’s friday

Ever wondered if today’s Friday? Yeah me too, every day.

Keep yourself updated with this simple function.

 

1) Open your profile settings file
nano ~/.bashrc

2) Enter the following function in the bottom

yay() {
    day=$(date +%u)
    if [ "$day" == "5" ];
    then
        echo "YAY, IT'S FRIDAY!!!"
    else
        echo "Not to bring you down, but it's not friday yet :("
    fi
}

3) Reload your config file
. ~/.bashrc

4) Try it out! Just type yay in your terminal window whenever you wonder if it’s Friday or not.

How to see server uptime on Windows and Linux

See uptime and average load information on Linux machines

Run command:uptime

Output:

kek@donald:~$ uptime
 08:17:33 up 293 days, 14:21, 1 user, load average: 0.00, 0.00, 0.00

 

Show uptime on Windows machines using net stats

AFAIK there is no command in Windows to quickly see the uptime. However, there are several commands to get the last boot time, although you’ll have to do a quick calculation if you need the uptime in days. The easiest/fastest method is to use net stats.

Run command: net stats srv

Output:

C:\Users\kek>net stats srv
Server Statistics for \\hostname

Statistics since 09.11.2017 00.02.28 # last boot/uptime

Sessions accepted 1
Sessions timed-out 0
Sessions errored-out 0

Kilobytes sent 1649
Kilobytes received 1181193

Mean response time (msec) 0

System errors 0
Permission violations 0
Password violations 0

Files accessed 329
Communication devices accessed 0
Print jobs spooled 0

Times buffers exhausted

Big buffers 0
 Request buffers 0

The command completed successfully.

 

 

CRON Cheatsheet

I’m tired of always looking up CRON scheduling, so here it is including some examples.

CRON Scheduling table:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6)
# │ │ │ │ │                                      
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command to execute

Note that the day of week (0-6) typically starts with Sunday as the first index (0), so Monday = 1, Tuesday = 2 and so on. On some systems you might be able to also use 7 as Sunday.

CRON Examples:

Note that all the cron jobs output are redirected to /tmp/log.txt. If omitted, the default is to send an email to the sysadmin email address (if configured).

Run Python script every night at 02 am

* 02 * * * python /path/to/script.py >> /tmp/log.txt 2>&1

Run PHP script once every two hours

0 */2 * * * php /path/to/script.php >> /tmp/log.txt 2>&1

Run shell script every 10 minutes

*/10 * * * * /path/to/script.sh >> /tmp/log.txt 2>&1

Workaround for running a script every 15 seconds

* * * * * /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 15; /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 30; /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 45; /path/to/script.sh >> /tmp/log.txt 2>&1

Run a script every weekday at midnight

0 0 * * 1-5 /path/to/script.sh >> /tmp/log.txt 2>&1

Run script every Monday in June, July and August at 0530

30 05 * 6-8 1 /path/to/script.sh >> /tmp/log.txt 2>&1

Related post:

Linux Cheatsheet

List a rough overview for automated ssh login attacks

We all love to read log files, and for Linux I tend to simplify that search process if I know what I’m looking for. As you probably know many daemons and programs  logs to /var/log , but usually I don’t care to specify the file (like syslog or mysql.err etc) so I just do cat on all the files in the log dir.

So here’s a quick gem to list automated ssh attacks to your server:

$ sudo cat /var/log/* | grep BREAK-IN

Output:

Clean unused kernels when boot partition is full

My /boot partition keeps getting full so I must regularly clean it.

Quick instructions:

  • Show current linux kernel used
    uname -r
  • Show all installed kernels
    dpkg --list | grep linux-image
  • Remove old kernels which are no longer in use
    sudo apt-get remove linux-image-xxxx
    (replace xxxx) with the unused version numbers
  • For good measure, clean unused packages
    sudo apt-get autoremove
  • Optional: if the GRUB boot list is full of old kernel entries, update it by running
    sudo update-grub

Check out these articles for more info: