Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

15/07/2020

[bash] Extract all distinct lines from file

Using a combination of cut and uniq, it is possible to extract all distinct lines from a given file:

cut -d\; -f1 file.txt | uniq


It is optionally possible to sort the file as well adding sort to the command:


cut -d\; -f1 file.txt | sort | uniq

[bash] Extract characters before marker from all lines in a file with sed

Using sed, it is possible to quickly extract all characters before a given marker from all lines in a file with:

sed 's/MARKER.*//' file.txt

29/04/2020

[Docker] Move docker directory to different location on NTFS filesystem

The default location of docker files (images, volumes, networks, etc) on most distributions is /var/lib/docker

This can be easily changed with the daemon.json configuration file.

First stop the docker service and make sure it is completely stopped.

You can now edit or create the configuration file under /etc/docker folder. In there, you can specify a new location for the docker files with the graph attribute:

{
   "graph": "/path/to/new/docker_folder"
}



You can then copy ALL the content to the new location or let docker recreate everything from scratch there.

WARNING: if the new location is on a different filesystem you might need to change the storage driver AND existing data might become inaccessible (it will remain on the filesystem though)

To set a new storage driver, set the storage-driver attribute as well (example for NTFS):

{
   "graph": "/path/to/new/docker_folder",
   "storage-driver": "vfs"
}

28/04/2020

[GNOME] Create application shortcut that can be added to favorites

Some applications you install come as archives that you extract in a desired location. However, not all come with an installer that takes care of creating the proper application entries, leaving the task to the user.

You can add a shortcut for any application by creating a file APPLICATION_NAME.desktop under /usr/share/applications and adding this content:

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Terminal=false
Categories=OPTIONAL_CATEGORY_LIST

GenericName=APPLICATION_NAME
Comment=OPTIONAL_COMMENT
Name=APPLICATION_NAME
Path=FULL_PATH_TO_APPLICATION_FOLDER
Exec=FULL_PATH_TO_APPLICATION_EXECUTABLE

Icon=OPTIONAL_FULL_PATH_TO_ICON

StartupWMClass=APPLICATION_WM_CLASS


[Linux] Find WM_CLASS value for an application

In order to group application windows together, the WMClass and WMInstance attributes have been specified in the Inter-Client Communication Conventions Manual for X server 11.

Long story short, they are two strings that are used to associate application windows to a specific application, they can be set by the application (WMClass) or the user (WMInstance).

They are very useful especially for those applications that are customizations or based on existing tools, which alone would have a different value (eg Java or Eclipse based apps).

Finding the value for a window is as simple as opening a terminal and running:

xprop

Then clicking on the desired window


25/04/2020

[Linux] Custom keyboard layout QWERTZ to QWERTY

We already saw how to customize a keyboard layout on Windows, now it's the turn of Linux, using XKB for Xorg.

Remapping keys is as simple as editing a text file. You will find all available layouts under /usr/share/X11/xkb/symbols, you can use them as basis for a new layout or directly edit them.

Pick the layout you want to change (maybe make a backup first), then invert the VALUES ONLY of the two lines containing the lower and uppercase z and y, then save.

You will need to restart X server and the changes will be in effect.

18/03/2019

[Ubuntu] Install Microsoft fonts

Most of the world uses Microsoft Windows and Office, therefore it might be sometimes necessary to generate documents using Microsoft fonts, which of course are only available on Windows.

For Ubuntu, the ttf-mscorefonts-installer package contains SOME of those fonts, simply install it and you can start using them AFTER regenerating the font cache with fc-cache

05/03/2019

[Ubuntu] Boot USB after error mmx64.efi not found

UEFI, great leap into the future and also great pain.

There is a funny error that can happen after creating a UEFI bootable USB to install a linux distro for example. If the installation is not completed immediately and the system is restarted, some files are left in some area of the EFI partition (I guess) and subsequent attempts to boot the exact same device will fail with an error:

