NB: All new filesystem-related stuff should go here. However I am not moving some older gists from this page to avoid breaking links.


  1. How to burn a blank CD on Ubuntu 20.04
  2. Trying to mount a, just purchased, blank CD as in:

    $ sudo mount /dev/sr0 /media/cdrom
    … will give you:
    mount: /media/cdrom: can't read superblock on /dev/sr0.
    Apparently at that point there is no filesystem at all on the disk. So simply insert the blank disk in the CD-ROM device and use the Brasero CD/DVD burner to burn a "data CD". Works like a charm.

  3. How to artificially change the time in Ubuntu:
  4. source #1
    source #2

    $ timedatectl set-ntp no
    $ timedatectl set-time 1974-12-24
    $ timedatectl set-time 03:05:49
    $ // do what you want to do ...
    $ timedatectl set-ntp yes
    
    NB: set-time is indeed used for both date and time.
    NB2: 1 and 0 can also be used in lieu of yes and no (respectively).

  5. how I fixed broken and missing packages
  6. In November 2022 I was initially unable to install kdiff3 on my Ubuntu 20.04 machine due to missing and broken packages. I was able to fix that with the following sequence:

    sudo apt update --fix-missing
    sudo apt install -f
    sudo apt --fix-broken install
    sudo apt autoremove

    … after which sudo apt install kdiff3 succeeded.

  7. how I configured Microsoft Mouse speed (incl. wheel speed)
  8. In September 2022 I replaced my Logitech mouse with a "Microsoft Comfort 4500" mouse on my ThinkStation P320 machine (running Ubuntu 20.04). I had to configure both the mouse acceleration and the wheel speed (both were very slow). The scripts I used are found in the following locations:

    mouse acceleration
    in project "environment", path: local-startup-scripts-ThinkStation-P320/change-microsoft-mouse-acceleration.sh
    wheel speed
    in project "tools", path: configure-mouse-wheel-speed.sh
    Be sure to also look for any accompanying README files (if any).

  9. how to list all custom repositories
  10. ls /etc/apt/sources.list.d
  11. Notes on upgrading Ubuntu 16.04 to 18.04 LTS
  12. The normative way to upgrade is:

    sudo apt update
    sudo apt upgrade
    … followed by:
    sudo do-release-upgrade
    (read more here)

    In February 2022 I encountered problems when following the above procedure as it failed, at the last step, with the following:

    Checking for a new Ubuntu release
     Please install all available updates for your release before upgrading.

    It turned out that this was due to a broken Python installation which I had to fix like this.

  13. fixed unverifiable signatures during apt update
  14. source

    Sometimes, during apt-get update you get hit by the following:

    the following signatures couldn’t be verified because the public key is not available

    E.g. like the following output:

    $ sudo apt-get update
    Ign http://security.ubuntu.com trusty-security InRelease
    Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
    ...
    Fetched 21.9 MB in 14s (1,537 kB/s)
    Reading package lists... Done
    W: GPG error: http://security.ubuntu.com trusty-security Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
    W: GPG error: http://archive.canonical.com trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32 

    In such cases, the following fixes it:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5

  15. how to install Oracle XE 11.2 on Ubuntu 16.04
  16. In January 2021 I used the instructions found here (PDF also saved here) and the process was, for the most part, smooth.
  17. how to launch GNOME control center will all the icons from the command line — i3wm and 16.04
  18. The following is sufficient (no sudo is required):
    env XDG_CURRENT_DESKTOP=GNOME gnome-control-center
    provenance: https://askubuntu.com/q/542744/89663
  19. how I installed Artifactory Pro on Ubuntu 16.04 (manually)
  20. NB: this is the preferred way as it affords greater control and does not require sudo

    After downloading the Artifactory Pro zip file from this page I followed the instructions on this page under the Manual Installation heading:

    To install Artifactory manually, simply unzip the Artifactory download file to a location on your file system. This will be your $ARTIFACTORY_HOME location.

    No further action is needed.

    Don't forget to modify your JVM parameters as needed by setting JAVA_OPTIONS in $ARTIFACTORY_HOME/bin/artifactory.default.

    I did not bother to set an ARTIFACTORY_HOME environment variable in my environment, nor did I bother to edit the JAVA_OPTIONS in the $ARTIFACTORY_HOME/bin/artifactory.default file.

    The only thing I did edit was the $ARTIFACTORY_HOME/tomcat/conf/server.xml file where I simply changed the value of a single connector port from 8081 (that's the first one that appears inside the Catalina service element) to 9081

    To launch artifactory I simply followed the instructions on the above page under heading Running Artifactory:

    Running Artifactory

    You can run Artifactory manually to see its behavior by directly executing: $ARTIFACTORY_HOME/bin/artifactory.sh The console is locked on the Artifactory process and you can stop it cleanly with Ctrl+C. To directly run Artifactory as a daemon process, using the environment variables of the shell you are currently in, execute the following script: $ARTIFACTORY_HOME/bin/artifactoryctl start

    … I just used artifactory.sh from a console terminal — I didn't bother with running it as a daemon.

  21. how I installed Artifactory Pro on Ubuntu 16.04 (as a service)
  22. After confirming with lsb_release -a that my release is codenamed xenial, I followed the instructions on this page:

    $ echo "deb https://jfrog.bintray.com/artifactory-pro-debs xenial main" | sudo tee -a /etc/apt/sources.list
    $ curl https://bintray.com/user/downloadSubjectPublicKey?username=jfrog | sudo apt-key add -
    $ sudo apt-get update
    $ sudo apt-get install jfrog-artifactory-pro

    To check the service, and in contrast to what one is advised in the linked page, the following did not work:

    sudo service artifactory check
    … instead, I confirmed correct installation with:
    sudo systemctl status artifactory.service
    sudo tail -f /var/opt/jfrog/artifactory/logs/artifactory.log
    … while also trying the following (for additional assurance):
    $ sudo systemctl stop artifactory.service
    $ sudo systemctl start artifactory.service

    When, following the above steps, I tried to connect to: http://localhost:8081/artifactory
    … but my Nexus Repository Manager was already running there, so I edited the following file:

    /var/opt/jfrog/artifactory/tomcat/conf/server.xml

    … and changed the port number to 9081.

  23. how I got Node 8.11.4 with pre-built binaries for Linux x64
  24. Simply fetch the version you need from https://nodejs.org/en/download/:

    wget https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz
    tar xf node-v8.11.4-linux-x64.tar.xz
    See this note on how to build from sources.

  25. how I fixed my python3 package on Ubuntu 16.04
  26. When I was trying to execute

    sudo apt-get install python3
    … I would eventually see the following problems:
    dpkg: error processing package python3 (--configure):
     package is in a very bad inconsistent state; you should
     reinstall it before attempting configuration
    dpkg: dependency problems prevent configuration of idle3:
     idle3 depends on python3 (>= 3.5.1-3); however:
      Package python3 is not configured yet.

    Trying the following:

    sudo dpkg --remove --force-remove-reinstreq python3
    … also failed with:
    dpkg: dependency problems prevent removal of python3

    I eventually managed to reinstall python3 only with:

    sudo apt-get --reinstall install python3

  27. how to restore packages if something you did broke Ubuntu
  28. My sad, didactic tale here — see my answer which is what eventually fixed the appearance of the terminal (apparently a lot of things in Ubuntu depend on the version of Python so you should never change those that come with the system).

    If you want to see why a particular package was installed, install aptitude and do:

    aptitude why <name-of-package>

  29. on whether autoremove is safe
  30. Short answer is that no, it's not. See here, here, here, and here.

    To make matters worse there's no easy way to discover if a package is a meta-package (and thus unsafe to remove — see also here for more).

  31. How to list packages with partial installation or uninstallation
  32. source

    I use:

    dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' | grep -v ^ii
    … to find packages with partial installation or uninstallation.

    To narrow down to only partially installed packages:

    dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' | grep -E ^.[^nci]

    The description of each field is (source):

  33. Fonts
  34. The collection of fonts you are able to use is the set of all fonts found under any subdirectory of /usr/share/fonts and ~/.fonts

    The above locations are scanned and any font found therein is added to the collection. The following command can be used to refresh the contents of the font cache:

    fc-cache -fv
    You may have to invoke it both with and without sudo as the effects may be different.

    In my system I have cloned the Google fonts repository on my home directory (so the repo resides in ~/fonts). I then did the following:

    cd ~/.fonts
    ln -s ~/fonts
    fc-cache -fv
    sudo fc-cache -fv

    I did the above in an effort to be able to configure my terminals to use the inconsolata font. Sadly, even though the fc-list command succeeds in finding the inconsolata both in the personal (~/.fonts) and the system-wide (/usr/share/fonts) locations:

    $ fc-list | grep -i inconsol
    /usr/share/fonts/truetype/inconsolata/Inconsolata-Bold.ttf: Inconsolata:style=Bold
    /home/mperdikeas/.fonts/fonts/ofl/inconsolata/Inconsolata-Regular.ttf: Inconsolata:style=Regular
    /home/mperdikeas/.fonts/fonts/ofl/inconsolata/Inconsolata-Bold.ttf: Inconsolata:style=Bold
    /usr/share/fonts/truetype/inconsolata/Inconsolata-Regular.ttf: Inconsolata:style=Regular
    … and even though Libreoffice finds the font, I still am not able to find it under the profile preferences of the terminal. So symlinking the ~/fonts directory from within ~/.fonts had no effect in my case (I guess that's because I had already copied the font into /usr/share/fonts).

  35. how to remove a Personal Package Archive (PPA) and any packages updated / installed by it
  36. In November 2017 I installed Emacs 25 on Ubuntu 16.04 by first installing a PPA (as described here). It was working fine, but I subsequently decided to unistall it and to remove the PPA I had installed for that purpose alone.

    Normally, I would purge the package and remove the PPA. Turns out there's a safer and cleaner approach that allows you to remove a PPA and at the same time gracefully downgrade any pacages it updated (over the official repositories) or any packages installed by it. This alternative is the program ppa-purge. I read about it here.

    So that's what I did in two simple commands:

    sudo apt-get install ppa-purge
    sudo ppa-purge ppa:kelleyk/emacs
    … after the above, emacs25 was no more (without having to explicitly apt-remove it)

    Note that the following file:

    /etc/apt/sources.list.d/kelleyk-ubuntu-emacs-xenial.list
    … continued to exist after the above procedure, but all its lines were commented out.

  37. how to install emacs25 on Ubuntu 16.04
  38. source

    In November 2017 I followed the below procedure to install Emacs 25 on my Ubuntu 16.04 ThinkPad T420 machine:

    sudo add-apt-repository ppa:kelleyk/emacs
    sudo apt-get update
    sudo apt-get install emacs25
        
  39. quick test to see if the locally configured SMTP MSA (Mail Submission Agent) is working
  40. This can be helpful when trying to troubleshoot programmatic MUA (e.g. using the javax.mail.Transport class).

    mail -s "subject" john.doe@gmail.com
    Program works by typing message body and ending it with a dot, at which point the email is sent out. mail is apparently using the Sendmail MUA (Mail User Agent) and talks to a MSA over SMTP at port 587 or 25 (if still allowed).

    It can happen that both the programmatic API and the mail program fail silently (with a 0 exit code) but then, when looking at the /var/log/maillog file one sees "Relaying denied" messages.

  41. how to see which directories are mounted on a local disk
  42. source. The following incantantion yields good results:
     df -P -T | awk '{print $NF " " $2}'| grep -v nfs | grep -v mvfs
    In the above incantantion we are filtering out the nfs and the MultiVersion File System filesystem types (the latter being used by the shitty ClearCase "product")
  43. find swap size
  44. There's a number of ways to obtain swap size:

  45. configuring swappiness
  46. Obtain current swappiness with:

    cat /proc/sys/vm/swappiness

    The Ubuntu default value is 60, for a reasonable endowed (memory-wise) system it is recommended to set that value to 10.
    Set it with:

    sudo sysctl vm.swappiness=10

    … following the above I did the following to (temporarily) clear and then turn back on the swap so that the new settings would take full effect:

    $ sudo swapoff -a &&  sudo swapon -a

  47. how to create a bootable USB flash drive with an image of Ubuntu
  48. finding which processes cause the disk to be grinding
  49. I had noticed by hard disk light flashing a lot so recently I used:

    $ sync
    $ echo 1 > /proc/sys/vm/block_dump
    $ dmesg -c | grep '/dev/sda'
          
    … don't forget to change the value of /proc/sys/vm/block_dump back to 0 when you're done.

    I've also used

    iotop --only
    (the --only option results in much cleaner output). It seems that in my case the culprit was jbd2 which I killed with:
    pkill gvfsd-metadata
    rm -rf .local/share/gvfs-metadata
          

    Sources: here and here.

  50. change the default login shell in RHEL
  51. Use either ypchsh or chsh.
  52. how to install Ubuntu from a USB flash drive in a Dell Precision laptop
  53. I basically prepared a USB flash drive with the ISO image of Ubuntu 14.04 LTS using unetbootin:

    sudo apt-get install unetbootin
    sudo unetbootin
          

    … I then inserted the flash drive to a port and tapped F12 when the Dell logo appeared during startup. This is consistent with what is described here under section: 3.Setup the Ubuntu Install:

    1. Insert the Ubuntu disk into your DVD drive or connect your Bootable USB into a port on the system.

    2. Tap rapidly on the F12 key when you see the Dell logo appear during start up. This will take you to the Boot Once menu.

    3. You can use the Cursor/Arrow keys to navigate the menu and highlight your selection. It will be either boot from USB or Boot from CD/DVD Drive. Once your Choice is highlighted hit the ENTER key.

    The guy at the store said that for versions of Ubuntu ≥ 14 UEFI should be used instead of BIOS (legacy).

    Some quick Googling reveals that the issue is more complicated than that.

    Incidentally I have failed to utilize the (expensive) video card — initially I had installed Ubuntu 16.04 and there appears to be an issue with the NVIDIA cards I wasted half a day on it, then gave up.

    Subsequently, when I installed Ubuntu 14.04 LTS I think I encountered the problem again but at any rate I finally did not install the NVIDIA drivers at all. Googling just now it seems that 14.04 also has some issues with the NVIDIA drivers. See for instance here.

    I wonder if the graphics card problems are related to the fact that the installation was done using UEFI and not BIOS.

    You can Google many ways to verify which controller is actually handling graphics — i.e. whether it is the processor built-in controller (Intel in my case) or an external graphics card controller (e.g. Nvidia).

    In my case I get:

    $ lspci | grep -i vga
    00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
          
    … I.e. the built-in Intel controller.

  54. how to mount any system that's accessible via ssh
  55. source
    Use sshfs.
    E.g. the following worked for me:
        $ sudo apt-get install sshfs
        $ mkdir /media/local-radacer-repository/
        $ sudo sshfs -o allow_other radacer@172.17.12.56:/data /media/local-radacer-repository
    radacer@172.17.12.56's password:
        $ ls /media/local-radacer-repository/
        total 28
        drwxrwxrwx 1  500  500  4096 Feb 19 12:59 ./
        drwxrwxrwx 7 root root  4096 May 19 15:39 ../
        drwx------ 1  500  500 16384 Feb 17 17:27 lost+found/
        drwxrwxr-x 1  500  500  4096 Feb 19 13:02 RADACER/
        
    To unmount:
        $ sudo fusermount -u /media/local-radacer-repository
        
  56. how to enable 64-bit Window versions in virtualbox under Ubuntu 14.04 64bit
  57. I had the strange situation on 2016-05-18 that even though my Ubuntu machine was 64-bit both in terms of CPU architecture and in terms of OS:
    $ uname -a
    Linux beorn 3.16.0-48-generic #64~14.04.1-Ubuntu SMP Thu Aug 20 23:03:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
    mperdikeas@beorn:~#
    $ arch
    x86_64
        
    ... the virtualbox program only allowed me to install 32-bit versions of Windows (even though I had installed the 64-bit version of virtualbox).

    The solution was to enter the BIOS and enable the following option:
    advanced → CPU configuration → secure virtual machine mode

  58. how to compute sector size of a block device
    1. find the device you are interested in
    2. $ mount | grep \ /\
      /dev/sda1 on / type ext4 (rw,errors=remount-ro)
            
    3. find the size of the block device in bytes
    4. $ sudo blockdev --getsize64 /dev/sda1
      246855761920
            
      NB: this should return a value that's in reasonable agreement with the output of:
      df -h .
    5. find the size of the block device in sectors
    6. $ sudo blockdev --getsize /dev/sda1
      482140160
            
    7. divide
    8. $ python
      Python 2.7.3 (default, Jun 22 2015, 19:43:34)
      [GCC 4.6.3] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> 246855761920 / 482140160.0
      512.0
      >>> quit()
            

      Hence, sector size is 512 bytes.
  59. setting default programs based on mime types in Ubuntu (from the command line)
  60. I followed the advice found here in order to change the default program associated with PDF files from evince to okular.

    However, changing the file /usr/share/gnome/applications/defaults.list (which is a symlink to /etc/gnome/defaults.list) didn't work for me.

    Instead, I had to change the file /usr/share/applications/defaults.list (which is different and not symlinked to the above):
    $ sudo cat /usr/share/applications/defaults.list | grep okular
    application/pdf=okular.desktop
        
  61. how to fix the screen resolution problem with VirtualBox in Ubuntu 14.04 64bit
  62. source
    The following worked for me:
  63. how to mount an ISO file
  64. source
    sudo mount -o loop path/to/iso/file/YOUR_ISO_FILE.ISO /media/iso
        
  65. how to find the PID of a process by its window
  66. source

    Run the following in a terminal:

    xprop | grep -i pid
    or
    xprop | awk '/PID/ {print $3}'
    … then use the mouse pointer to click on the window you're interested in.

  67. how to find the PID of the process listening to the 8080 port
  68. NB: the above uses extra flags to get around the fact that the 8080 port is shown aliased to http_alt in the default options of both netstat and lsof
    source
    There's two methods:
    using netstat
    sudo netstat -pan | grep 8080
    using lsof
    sudo lsof -P | grep 8080
  69. utility of hash in the shell
  70. source a
    source b
    hash is a bash built-in command. Last time I used to after installing version 24.5 of Emacs to ensure it gets picked-up:
    $hash -r
    Also, when called without any arguments it reports how many times you've hit which commands.
  71. how to install the Consolas font in Ubuntu

  72. source
    This is the procedure that worked for me:
    1. sudo apt-get install font-manager
    2. sudo apt-get install cabextract
    3. run the script at: ~/tools/consolas.sh in a dir where you don't mind the temporary directory temp that will get created
    4. double click on the Consolas fonts to install them with the default font manager
    5. manually copy the font files to /usr/share/fonts
    6. One might expect that installing the fonts with the font manager (in the previous step) would work but in my case it didn't and I had to manually copy the fonts:
      sudo mkdir /usr/share/fonts/truetype/consolas
      sudo cp /home/mperdikeas/tools/temp/CONSOLA*.TTF /usr/share/fonts/truetype/consolas
    7. run the fc-cache thing
    8. sudo fc-cache -fv
    9. launch LibreOffice to verify that the fonts are found
    10. reboot
    11. Sadly, even after the above step I couldn't select the new fonts in my terminal preferences so I had to log out and reboot.
  73. how to use xrandr to sent screen output from my laptop to an external monitor
  74. Sources (most helpful first): Procedure that worked for me:
    1. see what monitors are available using xrandr
    2. E.g. in my case I get (after plugging-in the second monitor):
      $ xrandr -q
      Screen 0: minimum 320 x 200, current 1280 x 800, maximum 8192 x 8192
      LVDS-1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 303mm x 190mm
         1280x800       60.0*+   49.5  
         1024x768       59.9  
         800x600        59.9  
         640x480        59.4  
         720x400        59.6  
         640x400        60.0  
         640x350        59.8  
      VGA-1 connected (normal left inverted right x axis y axis)
         1920x1200      60.0 +
         1600x1200      60.0  
         1280x1024      75.0     60.0  
         1152x864       75.0  
         1024x768       75.1     60.0  
         800x600        75.0     60.3  
         640x480        75.0     60.0  
         720x400        70.1  
      DVI-D-1 disconnected (normal left inverted right x axis y axis)
            
    3. Send VGA output to the VGA-1 monitor
    4. $ xrandr --output VGA-1 --mode 1920x1200
            
      At this point, the second (external) monitor shows ouput, but not all the screen is used. I assume this is because the laptop's monitor determines the screen size. So ...
    5. turn off the laptop monitor
    6. xrandr --output LVDS-1 --off
      At this point the external monitor is used fully.
    7. to turn the laptop monitor back on:
    8. xrandr --output LVDS-1 --auto

    NB: To mirror both monitors you do a:

    xrandr --output HDMI1 --mode 1920x1080 --output eDP1 --mode 1920x1080 --same-as HDMI1
          
    source

  75. how to play mp3 files from the console
  76. sudo apt-get install mpg321
    mpg321 song.mp3
        
  77. how to raise volume level of mp3 files
  78. sudo apt-get install lame
    lame --scale 3 song.mp3 song-three-times-louder.mp3
        
  79. how to tunnel HTTP traffic over SSH
  80. (instructions adapted and customized for my environment from this Linux journal article)
    A typical use case is to circumvent some sort of Kerio-control-like "solution" that's restricting access to sites. To implement this solution you need to enjoy administrator privileges to two machines:
    You then do the following:
    1. on the remote machine:
    2. You may wish to configure the following parameters in the remote machine's /etc/ssh/sshd_config file:
      # Force SSH Protocol 2
      Protocol 2
      
      #Turn on Privileged Separation for security
      UsePrivilegeSeparation yes
      
      #Deny root login
      PermitRootLogin no
      
      #Do not allow empty passwords
      PermitEmptyPasswords no
      
      # Forward my X Sessions
      X11Forwarding yes
      X11DisplayOffset 10
      
      # I hate Motd displays
      PrintMotd no
      
      # It's alliivee
      TCPKeepAlive yes
            
      NB: I am not certain the above configuration changes are necessary. Following the above edits, restart the SSH daemon on the remote machine. E.g. for Ubuntu:
      sudo /etc/init.d/ssh restart
            
    3. on the local machine:
    4. Open the tunnel in a terminal towards the remote machine. E.g. in the following I am using my koding VM as the "remote machine":
      ssh -D 5222 mperdikeas@mperdikeas.koding.io -N
            
      Once the tunnel is opened, configure your browser to use a SOCKS proxy. E.g. for the above scenario, I've configured Chrome to use as proxy a Socks host at localhost:5222.

  81. how to find the apt package to install for a LaTeX package
  82. Use the apt-cache command. E.g. for the LaTeX package outlines use:
    apt-cache search outlines | grep -i latex
        
  83. how to install TeX Live in Ubuntu
  84. source
    sudo add-apt-repository ppa:texlive-backports/ppa
    sudo apt-get update
    sudo apt-get install texlive
        

    If you already have TexLive and are updating type:
    sudo apt-get upgrade
        

    It might also be a good idea to install the TeX Live extras:
    sudo apt-get install texlive-latex-extra
        
  85. copy/synchronize from one hard disk (external or otherwise) onto another (with the possibility to resume)
  86. E.g. to backup the entire home directory:
    sudo rsync -avxHAWX --numeric-ids --progress ~ /media/wd-ext4-4T-plank/satl28-home/

    To copy bulk data from one external disk onto another (and keep the output as well):
    rsync -avxHAWX --numeric-ids --progress /media/cc171c39-fbb8-4d49-bd0f-84116ab2b11a/ /media/wd-ext4-4T-plank/planck-disk-1/ > ~/rsync.out

    source.
  87. what to do if Ubuntu 12.04 loops on the login screen
  88. It has occured to me once that Ubuntu 12.04 would keep looping on the login screen (while it would still be possible to login as a guest). The solution was to:
    1. open a shell terminal using CTRL+ALT+F1
    2. rename the ~/.Xauthority file, and,
    3. reboot from the terminal using sudo reboot
    ... as suggested in this Ask Ubuntu answer. Another apparently similar, yet less invasive, solution (which I haven't tried), is this one.
  89. alternative to the REISUB reboot
  90. It may sometimes be possible to unfreeze a Linux system by using:
    CTRL+ALT+F1
          
    ... to open a terminal (or F2, F3 ... up to F6 for that matter). Then top or htop tools can then be used to identify the offending process (in terms of CPU or memory utilization); alternatively some window manager may need to be restarted. To return whence you came from use:
    CTRL+ALT+F7
  91. how to check which libraries (so) are installed
  92. ldconfig -p
  93. determine physical memory
  94. Either use file /proc/meminfo
    $ cat /proc/meminfo  | grep MemTotal
    MemTotal:        8215280 kB
          
    … or use free as in, e.g.:
    free -m
  95. sectors, blocks and pages
  96. More information:
    here and here.
  97. How to get sector, block and page sizes
  98. To get the sector size do a:
    sudo fdisk /dev/sda1 -l
          

    Block size is an artifact of the filesystem, not the device, to get the block size for an ext3 or ext4 filesystem do a:
    sudo dumpe2fs /dev/sda1 | grep 'Block size'
          
    More here.
    The page size is an artifact of the kernel. It can be obtained with:
    getconf PAGESIZE
          
  99. tying sector size and block size together in a concrete example
  100. echo "a"> a && stat a | head -2
          
    In my system I get the following output:
      File: `a'
      Size: 2         Blocks: 8          IO Block: 4096   regular file
          
    In this example, the stat utility uses the term "blocks" not in the sense of file system blocks but rather to mean an arbitrarily-sized unit, in this case 512 bytes. So the 2 bytes of file "a" (size) require an entire file-system block, which in my system is 4096 (obtained using sudo dumpe2fs /dev/sda1 | grep 'Block size') and so this translates to 8 512-byte "units" or "Blocks" (in the stat's terminology). I.e. some Unix utilities use the term "block" without any reference to the file system block size.
    More here.
  101. show file systems, their type, UUIDs and mount points
  102. For file systems types and mount points:
    df -T
          
    For file systems UUIDs and types:
    sudo blkid
          
  103. show the configuration for automatic file system mounting
  104. cat /etc/fstab
          
    UUIDs can then be used to mount volumes automatically (see here).
    To find the UUID of a file system check this note
  105. find the UUID of a file system
  106. The below two ways seem to work:
    sudo dumpe2fs /dev/sda1 | grep UUID
            

    or
    sudo blkid /dev/sda1
            
  107. find the Debian version on which your Ubuntu version is based on
  108. $ cat /etc/debian_version
    wheezy/sid
            
    (output for my system).
    Typical correspondances:
    14.10        jessie / sid
    14.04        jessie / sid
    13.10        Wheezy / sid
    13.04        Wheezy / sid
    12.10        Wheezy / sid
    12.04        Wheezy / sid
    11.10        Wheezy / sid
    11.04        Squeeze / sid
    10.10        Squeeze / sid
    10.04        Squeeze / sid
            
    (
    source)
  109. how to toggle-on and off wired networking
  110. To see the interfaces:
    sudo ifconfig
    To bring down eth0:
    sudo ifconfig eth0 down
    To bring it up back again:
    sudo ifconfig eth0 up
  111. configuring and saving cron jobs
  112. The user-level cron files are apparently located in `/var/spool/cron/crontabs` but are not meant to be edited directly. Instead do a:
    crontab -e
    To view (pipe that to save) such files:
    crontab -l

    To monitor in real-time CRON jobs:
    tail -f /var/log/syslog | grep CRON
            
  113. total RAM (and usage / free thereof)
  114. free -m
            
    or
    cat /proc/meminfo  | grep MemTotal
            
  115. Find what package a file belongs to in Ubuntu/Debian
  116. apt-file search filename

    or
    apt-file search /path/to/file

    superuser link
  117. last thing to try in frozen Ubuntu before hard restart
  118. Holding down ALT and Sys Req / Print Screen keys hit the following keys: REISUB. Mnemonic: Restart Even If System Utterly Broken (or reverse BUSIER - the system is busier than usual).
    See also
    this alternative which is even softer.
    Ask Ubuntu link
  119. some random commands entered during networking troubleshooting:
  120. nslookup www.google.com
    cat /etc/resolve.conf
    ifdown eth0
    sudo /etc/init.d/networking restart
    cat /etc/network/interfaces
    ifconfig eth0
            
  121. how to properly kill
  122. First you should try a kill -15, followed by a kill -9 See this unix.stackexchange question
  123. number of cores
  124. nproc which returns a single integer, or, for a more detailed output: lscpu
  125. total size of files satisfying a find criterion
  126. du -c $(find . -type f -o -type l -maxdepth 1)
    so
  127. find which process is causing "device busy"
  128. (sudo) lsof | grep (device name or path to which device is mounted)
    so
  129. how to remove the lingering http_proxy environment setting
  130. Doing a: export http_proxy= is not enough for Rails (e.g. bundle install keeps failing). You should do a: unset http_proxy so that prinenv | grep http_proxy returns no sign of it.
  131. install bitcoin on Ubuntu
  132. Add the bitcoin PPA: ppa:bitcoin/bitcoin (e.g. using 'gksudo software-properties-gtk') followed by a:
    sudo apt-get update
    sudo apt-get install bitcoin-qt
            
    and maybe 'sudo apt-get install bitcoind'
  133. software center crash problem
  134. Checkout this askubuntu.com discussion. Bottom line:
    sudo rm /var/lib/apt/lists/* -vf
    sudo apt-get update
            
  135. add and manage Ubuntu PPAs - command line invocation of graphical tool
  136. gksudo software-properties-gtk
  137. add Ubuntu PPAs - command line only
  138. sudo add-apt-repository ppa:hotot-team
    sudo apt-get update
            
  139. run graphical command that needs root
  140. Use gksudo. It's primary purpose is to run graphical commands that need root without the need to run an X terminal emulator.
  141. how to diagnose and clear "hangover" HTTP proxy settings in Ubuntu
  142. $ env | grep -i proxy
    http_proxy=http://localhost:9000/
    UBUNTU_MENUPROXY=libappmenu.so
    $ unset http_proxy
    $ env | grep -i proxy
    UBUNTU_MENUPROXY=libappmenu.so
            
  143. find which process is thrasing the hard drive
  144.     $sudo apt-get install iotop
        $sudo iotop
            
  145. techniques for managing dotfiles
  146. password-aware zip/unzip utility in Ubuntu
  147. sudo apt-get install p7zip-full
    And then:
    7z x file.zip
    ... which prompts for password.
  148. busted package lists in Ubuntu
  149. When trying to install graphviz (I'm sure it can happen with other packages as well), I got:
        $ sudo apt-get install graphviz
        Reading package lists... Error!
        E: Encountered a section with no Package: header
        E: Problem with MergeList /var/lib/apt/lists/es.archive.ubuntu.com_ubuntu_dists_precise_main_i18n_Translation-en
        E: The package lists or status file could not be parsed or opened.
            

    The following fixes it:
    sudo rm /var/lib/apt/lists/* -vf
    sudo apt-get update
      
    After the above two commands sudo apt-get install graphviz succeeds. I think doing a sudo apt-get install upgrade wouldn't hurt either but I didn't try it in this particular case. I also tried it again in a similar situation and was able to sudo apt-get install p7zip-full while it previously failed.
  150. find which fonts are available
  151. fc-list
  152. disabled laptop internal keyboard (e.g. so as to only use the USB keyboard)
  153. Original article here. Do a:
    xinput --list
      
    to find the id of the devices connected to the computer. Then to disable a device (say the built-in keyboard has id 11, do a:
    xinput set-int-prop 11 "Device Enabled" 8 0 
      
    And to enable it back again, do a:
    xinput set-int-prop 11 "Device Enabled" 8 1
      
  154. remove existing partitions and format USB flash drive or SDHC memory card for Linux
  155. source

    Before you start, make sure you've unmounted any file systems that were mounted on that device

    First of all do a sudo -i. Then, use two commands: fdisk followed by a mkfs.ext3 First, do a:
    lsblk
    ... to find the device names and the partitions. In my case I had three (3) partitions on the same external USB HDD: /dev/sdg1/, /dev/sdg2 and /dev/sdg3. I then did a:
    fdisk /dev/sdg
    to create a single partition (m to list the available commands, p to list existing partitions, d to delete partitions, n to create a new partition and w to write the partition table).

    This was followed by a:

    mkfs.ext3 /dev/sdg1
    ... on the single partition I created. Finally, to label the drive I did a:
    sudo e2label /dev/sdg1 150GB-USB-hdd

    NB: more recently I just did a:

    mkfs.ext3 -L volume-label /dev/sdg1
    to format and label the volume in one step without needing to use e2label.

    NB2 You may not be able to write to this disk as normal user as root may own it, but just doing chown user:user /media/volume-name or chmod -R a+rwx /media/volume-name will do the trick.

    NB3 It is important that the fdisk is performed on the entire device (as in fdisk /dev/sdg) but that mkfs.ext3 is performed on a single partition (as in mkfs.ext3 .. /dev/sdg1).
    Doing the mkfs.ext3 on the entire device would still work but then the fdisk -l command will complain about not being able to find the file system type.

    NB4 To confirm that you've correctly formated the flash drive do a sudo blkid afterwards (this works whether the drive is mounted or unmounted)


    2018, April. I did the following to format to FAT32 a Transcend 8GB USB flash drive (which I intended to use to create a bootable Ubuntu 16.04 flash drive):

    sudo fdisk /dev/sdb
    In the step above I followed the sequence of steps described above to list the existing partitions (p), delete the existing partition (d) and then create a new partition (n) and, finally, write the partition table (w).

    This was then followed by:

    sudo mkfs.fat -F 32 /dev/sdb1
    to create a FAT32 file-system on the flash drive.

    However, I was unable to label it. I tried:

    sudo fatlabel /dev/sdb TRANS-8GB
    … but it wasn't working. However, I tried again later using:
    sudo fatlabel /dev/sdb1 TRNSND8BLAC
    … (as advised here) and it worked like a charm (on the second try). The difference was that the second incantation used the partition, not the entire device, and that filesystem was dismounted when I tried the second incantation.

    At any rate notice again how (as advised above) fdisk is performed on the entire disk whereas mkfs on a single partition.

    2019, May I encountered some problems with the above procedure in that the thumb drive I created (even though FAT32) wasn't readable from a High Sierra MacBook Air. To fix that I first completely erased and re-formatted the USB thumb drive using the gnome-disks program before proceeding with the April 2018 procedure. I still couldn't get the High Sierra machine to read it. I then formatted it on the Mac using the simple FAT filesystem and at that point it worked in both Ubuntu and MacOS.

    2021, May While trying to format a brand-new SanDisk 256G thumb drive I encountered problems with the above procedure. Specifically, the following step:

    $ sudo mkfs.ext3 -L san256G /dev/sdc1
    … became stuck at the point where the journal get's created:
    Creating journal (262144 blocks): 
    To get around this problem I formated the drive in ext4 as follows:
    $ sudo mkfs.ext4 -L san256G -F /dev/sdc1
    NB5 As always, you must remember to first delete the existing partitions, then create a new partition (just accept the defaults) and write it on the drive using:
    $ sudo fdisk /dev/sdc
    Only after the above step (which has always succeeded in my experience) should you go ahead with the mkfs.ext4 tool.

  156. remove BOM from files in Linux
  157. tail --bytes=+4 text.txt
  158. remote desktop connection in Linux
  159. rdesktop -a 16 -f 192.168.0.2
    a for color depth (16 bits), f for full-screen
  160. how I transformed a set of java files using the slav-latin encoding (for Czech) to UTF-8
  161. Two steps:
    1. change the encoding of the files using iconv
    2.  for x in $(find . -iname \*.java) ; do  iconv  --from-code=ISO-8859-2 --to-code=UTF-8 $x > $x.boo ; done
    3. rename the sources back to Java
    4. for i in $(find . -iname \*.java.boo) ; do mv -v $i ${i%.java.boo}.java ; done
      NOTE: before the previous I had the following which doesn't work as it does the renames to the local folder:
      for i in $(find . -iname \*.java.boo) ; do mv "$i" "`basename $i .java.boo`.java"; done
  162. find a package's version
  163. dpkg -s postgresql
  164. apt-get update -vs- apt-get upgrade -vs- apt-get dist-upgrade
  165. You should first run update, then upgrade. Neither of them automatically runs the other:
  166. list of fonts
  167. fc-list
  168. format external USB flash drive in Linux
    1. remove and insert the flash drive and do a:
      dmesg | tail
      .. to identify the device (/dev/sdc1 in my system)
    2. confirm with a:
      df
    3. dismount:
      sudo umount /dev/sdc1
    4. format:
      sudo mkfs.ext3 -n 'name' /dev/sdc1

      Note, sometimes -n is not understood and the following works instead:

      sudo mkfs.ext3 /dev/sdc1
    5. I've also seen:
      sudo mkfs -t vfat /dev/sdb1
  169. find sockets bound and listened-to in the local host
  170.  sudo lsof -P -i -n 
  171. find the libraries used by a program
  172. ldd $(which wget)
  173. use the ldd Linux command to find version information (and dependencies?) about specific library files
  174. ldd /usr/lib/libappindicator3.so.1
  175. get seconds since the epoch to time
  176. date -d @23948239
  177. get date as seconds since the epoch
  178. date +%s
    date -d "Dec 24 1974" +%s
        
  179. open a file manager on the current directory
  180. xdg-open .
  181. viewing binary files in Linux
  182. Use the hexedit program.
  183. the two components of the LANG environment variable
  184. In my machine, at present:
    echo $LANG
    en_US.UTF-8
        
    The first component of the environment variable specifies the collation which dictates: (a) lowercase / uppercase logic, (b) ordering logic, (c) maybe, default codepage. The second component is the encoding. LANG should be set to the same value as the LC_ALL otherwise some instabilities may be observed.
  185. on the LANG environment variable
  186. The LANG environment variable is taken into account by the i18n component of libc, and therefore, because of that by all tools, interpreters and other libraries that interact with the console.

    In my machine it is currently:

    $echo $LANG
    en_US.UTF-8
          
    As a result everything that's inputed from the keyboard or output to the keyboard is converted automatically to UTF-8 (this is analogous to the 'Regional Settings' in Windows machines).

    To experiment do a:

    cat > datatest
            
    and type-in some Greek characters. The command file on my machine then yields:
    file datatest
    datatest: UTF-8 Unicode text
            
    If the file is converted to a Greek codepage, with:
    iconv -f utf-8 -t iso8859-7 < datatest > greek
            
    .. file then duly reports:
    file greek
    greek: ISO-8859 text
            
    .. and cating the file produces garbage on the console.
  187. configure emacs as the default text editor in GNOME
  188. Open (or touch if it doesn't exist) file:
    ~/.local/share/applications/defaults.list
    Add or edit the following text:
    [Default Applications]
    text/plain=emacs
            
  189. restore corrupt VM in Ubuntu
  190. do the following as root (history excrept):
      348  cd /home/mperdikeas/virtual-machines/vm/
      349  l
      350  ls -ltra
      351  l *lck
      352  mv *lck /var/tmp/
      353  ls -ltra
      354  mv caches/ /var/tmp/
      355  ls -ltra
      356  mv *vmem /var/tmp/
      357  l
      358  chown root.root *
      359  l
      360  chmod 644 *
      361  l
      362  vmplayer Windows\ XP\ Professional.vmx
            
  191. enable ssh authentication
  192. cat .ssh/id_dsa.pub
    (grep with mouse)
    cat >> .ssh/authorized_keys
            
  193. how to view the shared directories of a samba system
  194. smbclient -U a_tsiodras -L //172.31.128.250
            
    Occassionally, this might give a:
    session setup failed: NT_STATUS_LOGON_FAILURE
            
    if the server is not configured to provide a listing of the shared folders. In these cases, the only recourse is to know the shared folder names and directly mount them as shown on the below item.
  195. how to mount a samba system
  196. sudo mount -t cifs -o username=a_tsiodras //172.31.128.250/Download /iso2/ 
            
  197. find the (not-installed) package a file, e.g. javac belongs to
  198. Use the apt-file program:
    sudo apt-get install apt-file
    sudo apt-file update
    apt-file search /usr/bin/mysqldump
            
    (SO answer)
    Also, to find which installed package a file belongs to you can use, e.g.:
    dpkg -S /bin/ls

    Note that this doesn't always work for config files and files in /var since those are generated after the package is extracted.
  199. my LANG setting
  200. $ echo $LANG
    en_US.UTF-8
            
  201. how to format a memory stick
  202. First view drives and partitions:
    sudo fdisk -l
    Unmount the drive in question and format it, e.g. in NTFS:
    sudo mkfs -t ntfs /dev/sdg1
  203. find the UUID of a device in Ubuntu
  204. sudo blkid
  205. updated from unauthenticated sources in Ubuntu
  206. sudo apt-get update && sudo apt-get upgrade --allow-unauthenticated
    (source)
  207. view system calls made (e.g. in the invocation './NeuroCode.exe Project.xml'):
  208. strace -f ./NeuroCode.exe Project.xml 2>&1 | less
  209. view loaded modules in a Linux system
  210. lsmod
  211. how to install a bundle in Ubuntu:
  212. sudo sh VMware-Player-5.0.0-812388.i386.bundle 
  213. troubleshooting mounting problems
  214. Things one can do:

    The umount command shows all mounted filesystems.

    If an external HDD is not visible even at the output of fdisk -l this means that it is not visible, even as a device, which strongly suggests that the USB port itself may have been fried. I suppose a fried USB port could be diagnosed by the output of the lsusb command.

  215. mounting NTFS filesystems
  216. In general, all kernels provide default mount drivers in the kernel. However, for NTFS filesystems in particular, the best available mount driver is of type FUSE (Filesystems in USEr space) and you can get it with sudo mount ntfs-3g. You then use ntfs-3g instead of mount to do the actual mounting.
  217. find user id of a user
  218. id -u john
    For more information, includiing group id:
    id john
  219. add an Ubuntu repo's key to your APT keyring
  220. wget -q -O - http://emacs.naquadah.org/key.gpg | sudo apt-key add -
  221. show USB devices recognized by the kernel
  222. lsusb
  223. kernel messages
  224. dmesg
  225. cleanly remove an application
  226. apt-get remove --purge [appname]
    apt-get autoremove [appname]
    apt-get clean
    apt-get autoclean
                
    update 29.VIII.2012: ttsiodras recommends this:
    dpkg -P [packagename]
                
  227. install DEB packages
  228. wget the package (say package.deb) in a tmp folder and then do a:
    sudo dpkg -i package.deb
                
  229. starting scripts upon bootup
  230. There are two ways:

    1st way. Either: (a) using /etc/rc.local for things that are supposed to simply be run at startup, and (b) the init.d scripts - and their symlinks under runlevels /etc/rc{3,5}.d - for everything else.

    2nd way. There's also something without the complexity of startup scripts, which is much easier to use when you want to start/stop your process as if it is a daemon: "supervisor" ( http://supervisord.org/ ):

      [program:yourapp]
      command=/path/to/app --option1 ... 
      user=yourapp
      directory=/apps/yourapp
                      

    You add the file to /etc/supervisor/conf.d/, make a "supervisorctl update" and your service is up an running. It's a no-brainer and much easier than juggling rc.d scripts. Crash recovery and optional web interface included.

  231. how to find if Apache is running
  232. ps ax | grep httpd | grep -v grep
              
  233. how to cleanly re-install Apache (Debian)
  234. sudo apt-get remove --purge apache2 apache2-utils
    sudo apt-get install apache2
              
  235. how to find installed packages (Debian)
  236.  dpkg --get-selections
  237. how to find the source package a binary (e.g. ldapsearch) belongs to
  238. dpkg -S ldapsearch
  239. how to find the loci of the files of an installed package (Debian)
  240. update: It seems that the following produce more verbose / extensive output (see also this answer):
    dpkg-query -L <package name>
    apt-file list <package name>
              
    dpkg -L httpd

    end of update
    (-L lists all files installed to your system from that package name)

    Note that dpkg lists the files that were fetched as part of the install processes. Post-install hooks may create additional files (e.g. pyc files from py Python files). This can be seen by comparing the outputs of the following two commands:
    dpkg -L python2.7
    ls -s /usr/lib/python2.7/
                
    To find which packages are installed (so you can then do a dpkg -L on them, do a:
    dpkg --get-selections
  241. how to find directories in current dir
  242. ls | grep ^d
  243. find the 10 largest files or directories in a hierarchy
  244. find . -type f -print0 | xargs -0 du -sb | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

    (for directories just use '-type d' instead of '-type f')

  245. find the largest directories in a hierarchy
  246. du * | sort -n
    or..

    du --max-depth=1 * | sort -n 
    .. or ..

    du --max-depth=1 | sort -n
    ('*' is really redundant)

  247. get list of users in Linux
  248. cat /etc/passwd | cut -d ":" -f1