Linux
Table of Contents
- 1. Network
- 2. Trouble Shooting
- 3. Files
- 4. System
- 5. Shell Interaction
- 6. App
- 7. Prompt
- 8. Job control
- 9. Install fonts
- 10. Power management
- 11. Grub
- 12. Run level
- 13. LDLIBRARYPATH
- 14. Networking using NetworkManager
- 15. Remove viewer
- 16. File Management
- 17. Drivers
- 18. Encoding
- 19. Kernel Developers
There's a separate page for some Installation related issues. A page about samba.
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.
- Debian Wiki: https://wiki.debian.org/
- FreeBSD: https://www.freebsd.org/
1 Network
To resolve a name to IP address, you can add it into
/etc/hosts
. E.g. at the end of the file, add:
172.18.0.2 srcml-server-container
The scenario to use this is that host system cannot resolve the name of container to the specific IP. I have to specify it manually.
ifconfig
is in net-tools
package, and is deprecated. Use ip
instead:
ip addr show <dev> ip link # show links ip link show <dev>
2 Trouble Shooting
2.1 Cannot su root
When su cannot change to root, run
chmod u+s /bin/su
2.2 in docker, cannot open chromium
failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted.
Solution
chromium --no-sandbox
3 Files
In Unix, everything is a file.
/etc/X11/rgb.txt
- rgb file
4 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
- hostname -i: print host ip addr
5 Shell Interaction
Ctrl-s
- stop the screen
Ctrl-q
- recover the screen
Shift-pageup/down
- page up & down
shift-Insert
- paste
Ctrl-l
- clear
6 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
6.1 Speech recognition engines
gnustep-gui-runtime
say "hello"
It is not working yetfestival
echo "hello" | festival --tts
The speech is pretty smoothspeech-dispatcher
spd-say "hello"
quality is not that goodespeak
espeak "hello"
quality is not that good
6.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.
6.3 unzip
-q
: quiet-d folder
: output to that folder
Cannot rename the content, must mv after extraction.
6.4 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>
Download music only:
youtube-dl --extract-audio --audio-format flac <url>
6.5 VNC
I use tigervnc because it seems to be fast.
- vncpasswd: set the password
- vncserver&: start the server.
- It is started in :1 by default, so connect it with
vncviewer <ip>:1
- On mac, the docker bridge network does not work, so you cannot connect to the contianer by IP addr. In this case, map the port 5901. 5900+N is the default VNC port.
- vncserver -kill :1 will kill the vncserver
- vncserver :2 will open :2
- It is started in :1 by default, so connect it with
6.6 mpd
music play daemon
To start:
mkdir -p ~/.config/mpd cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf mkdir ~/.mpd/playlists
# Required files db_file "~/.mpd/database" log_file "~/.mpd/log" # Optional music_directory "~/music" playlist_directory "~/.mpd/playlists" pid_file "~/.mpd/pid" state_file "~/.mpd/state" sticker_file "~/.mpd/sticker.sql" # uncomment pulse audio section audio_output { type "pulse" name "My Pulse Output" }
Start mpd by:
systemctl --user start mpd systemctl --user enable mpd
6.6.1 Clients
- gmpc
- stumpwm contrib mpd
7 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
7.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\]
8 Job control
C-z
to suspend.top
, then you can see the CPU usage and all process IDs. Simply pressk
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)
9 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
10 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.
11 Grub
11.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.
11.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
.
12 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.
12.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
.
13 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
14 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
14.1 add a wifi connection
nmcli device wifi list nmcli device wifi connect IASTATE nmcli device wifi connect ID password pwd
15 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
.
16 File Management
16.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
16.2 Back Up & Syncing
16.2.1 rsync
This commnad is used to sync from source to destination. It does not perform double way transfer. It decides a change if either of these happens:
- size change
- last-modified time
rsync [options] src dst
Available options
-v
: verbose-h
: human readable message-z
: compress-r
: recursively-a
: archive mode: preserve symblic links, file permissions, timestamps-e ssh
: use ssh--progress
: show progress--include <regex>
--exclude <regex>
--delete
: DANGEROUS if dst has more than src, delete those on dst--max-size='200k'
: set the size limit for each file--dry-run
: dry run
Commonly used options: vhzra
dry-run
Remember to use a
option, otherwise the dst will always have newer
(thus different) timestamp, and you will do the copy all the time.
17 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.
18 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
19 Kernel Developers
- Linus Torvalds
- Steve Rostedt
- Sarah Sharp
- Greg Kroah-Hartman
- Alan Cox
- Dave Jones
- Jean Delvare
- Arnd Bergmann
- Herbert Xu
- Arnd Bergmann
- Jes Sorensen
- Jonathan Corbet