Failed to open \EFI\BOOT\mmx64.efi - Not Found
Failed to load image \EFI\BOOT\mmx64.efi: Not Found
Failed to start MokManager: Not Fond
Something has gone seriously wrong: import_mok_state() failed


The easiest fix, is to simply browse the USB drive and go into the efi/boot folder, then copy the grubx64.efi file and rename it to mmx64.efi

The next boot will work again as intended. Magic of the machines

15/08/2018

[Ubuntu] Revert kernel back to older version

Intro story: So much luck in a single day.

I always keep only 2 kernel versions after every update, so that I can boot back if something goes wrong. This usually helps, except today I decided to upgrade my Ubuntu from 16.04 to 18.04 since I like spending my nights fixing stuff after unnecessary upgrades, but hey, the future is there.

So I first fully updated my current installation (1st kernel bump), then migrated to the new one (2nd kernel bump) and it turns out I got two 4.15 kernels, with only different minor version.

Double interesting, my wireless card:

02:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8821AE 802.11ac PCIe Wireless Network Adapter

apparently has issues (read: bug) with kernel 4.15 preventing it from working at all (not even connected to the router), and even more interesting, on one version it can actually only connect to websites under google.com domain..

Anyway, quick fix was to revert back my kernel, here is how for future me to remember:
  1. go to http://kernel.ubuntu.com/~kernel-ppa/mainline/ and download in the same folder: linux-headers-VERSION-generic-XXX_SYSTEM.deb, linux-headers-VERSION_all.deb, linux-image-VERSION-generic-XXX_SYSTEM.deb for your system, eg I have 64 bit system and got amd64 files
  2. install them by going into the folder where you downloaded them, make sure there are only those three .deb files and run: sudo dpkg -i *.deb
  3. restart the system, then press SHIFT at boot to enter the GRUB choices, then check from the top line (number 0) to the line of your kernel version. If your installation has the "Advanced" menu entry and does not display all kernels, go there and do the same counting. We need this to set a default GRUB entry to always boot in this kernel
  4. edit /etc/default/grub and change the value of GRUB_DEFAULT to the number you counted OR to (exactly as shown) "1>N" if you have the "Advanced" menu option. This means you want to boot into the Nth entry (starting from 0) under the "Advanced" menu. Also set GRUB_TIMEOUT to some value in seconds that's more than 1, to have some time to block the boot process in case of mistakes
  5. run sudo update-grub and you are set
Note that this is a TEMPORARY fix, you would not want to have a fully updated system run on an older version of the kernel, mainly because some obscure dependency or feature might be missing/not working, therefore check back periodically to see if your issue has been addressed and try the latest kernel version out!


04/06/2016

[Ubuntu] fix plymouthd splash load boot error

We sometimes struggle to keep up with all the things that are constantly evolving, so I like how Ubuntu still gives us reassurances that some important features are cemented in its core, such as the plymouthd boot splash error: "plymouthd could not load boot splash: could not access needed shared library".

Just update the kernel and you might be the lucky winner that gets stuck at boot.

The fix is easy and fast enough though. The immediate thing you can try is to edit the boot options when GRUB presents you the list of boot choices:
  1. select the Ubuntu line corresponding to the kernel you want to boot and press the e key
  2. find the line where the ro quiet splash parameters are set (unless you have already changed them in the past), but then you know which line I'm talking about anyway ;)
  3. remove the splash parameter
  4. add at the end of the line: gfxpayload=keep
  5. press F10 to boot

18/10/2014

[Ubuntu] Calibri and Microsoft fonts not displayed correctly

When using or displaying fonts from the Microsoft family on Ubuntu, they sometimes appear to be displayed incorrectly, rendering them unreadable. The issue is that the font rendering engine Freetype, uses the embedded bitmaps found inside those fonts which are only there so that they look pretty on Windows.

