A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Install postgres on Ubuntu 16

How to do it:

  • sudo apt-get install postgresql postgresql-contrib
  • sudo -i -u postgres
  • psql

Docker basics

# Download an image and spin up a container, run it, connect to it

docker pull [name pf image] # download an image

docker run -d -p 80:80 --name pintail-whoami pintailai/pintail-whoami:0.0.1 # download + run

docker run --rm -v /path/on/machine:/app/out image-name:stable params to app

# List running containers

docker ps # show running containers

docker ps | cut -c-$(tput cols) # show running containers without wrapping to the next line

docker ps -q # show just the IDs of the running containers

docker ps -q | head -1 # show ID of most recently started container (how to sort)

# Run a shell on a container

docker run -i -t [Container ID] /bin/bash

# Connect to a shell on an already-runnning docker container.
# (Shell: Use /bin/bash for ubuntu or /bin/ash for alpine)

docker exec -it [Container ID] [shell]

docker exec -it `docker ps -q | head -1` /bin/bash # run shell on the most recently started container

# Copy a file off

docker cp <container>:<src-path> <local-dest-path>

# Delete all stopped containers and images

docker system prune -a

# List all images

docker image ls

Easily save music playlists from Youtube on Ubuntu

git clone https://github.com/rg3/youtube-dl.git
cd youtube-dl
./youtube-dl 'https://www.youtube.com/playlist?list=PL517964F9D64C8D0B' --ignore-errors --extract-audio --audio-quality 0 --audio-format mp3 --prefer-ffmpeg --output '%(playlist_index)s - %(title)s.%(ext)s'

(source, source)

...but then the mp3 files have the wrong length and can't be fast forwarded properly in many players (youtube-dl 2014.04.30.1)

To fix them:

sudo apt-get install vbrfix
cd /path/to/mp3s
find . -type f -iname '*.mp3' -exec vbrfix {} {} \;
rm vbrfix.log vbrfix.tmp

(source, source)

Ubuntu graphics drivers decided to break

HP EliteBook 8460p

Apparently I have an ATI Radeon graphics card, I only know this because Ubuntu 13.04 failed to use it to display X11 after an update one day. I could get to a command prompt but X11 would not start.

After much research, I concluded that I had to run this to get it working again:

sudo apt-get install fglrx fglrx-amdcccle

But after that my second monitor didn't work, and also whenever I disconnect the laptop from the docking station, the screen shows a mess of wiggly lines and I have to reboot.

(source, source, source)

UPDATE: Someone suggested using the built-in Intel Core i7 Pro graphics card instead, one way is to disable the ATI driver in the BIOS, another is to disable via modprobe blacklist, apparently there are easy instructions on the Ubuntu wiki.

When I tried this, the functionality was even worse: No multiple monitors.

How to set network proxy from command line in Ubuntu

You might need to do this if your network settings dialog box crashes as I've seen on Ubuntu 13.10:

gsettings set org.gnome.system.proxy autoconfig-url http://myserver/myconfig.pac
gsettings set org.gnome.system.proxy mode auto

This is how I found out the settings:

$ for key in $(gsettings list-keys org.gnome.system.proxy); do echo $key = $(gsettings get org.gnome.system.proxy $key); done

autoconfig-url = 'http://myserver/myconfig.pac'
ignore-hosts = ['localhost', '127.0.0.0/8']
mode = 'auto'
use-same-proxy = false

It doesn't have to be a .pac file, ours is .dat.

(source)

Enforcing breaks away from the screen

There's a need to interrupt oneself, to avoid spending too much time constantly staring at the screen/sitting down, etc. to prevent RSI, eye strain, back injury, etc.
  • RSIBreak - Looks promising, but falls prey to multi-monitor taskbar bug and is hidden behind taskbar, also greying out of screen doesn't work. And doesn't seem to always alert me. And "lock screen" button doesn't work. Nor does "run on startup". (Ubuntu 12.04).
  • Workrave - In some ways looks better than RSIBreak. Easier to configure/understand notification times, has numbers countdown instead of a clock, and suggests exercises to do in the breaks. But it doesn't match up small breaks with long breaks like RSIBreak does, so it often pops up an alert soon after I've just taken a break.


