Simple trick for remembering tar parameters

You have probably looked up the parameters for tar more than you’ve changed socks. And what if the scenario from xkcd ever became real? Could you really run a valid tar command without googling first?

XKCD: “I don’t know what’s worse–the fact that after 15 years of using tar I still can’t keep the flags straight, or that after 15 years of technological advancement I’m still mucking with tar flags that were 15 years old when I started.”

Here’s a few tricks to help you remember how to use tar if you want to extract files from an archive, either .tar , .gz or tar.bz2

-xextract
-ffile

That’s it! All you need is tar -xf <filename>

Many guides will use -xvfz (or -xfzv or -xfvz or whatever), but -v and -z are not actually necessary.

-z is only used to tell tar it’s a .gz file, but for the last 15 years or so tar have been able to automatically detect this itself.

The other parameter, -v, is not necessary either, but it can be quite useful as it simply means verbose (extended/detailed) output in the terminal window.

So you if you want to see the progress of the file operation, include -v as well, so the final command becomes:

tar -xvf <filename>

Remember it by saying out loud: tar eXtract Verbose File <filename>

Or, as mentioned, simply use: tar -xf <filename> (tar eXtract File <filename>)

How to restart KDE Plasma shell if it freezes

If your KDE Plasma environment is hanging or freezing you don’t necessarily have to logout and login. Open the Search/Run prompt by pressing ALT+F2 and enter konsole to open your terminal.



Then simply issue the necessary command to restart plasma shell.

For KDE4:

killall plasma-desktop
kstart plasma-desktop


KDE5:

killall plasmashell
kstart plasmashell


KDE5.10 and above:

kquitapp5 plasmashell
kstart5 plasmashell

Credits goes out to Korcia at this AskUbuntu thread.

Add text color to Linux bash scripts

Bash supports coloring text, but I never remember the syntax, so here’s a little cheat sheet. During my little research it also seems you can enter the color codes in two ways as illustrated below:

echo -e "\033[0;32m Hello world!"
echo -e "\e[32m Hello world!"

Some more examples:

Difficult syntax:
\033[0;xxm (where xx is color code)
Easier syntax:
\e[xxm (where xx is color code)

I’m not sure if there’s any reason to choose one or the other, but the latter example is arguably easier to remember.

All color codes:

Reset color   0
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown/Orange 0;33
Light Gray 0;37
Dark Gray 1;30
Light Blue 1;34
Light Green 1;32
Light Cyan 1;36
Light Red 1;31
Light Purple 1;35
Yellow 1;33
White 1;37

You can also do lots of other things in bash, such as blinking text, bold, etc. Take a look at this site for more examples.

If you like to create CLI tools, adding some colors will make it a lot more immersive and easier to read output, like this example:

Linux terminal command equivalents in Windows

LinuxWindowsDescription
sudo <cmd>runas /user:admin <cmd>
This will run the command with admin-privileges on Linux, while on Windows it’ll simply run as the user provided (so you need to run as a user who has local administrator rights)
cat src1.js src2.js > compiled.jstype src1.js src2.js > compiled.js
Combine two or more files into one
ifconfigipconfigShows network information
traceroutetracertTrace an address and show routes
uptimenet stats server or net stats workstationWindows don’t have a builtin command to show uptime in days, but this command will show you when the machine was last booted (do the math)
lsdirShow directory contents
freememShow available RAM

I started on this article a couple years ago but was quickly forgotten in the drafts bin. Now I actually don’t have any Windows computers available anymore and can’t be arsed to look up more commands so this’ll have to work for now.

Some simple commands such as cd, mkdir, rm, rmdir has been ignored for now as they’re equal in both operating systems.

Please post a comment below if you know of any useful commands available on both operating systems.

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.