The solution is to disable that behaviour by creating a file .config/fontconfig/fonts.conf with this content

 <match target="font" >  
   <edit name="embeddedbitmap" mode="assign">  
     <bool>false</bool>  
   </edit>  
 </match>  

By logging out and in again, you should finally see them correctly displayed

[Ubuntu] Change terminal background color

On Ubuntu Linux, the default gnome terminal theme doesn't lend itself easily to screenshots, since they decided for some reason that violet would be a good background choice.

To change it, install gconf-editor:

sudo apt-get install gconf-editor

Then run it:

gconf-editor &

And browse to:

/apps/gnome-terminal/profiles/Default/

where you should uncheck "use_theme_colors" and change the default background color to anything you like. You will also find all other settings such as foreground color, font and so on.

05/07/2014

[Ubuntu] Enable hibernation

Ubuntu by default has the hibernation option disabled, even if the system is installed with enough swap space.

Before enabling it, first check if it works without issues by running this command:

sudo pm-hibernate

If the system hibernates correctly and you don't see any errors, edit the /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla file:

gksu gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

Then look for these two sections:

[Disable hibernate by default in upower]
[Disable hibernate by default in logind]

And change the ResultActive value to yes

Save, reboot and you'll have the option to hibernate the system now.


[Ubuntu] Fix volume reset after reboot

A small but annoying bug in Ubuntu causes the sound volume to be unmuted and reset to 100% after a reboot or logout.

This can be fixed by editing the /etc/pulse/default.pa configuration file for PulseAudio:

gksu gedit /etc/pulse/default.pa

Then look for these lines:

### Automatically restore the volume of streams and devices
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

and comment out the first one:

### Automatically restore the volume of streams and devices
#load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

Save, logout or reboot and you're set.

26/04/2014

[Linux] Replace Unity with another desktop environment

If you too feel like Unity is a nightmare and would like to switch to another desktop environment, but do not fancy to reinstall everything from scratch, know that it's indeed possible to switch between multiple installed ones at login time, although it's not recommended to have more than one installed.

This example will show how to convert Ubuntu(Unity) in XUbuntu(Xfce), but can be adapted to any desktop environment you like (simply install the desired environment instead of xubuntu-desktop).

First, install XUbuntu desktop:

sudo apt-get install xubuntu-desktop

Now if you log out, before you log in, you'll be able to select which desktop environment you want to log in to by clicking on the Ubuntu logo and selecting another session (ie: XUbuntu Session).

If you wish to remove the old environment to clean things up a little, run:

sudo apt-get remove activity-log-manager-common compiz compiz* gnome-applet* gnome-bluetooth gnome-control-center gnome-desktop* gnome-pane* gnome-power-manager gnome-screensaver gnome-screenshot gnome-sessio* gnome-shell-common gnome-termina* gnome-user* hud libzeitgeist* nautilus overlay-scrollba* python-zeitgeist unity unity* zeitgeist zeitgeist*

Afterwards, you may also want to run:

sudo apt-get autoremove

and if you have installed deborphan:

sudo orphaner --purge

[Linux] Add/remove PPA repositories

You can easily add and remove PPA repositories to your software sources with the apt-add-repository command. Use:

sudo apt-add-repository ppa:USER/REPOSITORY

to add and:

sudo apt-add-repository -r ppa:USER/REPOSITORY

to ONLY remove (same as --remove) it. Alternatively, if you installed ppa-purge, you can use it to remove the repository AND (if possible) revert to the official packages:

sudo ppa-purge ppa:USER/REPOSITORY

[Linux] Install VMWare Player

After downloading VMWare Player for Linux, you may feel a bit stuck on how to install it. Luckily, it's as easy as:

gksudo bash PATH_TO_DOWNLOAD_LOCATION/VMware-Player-VERSION.bundle

If you do not have gksu, install it:

sudo apt-get install gksu

20/05/2009

