NOTES ON UBUNTU


1 USEFUL PACKAGES

1.1 Installation

apt-cache -n search <package>
→ search for an available package.
(sudo) apt install <package>
→ install a package.
(sudo) dpkg -i package.deb
→ install from a deb archive. Once it is done, the .deb file can be removed.
(sudo) apt install -f
→ solve dependency issues (fix-broken).
(sudo) apt update
→ refresh the package list.
(sudo) apt upgrade
→ download and update all the packages already installed, as long as it is does not lead to a dependency issue.
(sudo) apt dist-upgrade
→ equivalent to upgrade, but the dependencies are updated, too.
(sudo) apt remove <package>
→ remove a package.
(sudo) apt autoremove
→ remove useless packages (previous version).
(sudo) apt autoclean
→ clean the apt directory.

1.2 PDF

Okular
→ displaying, annotating, printing.
QPDFview
→ displaying a large number of PDF in a single window:
C-TAB
→ next tab;
C-S-TAB
→ previous tab.
PDFsam
→ merging and splitting.
pdfpc
→ beamer presentation.

1.2.1 Processing PDF on the command line

Extracting pages:
qpdf --empty --pages input.pdf 1-10 -- output.pdf
Suppressing the white margins in a figure
pdfcrop. It can also be used to crop arbitrary margins (negative values):
pdfcrop --margins '-left -top -right -bottom' input.pdf output.pdf
Reversing page order:
pdfjam file.pdf 'last-1' --outfile file_reverse.pdf
Merging PDF documents:
pdfunite file1.pdf ... fileN.pdf fileOUT.pdf
Create a booklet:
i.e. from a one page per page PDF, make a landscape 2 pages per page PDF with correct page distribution (just need to fold the stack of paper in two (or cut it in the middle) to have a proper booklet:
pdfbook2 file.pdf

⇒ creates file file-book.pdf.

1.2.2 HTML to PDF Conversion

wkhtmltopdf <file>.html <file>.pdf
→ convert an HTML to a PDF. It is also integrated to Firefox.

1.3 Images

gwenview
→ creating diaporamas.

1.3.1 Processing images on the command line (with ImageMagick)

Convert to another format:
convert input -quality 100% output
Degrade the resolution of an image:
convert input -quality 100% -density 300 output
Reversing the color table:
convert input -channel rgb -negate output
Cropping an image:
once the size of input is know, using identify input, do:
convert input -crop WxH+x0+y0 output
Resizing an image:
convert input -resize 150% output
or:
convert input -resize 300x300 output
Rotate an image:
convert input -rotate 60 output
Make the white parts of an image transparent:
the output must be a PNG:
convert input -fuzz 10% -transparent White output.png
Overlay two images:
convert input_below input_above -geometry +x+y -composite output
Add images side by side horizontally:
convert -append input1 input2 output
Add images side by side vertically:
convert +append input1 input2 output
Add text to an image:
convert -pointsize 50 -fill blue -draw 'text 200,100 "Coucou" ' input output

1.3.2 Making animated GIFs

From a series of frame, by alphabetical order:

convert -delay 20 -loop 0 frame*.png anim.gif
convert anim.gif -coalesce -layers Optimize -compress LZW -strip anim.gif

The last line is used to optimize, slightly reducing the file size.

1.3.3 Get out of this annoying WEBP format

dwebp image.webp -o image.png

1.4 Universal Text File Conversion

Find encoding of a file
file -i file.txt
pandoc
→ convert between ORG, TeX, HTML, ODT, WORD, PPTX, etc.

1.5 Videos

  • Gives info on a video file:

    ffprobre <file>.mp4
    
  • Trim a video:

    ffmpeg -ss 01:30:15 -i <input>.mp4 -to 02:30:15 -c copy <output>.mp4
    

2 SHORTCUTS

2.1 Windows

On dappcz161, the F* keys must be accessed with the fn key.

M-TAB
→ toggle between applications in the current workspace.
M-SPC
→ open the menu of the current window.
M-F2
→ open a command line.
M-F4
→ close the window.
M-F7 arrows
→ move the current window.
M-F8 arrows
→ resize the current window.
M-F10
→ maximize/minimize the current window.
C-M-arrows
→ toggle between workspaces.
C-S-M-arrows
→ move a window in another workspace.
C-M-t
→ open a terminal.

2.2 Special Characters

2.2.1 Main Special Characters

On dappcz161, the COMPOSE key is set as the right control key (in Application → Keyboard → Layout).

COMPOSE-a e:
æ.
COMPOSE-, c:
ç.
COMPOSE-' e:
é.
COMPOSE-` e:
è.
COMPOSE-^ e:
ê.
COMPOSE-" e:
ë.
COMPOSE-^ i:
î.
COMPOSE-" i:
ï.
COMPOSE-~ n:
ñ.
COMPOSE-^ o:
ô.
COMPOSE-o e:
œ.
COMPOSE-s s:
ß.
COMPOSE-` u:
ù.
COMPOSE-^ u:
û.
COMPOSE-" u:
ü.
COMPOSE-/ u:
µ.
COMPOSE-x x:
×.
COMPOSE-. .:
….
COMPOSE-? ?:
¿.
COMPOSE-! !:
¡.
COMPOSE-< <:
«.
COMPOSE-> >:
».
COMPOSE-^ 0 to 9:
⁰ to ⁹.
COMPOSE-_ 0 to 9:
₀ to ₉.
COMPOSE– >:
→.
COMPOSE-< -:
←.
COMPOSE-( x ):
ⓧ where x can be any character.

2.2.2 Unicode Characters

C-x 8 RET <unicode>
→ in Emacs.
C-S-u <unicode>
→ outside Emacs.
  1. Most useful
    C-x 8 RET 00d7 RET:
    ×.
    C-x 8 RET 2260 RET:
    ≠.
    C-x 8 RET 2243 RET:
    ≃.
    C-x 8 RET 226a RET:
    ≪.
    C-x 8 RET 226b RET:
    ≫.
    C-x 8 RET 20ac RET:
    €.

2.2.3 Greek Characters (Unicode)

Unicode 0 1 2 3 4 5 6 7 8 9 A B C D E F
039.   Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο
03A. Π Ρ   Σ Υ Υ Φ Χ Ψ Ω            
03B.   α β γ δ ε ζ η θ ι κ λ μ ν ξ ο
03c. π ρ ς σ τ υ φ χ ψ ω            

2.2.4 Mathematical Symbols (Unicode)

Unicode 0 1 2 3 4 5 6 7 8 9 A B C D E F
220.                
221.                
222.                    
224.                            
226.                    
227.                            
228.                        
229.                        

2.3 Applications

2.3.1 Brave

New window
C-n.
New tab
C-t.
Toggle between tabs
C-TAB (forward) & C-S-TAB (backward).
Reload the page
C-r.
Mark the page
C-d.
Manage bookmarks
C-S-o.
Private window
C-S-n.
Download window
C-j.
Darl readre
M-S-D.

2.3.2 Firefox

New window
C-n.
New tab
C-t.
Toggle between tabs
C-TAB, then arrows.
Reload the page
C-r.
Mark the page
C-d.
Manage bookmarks
C-S-o.
Private window
C-S-p.
Online payment
→ allow cookies.

2.3.3 Terminal

S-up/down
→ page up/down (on dappcz161 use also fn).
C-D
quit.

2.3.4 VLC

SPC
→ play/pause.
f
→ full screen.
a
→ toggle between different aspect ratios.
z
→ zoom.
M-left
→ slow backward.
M-right
→ slow forward.
C-left
→ normal backward.
C-right
→ normal forward.
C-M-left
→ fast backward.
C-M-right
→ fast forward.
C-up
→ volume up.
C-down
→ volume down.
m
→ mute.
C-e
→ adjust audio/video controls.
t
→ show elapsed and remaining times.
+
→ increase the play speed.
-
→ decrease the play speed.
n
→ play the next track.
p
→ play the previous track.
s
→ stop the video
C-h
→ show/hide the controls.

2.3.5 espeak

This is the equivalent of say on Mac

  • espeak "Hello"
  • espeak -vfr "Hello"

3 CUSTOMIZING

3.1 System Settings

Applications automatically launched with a new session
→ files in ~/.config/autostart.
Changing the owner of a directory
sudo chown -R galliano:galliano <répertoire>.
Changing the name of the workspaces
gsettings set org.gnome.desktop.wm.preferences workspace-names "['Code 1', 'Code 2', 'Code 3', 'Text', 'Bureaucracy', 'Mail', 'Web', 'Perso']".
Thunderbird date format
→ edit the variables in /etc/default/locale in order to get:
  • LANG="fr_FR.UTF-8";
  • LANGUAGE="fr_FR:en_US".

3.2 Exploring the Network

List IP addresses or machines connected to the local network
sudo arp-scan -l.
Print info on a machine
nmap -sP <IP>.

3.3 Centralizing Bookmarks and Passwords with Firefox

3.3.1 Create a Firefox account

  1. In Firefox, go to the menu and click on Sync.
  2. Create an account.

This account can be accessed by multiple devices (computers and phones). Passwords, bookmarks and history can be synchronized.

3.3.2 Managing bookmarks

  1. Menu → Bookmarks → Manage bookmarks.
  2. Organize bookmarks in different directories.
  3. Synchronize by clicking on Menu → Sync.

3.3.3 Saving bookmarks

  • Export as HTML.

4 CENTRALIZING PASSWORDS

4.1 GPG Keys

4.1.1 Creating a key

gpg2 --full-gen-key.

  1. Choose RSA and RSA.
  2. Key size: 4096.
  3. Validity: 365.
  4. Name, address and comment (optional).
  5. Enter a secrete phrase (use diceware.py).
  6. At this stage public and private signed keys, as well as a revocation certificate have been signed.
  7. Save the key: gpg2 --export-secret-keys --armor xxxxxxxx.xxxxxxxx@cea.fr > fg-privkey.asc.
  8. Move fg-privkey.asc to another device (secured).

4.1.2 Managing a key chain

Listing a key chain
gpg2 --list-keys. In particular, the second line of the field, pub, gives the ID. Later, <id> can be this ID or the email address (both work).
Exporting a public key on a server
gpg2 --send-key <id> --keyserver <server>.
Adding uid
gpg2 --edit-key <id>.
Checking the fingerprint
gpg2 --fingerprint <id>.
Signing the public key
gpg2 --sign-key <id>.
Changing the expiration date
gpg2 --edit-key <di> expire.

4.1.3 Signing and crypting files with GPG

Signing a file
gpg2 --clear-sign <file>.
Crypting a file
gpg2 --encrypt <file> ⇒ asks for the identity of the recipient and create a crypted copy (binary) <file>.gpg.
Creating a crypted ASCII file
gpg2 --armor --output <file_crypt> --encrypt <file><file_crypt> is an ASCII version of <file>, but crypted.
Decrypting a file
gpg2 --output <file> --decrypt <file>.gpg.
Checking the signature of a file
gpg2 --verify <file>.

4.1.4 Sharing keys between différent machines

  1. On the first machine :: → gpg2 -a --export-secret-key <id> > <key>.asc.
  2. On the second machine :: → gpg2 --allow-secret-key-import --import <key>.asc.

If the transfer of <key>.asc was done using the USB key (vault), no problem, otherwise suppress the file in a secure way : shred --remove <key>.asc.

4.1.5 Display a key

Private key
gpg2 --export-secret-keys --armor xxxxxxxx.xxxxxxxx@cea.fr.
Public key
gpg2 --export --armor xxxxxxxx.xxxxxxxx@cea.fr.

4.1.6 Erase

  1. Erase a public key :: → gpg2 --delete-keys xxxxxxxx.xxxxxxxx@cea.fr.
  2. Erase a private key :: → gpg2 --delete-secret-keys xxxxxxxx.xxxxxxxx@cea.fr.

4.2 Using GPG Keys with SSH

4.2.1 Generate a subkey

gpg2 --expert --edit-key <id>.

  1. gpp> addkey.
  2. (8) ⇒ RSA (give the capacity).
  3. s ⇒ signing capability.
  4. c ⇒ crypting capability.
  5. a ⇒ authetifying capability.
  6. q ⇒ quit.
  7. Size: 4096.
  8. Validity: 365; then yes-yes.
  9. quit.
  10. Sauvegarder la clef (gpg2 --export-secret-subkeys --armor xxxxxxxx.xxxxxxxx@cea.fr > fg-privsubkey.asc) ou tout le répertoire ~/.gnupg.

4.2.2 Configuration for SSH

  1. GPG agent
    1. Create ~/.gnupg/gpg-agent.conf, and add the line: enable-ssh-support
    2. gpg2 -K --with-keygrip ⇒ display the keygrip.
    3. Create ~/.gnupg/sshcontrol and add the keygrip.
  2. BASH profile

    Add in ~/.bashrc :

    export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
    gpgconf --launch gpg-agent
    
  3. Copy the public key distant server
    1. Add a public key :: → ssh-add -L.
    2. Copy on the server :: → ssh-copy-id <server-adress>.

5 PROBLEM SOLVING

5.1 Getting info about the system

Print the Ubuntu version number
cat /proc/version.
System information
uname -a.
Print the number of processors
nproc --all.
List the partitions
sudo fdisk -l or sudo parted -l or lsblk.

5.2 Troubleshooting

Shutting down
sudo shutdown -h.
Restarting
sudo shutdown -r.
Boot partition is full
sudo apt-get autoremove.
Problem with GNOME:
  • sudo apt-get update;
  • sudo apt-get upgrade;
  • sudo atp-get dist-upgrade;
  • sudo apt-get ubuntu-drivers.

5.3 GRUB

sudo grub-install -v
→ install GRUB if it is not already there.
Launching the GRUB
hold Shift during boot.
up/down, then RET
→ choose the OS if several are available.

5.4 Reparing the filesystem

If the filesystem is corrupted.

  1. sudo shutdown -r.
  2. Hold Shift while starting to launch the GRUB.
  3. In the GRUB, select "Recovery mode".
  4. Select "fsck".
  5. Answer yes to the question if the filesystem should remounted.
  6. "Resume normal boot".

BACK

Author: F. Galliano
Last update: 05 janv. 2024