Linux

Table of Contents

One of the most wired error I had (multiple times) is that, my dist is full. Then I cannot log into my account. Hopefully the home partition is separate from root partition, I can still log into root to discover this thing.

One of the situation I encountered is the xsession-errors file is more than 400G.

1 Files

In Unix, everything is a file.

/etc/X11/rgb.txt
rgb file

2 System

iostat
to monitor the IO usage. (from sysstat package)
id
show the group information of current user
dmesg
kernel log
/proc/cpuinfo
the file describing CPU

3 Shell Interaction

Ctrl-s
stop the screen
Ctrl-q
recover the screen
Shift-pageup/down
page up & down
shift-Insert
paste
Ctrl-l
clear

4 App

  • File explorer: konquerer
  • Image viewer: feh

setting the wallpaper by:

feh --bg-fill /path/to/wall/paper

And load previous setting by:

sh ~/.fehbg &
  • image processing: graphicsmagick, imagemagick

4.1 Speech recognition engines

gnustep-gui-runtime
say "hello" It is not working yet
festival
echo "hello" | festival --tts The speech is pretty smooth
speech-dispatcher
spd-say "hello" quality is not that good
espeak
espeak "hello" quality is not that good

4.2 mplayer

Interactive controls:

LEFT/RIGHT
10 sec
UP/DOWN
1 min
PGUP/PGDWN
10 min
[]
playback speed by 10%
{}
half/double speed
BACKSPACE
reset playback speed
/*
volume
SPACE
pause
f
toggle fullscreen
o
OSD

When changing the speed, the pitch changed. To disable this, start mplayer by mplayer -af scaletempo.

To stretch the images to full screen, pass the -zoom option when starting.

4.3 youtube-dl

When downloading a playlist, you can make the template to number the files

youtube-dl -o "%(playlist_index)s-%(title)s.%(ext)s" <playlist_link>

5 Prompt

  • prompt($PS1-4)
    • \d: date
    • \D{format}
    • \h: hostname
    • \H: full hostname
    • \t: time 24hour HH::MM::SS
    • \T: time 12hour HH::MM::SS
    • \@: time 12hour am/pm
    • \A: time 24hour HH::MM
    • \w: current working directory
    • \W: basename of $PWD

5.1 escape color

  • 1: bold
  • 4: underline
  • 30-37: black, red, green, yellow, blue, pink, cyan, white
  • 40-47: background
  • 90-97: light
  • 100-107: light background

example:

  • \033[1;4;32;45m
  • \e[32;45m
  • \e[0m

in PS1, use:

  • \[\033[32;45m\]

6 Job control

  • C-z to suspend.
    • top, then you can see the CPU usage and all process IDs. Simply press k and enter the PID can kill the process.
  • refer a job
    • %n: job number
    • %%: current job
    • %+: current job
    • %-: previous job
    • %: current job
    • %ce: the job "ce"
    • %?ce: the job, whose command has "ce"

Some commands:

jobs
list all background jobs
fg %1
continue it in foreground
bg %1
continue it in background
kill %1
kill the job (first)

7 Install fonts

  • OTF: OpenType
  • TTF: TrueType
  • EOT: Embedded Open Type
  • WOFF: Web Open Font Format

To install:

cp *.otf ~/.fonts
sudo fc-cache
fc-list

8 Power management

No extra software needed! systmed can handle it, by acpid. The configure file is /etc/systemd/logind.conf. man logind.conf for details.

HandlePowerKey=hibernate
HandleLidSwitch=suspend

hibernate will save to disk, while suspend save to ram. Both of them will resume to the current status.

9 Grub

9.1 Introduction

Use grub 2 instead of grub legacy. For a quick look at what they look like:

Grub Legacy boot/grub/menu.lst:

title           Debian GNU/Linux
root            (hd0,2)
kernel          /vmlinuz root=/dev/hda3 ro
initrd          /initrd.img

Grub 2 /boot/grub/grub.cfg:

menuentry "Debian GNU/Linux" {
        set root=(hd0,3)
        linux /vmlinuz root=/dev/hda3
        initrd /initrd.img
}

Note that the root is (hd0,2) in grub legacy vs. (hd0,3) in grub 2.

9.2 Grub 2

The menu configure file is located at /boot/grub/grub.cfg. It is generated by /usr/sbin/update-grub (8) using templates from /etc/grub.d/* and settings from /etc/default/grub.

10 Run level

Use debian as example distribution.

The default run level is 2, corresponding to /etc/rc2.d/XXX scripts. By default there's no difference between level 2 to 5.

10.1 Run level description

  • 0: halt
  • S: single user mode on boot
  • 1: single user mode, switched from multi-user mode
  • 2: multi-user mode
  • 3,4,5
  • 6: reboot
  • telinit(8) can change the run level dynamically.
  • runlevel(8) check current run level

Those scripts starts with "S" or "K" meaning start or stop sent to systemd utility. Those scripts are symbol linked to ../init.d/xxx.

11 LDLIBRARYPATH

On CentOS, the default LD_LIBRARY_PATH does not contains the /usr/local/lib. The consequence is the -lpugi and -lctags are not recognized because they are put in that directory. Set it, or edit /etc/ld.conf.d/local.conf and add the path. After that, run ldconf -v as root to update the database.

Also, the error:

Linux error while loading shared libraries: cannot open shared object file: No such file or directory

is also because the cache is not updated. So the solution is sudo ldconfig

12 Networking using NetworkManager

Install network-manager package, and:

Start the service

systemctl enable NetworkManager

change /etc/NetworkManager$/NetworkManager.conf to:

[ifupdown]
managed=true

restart

systemctl restart NetworkManager

12.1 add a wifi connection

nmcli device wifi list
nmcli device wifi connect IASTATE
nmcli device wifi connect ID password pwd

13 Remove viewer

The lab machines are accessed via spice. The client for spice is virt-viewer. It can be installed through package manager. The actual client is called remote-viewer, which is shipped with virt-viewer. So the command to connect to the .vv file: remove-viewer console.vv.

14 File Management

14.1 Swap File

A swap file can also be used as swap memory. When doing linking, the ld might fail because of lack of memory.

Check the current swap:

swapon -s

Create swap file:

dd if=/dev/zero of=/path/to/extraswap bs=1M count=4096
mkswap /path/to/extraswap
swapon /path/to/extraswap
swapoff /path/to/extraswap

This will not be in effect after reboot. To automatically swap it on, in /etc/fstab

/path/to/extraswap none swap sw 0 0

15 Drivers

I was installing drivers for my RX470 on Debian strench. The good news is it works out of box, I guess using xserver-xorg-video-amdgpu. However the temperature is 58 idle.

To fix that, I tried to install the newest driver, the amdgpu-pro. It does not support Debian officially, although I can modify the install script to pass the system test (it tests Ubuntu or steam). The installation script failed, but leaves me with the /var/opt/amdgpu-pro-local repo, which is also visible by apt. All the things can be removed by running amdgpu-pro-uninstall. Installing amdgpu-pro package will fail the machine, and you will not be able to log in again. The integrated graphic card would still work to log in and fix this but unless you have one, don't try it … Installing xserver-xorg-video-amdgpu-pro seems did gives me a temperature of 50, much better ..

Of course, the fan on the GPU is spinning all the time even if I use integrated graphic. The RGB lighting is not going to be customize-able.

16 Encoding

When converting MS windows format to unix format, you can use emacs and call set-buffer-file-coding-system and set to unix. Or you can use dos2unix, perhaps by

find . -name *.java | xargs dos2unix

Author: Hebi Li

Created: 2017-06-14 Wed 22:42

Validate