Query installed packages on Ubuntu

Ubuntu uses debian packages, not RPMs so yum isn't relevant.

List all packages:
dpkg-query -l

Display summary info for a package:
dpkg-query -s package_name

Display files installed by a package:
dpkg-query -L package_name

Upgrade Ubuntu 12.04 to 12.10

Change the 'Update Manager' settings to notify you of any new Ubuntu versions (source).

Sound systems in Ubuntu

May have to fiddle with all of these to make sound work correctly:
  • pulseaudio
  • alsamixer
  • sound settings
  • skype sound devices

How to view .msg files on Ubuntu

wget http://www.matijs.net/software/msgconv/msgconvert.pl
sudo apt-get install libemail-outlook-message-perl
sudo apt-get install libemail-localdelivery-perl
perl msgconvert.pl YourMessage.msg

Thanks to this software

How to install CPAN Perl modules on Ubuntu using apt-get package manager

script:

PACKAGE=$(echo "$1" | perl -e '$x=<>; chomp($x); $x=~s/::/-/g; $x=lc($x); print "lib$x-perl"')
sudo apt-get install $PACKAGE

Thanks

Configuring Ubuntu

After upgrading from Ubuntu 11.04 (Natty Narwhal) to 12.04.2 (Precise Pangolin), I couldn't make my original account log in to gnome. So I had to copy over all the settings to a new user account. Also, a number of things are different in Ubuntu 12.
  • To bypass Unity, select 'Ubuntu classic' window manager at login screen
  • In Synaptic package manager, find overlay-scrollbar and uninstall it, then reboot
  • There is no top-level settings menu like 11.04, instead look under the Applications menu
  • Gedit: Set tab width to 4, insert spaces instead of tabs, and use automatic indentation
  • Nautilus: Edit | Preferences | Views (tab) | View new folders using: List View
  • Increase terminal buffer to 'unlimited'
  • Copy over SSH keys:
    • cp -rp ~olduser/.ssh ~newuser/
  • Install chromium, copy settings from chrome:
    • sudo cp -Rp ~olduser/.config/google-chrome/ ~newuser/.config/chromium/
  • Install Thunderbird 24 + Lightning calendar plugin, copy user profile across
    • mv ~newuser/.thunderbird/axhtibx7.default{,.backup}
    • sudo cp -Rp ~olduser/.thunderbird/sw5u8ylf.default ~newuser/.thunderbird/axhtibx7.default
    • The 'Accept' button is missing for some event invites
      • "This message contains an event that this version of lightning cannot process"
      • This is a bug (reported and fixed via developer's patch)
    • Sort by 'Received' and 'Threaded' to get threads ordered by last received message
  • Install Firefox, copy user profile:
    • mv ~/newuser/.mozilla/firefox/ce3ut43x.default{,.backup}
    • cp -rp ~oluser/.mozilla/firefox/ra129tce.default/ ~/newuser/.mozilla/firefox/ce3ut43x.default
  • Install Pidgin for IRC, copy config across:
    • cp -rp ~olduser/.purple/ ~newuser/
    • Error, Pidgin crashes with "SIGSEGV in pthread_mutex_lock()"
    • So, re-set up pidgin for all networks
    • Disable smileys as they intefere with pasted code:
      • Tools | Preferences | Themes | Smiley Theme | None
  • Install VirtualBox, go to "Machine | Add", and browse to your VM on disk
  • Install Skype 4.0.0.8, because 4.2.x crashes on incoming calls:
    • Type Ctrl-O to reach the options screen to set the proxy in 4.2.x (source)
    • Disable 'contact online' and 'contact offline' notifications because of this
    • Skype has no sound, in fact Ubuntu has no sound:
      • killall pulseaudio (sourcesource)
      • restart Skype (may need to "kill -9 skype")
  • To find the exact version of Ubuntu I'm running:
    • This only shows 12.04: Applications | System Tools | System Settings | Details
    • This command tells you the exact version (12.04.3):
      • lsb_release -a
  • Configure multiple workspaces:
    • Right-click in the bottom-right-hand corner and edit preferences (source)
    • Still can't actually switch workspaces though without the screen freezing up.
    • Hold Ctrl-Alt-Del for 5 seconds to get back.
  • Fix Alt-tab:
    • sudo apt-get install compizconfig-settings-manager
    • Scroll to bottom, check 'Static application switcher' (source)
  • Fix the date display:
    • Use dconf-editor | com | canonical | indicator | appmenu | datetime (source)
  • I get "Ubuntu internal error" sometimes, that never happened under 11.04.
  • Beware of cancelling a logout. An application preventing the logout may eventually crash or close, and the logout will happen at that point without further warning.
  • Problem: Sound comes out of both the laptop speakers and the headphones at the same time.
  • Problem: Workspaces don't work properly. Cannot right-click on window's title to send it to a new workspace. Clicking on a new workspace in the bottom right doesn't work.
  • Problem: The top and bottom taskbars are visible even when the screen is locked, when using multiple monitors (bug report).

Fix debian/ubuntu gpg error when updating package sources


When updating the Debian based system, apt-get may display an error message like:

W: GPG error: ftp://ftp.debian.org/ testing Release:       
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 010908312D230C5F      

W: There is no public key available for the following key IDs:      
010908312D230C5F

The same problem in Synaptic package manager appears as:

W: Failed to fetch http://http.us.debian.org/debian/dists/sid/InRelease  
W: Failed to fetch http://http.us.debian.org/debian/dists/sid/Release.gpg

Unable to connect to http.us.debian.org:http: [IP: 128.30.2.36 80]

This is a feature of the apt-get system that guarantees the authenticity of servers for updating Debian.

Simply type the following commands, taking care to replace the number below with that of the key that was displayed in the error message:
gpg --keyserver pgpkeys.mit.edu --recv-key  010908312D230C5F      
gpg -a --export 010908312D230C5F | sudo apt-key add -

Copy+pasted from here

Why doesn't smbclient work?

Symptoms:
You can mount a NetApp 'shared drive' using the mount program fine.
But if you try to browse it using smbclient, you get this error when it fails to connect:
session setup failed: NT_STATUS_MORE_PROCESSING_REQUIRED

Cause:
A bug in Ubuntu 11.04

Workaround:
Change your hostname to a short string, without any hypens (dashes) in it!

(copy)

Fix hanging network-manager applet in Ubuntu 11.04

#!/bin/bash

# Fix the frozen network-manager applet
# Thanks to http://askubuntu.com/questions/23611/network-manager-applet-menu-freezes-and-does-not-respond

killall nm-applet
sudo /etc/init.d/network-manager restart
nm-applet &> /dev/null &

How to manage problematic application windows in Ubuntu

In Ubuntu:

To find out what application a window belongs to: Type xwininfo in the console, then click on the window.

To kill a window, type xkill in the console, then click on a window to kill it.


Ubuntu: Remove Unity and overlay scrollbars

1. Select 'Ubuntu classic' instead of 'Ubuntu' at the login screen

2. sudo apt-get remove overlay-scrollbar

Which version of Ubuntu?

Which version of Ubuntu should I install?

  • 11.04 - Yes! This works fine.
  • 11.10 - No. The menus are borked.

These are all the lovely settings you're missing in >11.04:

System preferences:



System administration:



Control centre:

Email clients on Ubuntu

Linux email clients for Microsoft Exchange:
  • Evolution: Ugh. Clunky. Hangs.
    • "Microsoft Exchange" server type screen scrapes webmail
    • MAPI needs the 'evolution-mapi' package from Ubuntu software centre
    • Otherwise IMAP
  • Thunderbird: Pfft. Also clunky. Hangs slightly less than Evolution, sometimes.