How to force package removal when apt fails on Ubuntu / Come forzare la rimozione di pacchetti quando fallisce apt su Ubuntu

IN ENGLISH:

Sometimes lacking the super-cow powers is a problem. Apt may in fact have trouble removing certain malformed packages. To force uninstall you could try:
sudo apt-get -f remove package
if it fails too, probably giving this error (or similar): 
subprocess post-removal script returned error exit status 2
Errors were encountered while processing:
  package_name
E: Sub-process /usr/bin/dpkg returned an error code (1)

you may try this:
cd /var/lib/dpkg/info
ls | grep package_name

locate some package_name.prm and delete it rm package_name.prm then try again with sudo apt-get remove package

IN ITALIANO:

A volte la mancanza dei poteri della supermucca è un problema. Apt puo' avere difatti problemi nella rimozione di certi pacchetti malformati. Per forzare la disinstallazione potete provare:
sudo apt-get -f remove nomepacchetto
se fallisce anche questo, magari dando questo errore (o simile): 
subprocess post-removal script returned error exit status 2
Errors were encountered while processing:
  nomepacchetto
E: Sub-process /usr/bin/dpkg returned an error code (1)

potete provare:
cd /var/lib/dpkg/info
ls | grep nomepacchetto

e cercate un qualche nomepacchetto.prm e cancellatelo rm nomepacchetto.prm quindi provate ancora con sudo apt-get remove package

26/04/2009

View tv on Ubuntu linux / Vedere la tv su Ubuntu linux

IN ENGLISH:

After swearing all the known gods and whishing sudden death for all the fake "howto" nerds I found on the internet, I came out with a solution for the question: "how can a noob watch tv on linux?".

The answer is easy: VLC!!
Ok, not just easy as simply VLC!, but quite. Let's see how we're going to receive the digital tv:
  1. Install vlc and dvb-utils: sudo apt-get install vlc dvb-utils
  2. locate the dvb folder path: whereis dvb, it should be under /usr/share/dvb
  3. browse to that folder: cd /usr/share/dvb/dvb-t
  4. scan for channels: scan - e.g. scan uk-Oxford >~/Desktop/channels.conf
  5. if your city is not in the list, manually create a file by looking at  the structure of one  other present in the folder, find the frequencies here (for uk), other similar sites should be found googling them. then scan with your file: scan myfile > ~/Desktop/channels.conf
  6. open vlc then open channels.conf created on the Desktop with the "open file" menu choice. You can browse to other channels looking at the playlist.
  7. If you didn't solve your problem, try writing me (just post a comment).. or if you wish, join the global swearing and make all the saints drop down one by one!


IN ITALIANO:

Dopo aver bestemmiato tutte le divinità note ed aver augurato morte violenta a tutti i finti nerd del "come fare" di internet, ho trovato una risposta alla domanda: "come fa un noob a vedere la tv su linux?".

La risposta è semplice: VLC!!
Ok, non così semplice come solo VLC!, ma quasi. Vediamo come ricevere la tv digitale:
  1. Installiamo vlc e dvb-utils: sudo apt-get install vlc dvb-utils
  2. cerchiamo la cartella dvb: whereis dvb, dovrebbe essere sotto /usr/share/dvb
  3. andiamoci: cd /usr/share/dvb/dvb-t
  4. cerchiamo i canali: scan it- e.g. scan it-Genova >~/Scrivania/channels.conf
  5. se la vostra città non è nella lista, potete creare un file manualmente guardando la struttura degli altri e cercando qua le frequenze: scan miofile > ~/Scrivania/channels.conf
  6. aprite vlc ed aprite il file channels.conf creato sul Desktop mediante il menu "open file". Potete cambiare canale semplicemente guardando la playlist.
  7. Se non avete risolto il problema, provate a scrivermi(semplicemente postate un commento).. o se volete, unitevi alla bestemmia mondiale e fate cadere i santi uno ad uno!