Linux Basic Configuration and Operation (1)

Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100 mph.
                                     —— Linus Torvalds

linux.png

[*] Caution: This blog is written for Debian/Ubuntu, and it is not suit to other Linux distribution, such as Fedora/CentOS.

Basic Operation

Root & User

1
2
3
$ sudo passwd root  # new or modify password of root
$ su root # use permission of root
$ su user # use permission of user

Shut Down & Restart

The following multiple lines of command is common to turn off computer.

1
2
3
4
5
6
$ halt                                      # shut down immediately 
$ poweroff # shut down immediately
$ systemctl poweroff # shut down immediately
$ shutdown -h now # shut down immediately
$ shutdown -h 0 # shut down immediately
$ shutdown -h [Num] # shut down after Num minutes

The following multiple lines of command is common to restart computer.

1
2
3
4
5
$ reboot                                    # restart immediately
$ systemctl reboot # restart immediately
$ shutdown -r now # restart immediately
$ shutdown -r [Hours:Minutes] # restart in Hours:Minutes
$ shutdown -c # cancel shutdown command

Suspend & Hibernate

Suspend and sleep have the same meaning, which mean that turn off all peripherals and only keep cpu and memory running. And press Fn multiple times to exit the suspend state.

1
2
$ sudo pm-suspend               # valid
$ sudo systemctl suspend

Standby mode means that save state to memory and turn off other devices, especially it resumes slower than suspend but faster than hibernate.

1
2
$ sudo pm-suspend-hybrid        # valid
$ sudo systemctl hybrid-sleep

Hibernate means that save state to disk and turn off all devices, which resumes slower than the above two states.

1
2
$ sudo pm-hibernate             # valid
$ sudo systemctl hibernate # invalid

Change Hostname

1
2
3
$ su root
# vim /etc/hostname
$ reboot

File Management

1
2
3
4
5
6
7
$ mkdir [Path]                              # new path
$ rmdir [Folder] # remove empty folder
$ rmdir -rf [Folder] # remove non-empty folder
$ cp [File] [BackupFile] # back up file as copy
$ rm [File_1] [File_2] ... [File_n] # remove file
$ mv [File] [Path] # move file to path
$ mv [FileName] [NewName] # change filename

Task Management

Manage task by using CLI.

1
2
3
4
5
$ ps -A                                     # list all process
... ...
$ kill -9 [PID] # kill process forcibly by PID
$ killall -9 [ProcessName] # kill process forcibly by name
... ...

Manage task by using GUI, if Gnome is exist.

1
$ gnome-system-monitor                      # call Task Manager

Gnome Management

Press Alt + F2, then typing r could restart Gnome.

Package & Zip & Unzip

.tar

1
2
$ tar xvf [FileName.tar]                    # untar
$ tar cvf [FileName.tar] [DirName] # package

.gz

1
2
3
$ gunzip [FileName.gz]                      # unzip-1
$ gzip -d [FileName.gz] # unzip-2
$ gzip [FileName] # zip

.tar.gz & .tgz

1
2
$ tar zxvf [FileName.tar.gz]                # unzip
$ tar zcvf [FileName.tar.gz] [DirName] # zip

.bz2

1
2
3
$ bzip2 -d [FileName.bz2]                   # unzip-1
$ bunzip2 [FileName.bz2] # unzip-2
$ bzip2 -z [FileName] # zip

.tar.bz2

1
2
$ tar jxvf [FileName.tar.bz2]	            # unzip
$ tar jcvf [FileName.tar.bz2] [DirName] # zip

.bz

1
2
$ bzip2 -d [FileName.bz]                    # unzip-1
$ bunzip2 [FileName.bz] # unzip-2

.tar.bz

1
$ tar jxvf [FileName.tar.bz]                 # unzip

.Z

1
2
$ uncompress [FileName.Z]                   # unzip
$ compress [FileName] # zip

.tar.Z

1
2
$ tar Zxvf [FileName.tar.Z]                 # unzip
$ tar Zcvf [FileName.tar.Z] [DirName] # zip

.zip

1
2
$ unzip [FileName.zip]                      # unzip
$ zip [FileName.zip] [DirName] # zip

.rar

1
2
$ rar x [FileName.rar]                      # unzip
$ rar a [FileName.rar] [DirName] # zip

Swap Space

View current swap file.

1
2
$ cat /proc/swaps
Filename Type Size Used Priority

New a swap file and configure it.

1
2
3
4
5
6
7
8
9
10
$ swapfile=/mnt/4GiB.swap
$ sudo root
# fallocate -l 4g $swapfile
# chmod 600 $swapfile
# mkswap $swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=45308b8a-1ff1-4975-8bbe-7606c8cd9d4e
# swapon $swapfile
# echo '/mnt/4GiB.swap swap swap defaults 0 0' | sudo tee -a /etc/fstab
/mnt/4GiB.swap swap swap defaults 0 0

View swap file again.

1
2
3
4
5
6
7
$ cat /proc/swaps
Filename Type Size Used Priority
/mnt/4GiB.swap file 4194300 0 -1
$ free -h
total used free shared buff/cache available
Mem: 2.0G 1.1G 178M 58M 646M 565M
Swap: 4.0G 0B 4.0G

Modify System Font

Install

Install font file, take consola as an example.
And download suitable font file from here to linux.

1
2
$ unzip YaHei.Consolas.1.12.zip                                     # unzip font file
$ mv YaHei.Consolas.1.12.ttf consola.ttf

Activate

You should add it to the system font file and activate it, if you want to uing it for the system instead of one program.

1
2
3
4
$ sudo mkdir /usr/share/fonts/consola/                              # make folder for font file
$ sudo cp Fonts/consola.ttf /usr/share/fonts/consola/
$ cd /usr/share/fonts/consola/
$ sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv # activate font file

Input Method

IBus Pinyin & XIM Pinyin

As me, ibus-pinyin is more easy to use than google-pinyin.

  1. If language of os is English, it is necessary that install 'ibus-pinyin' or 'fcitx-pinyin'.
1
2
$ sudo apt-get install ibus-pinyin
$ sudo apt-get install fcitx-pinyin # It's not necessary
  1. Click Setting -> Region & Language -> Manage Installed Languages

  2. Select Keyboard input method system = IBus -> Install / Remove Languages... -> Chinese(simplified) -> Apply

  3. Reboot os.

1
$ reboot
  1. Click Setting -> Region & Language -> Input Sources -> Chinese(Intelligent Pingyin)

  2. Configure sth such as switching mode in Preferences.

ibus-preferences.png

Google Pinyin

  1. Open input method configuration.

    1
    $ im-config
  2. Select OK -> Yes -> fcitx & OK -> OK

    1
    2
    3
    $ sudo apt install fcitx-googlepinyin
    $ reboot
    $ fcitx-config-gtk3
  3. After adding Google Pinyin is ok.

Change Sources

Back Up older

1
2
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak   # back up old sources 
$ sudo rm /etc/apt/sources.list # remove old sources

Edit Newer

1
$ sudo vim /etc/apt/sources.list                            # edit new sources
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# /etc/apt/sources.list
# from aliyun_sources
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

You can also use the following code.

1
2
3
4
5
6
7
8
9
10
11
12
# /etc/apt/sources.list
# from aliyun_sources
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

Update

1
$ sudo apt-get update                                       # update sources

Package Manager - apt & snap

apt

Normally, the command apt = ( apt-get | apt-cache | apt-config ), although apt has new usage. In other words, you just need to use the command apt in most of the time when using Ubuntu OS.

1
2
3
4
5
6
7
8
9
10
$ sudo apt install [SoftwarePackage]                        # install
$ sudo apt remove [SoftwarePackage] # remove
$ sudo apt remove --purge [SoftwarePackage] # remove package & configuration
$ sudo apt search [SoftwarePackage] # search
$ sudo apt list --installed # show packages that are installed
$ sudo apt list --upgradeable # show packages that are able to upgrade
$ sudo apt update # update
$ sudo apt upgrade # upgrade
$ sudo apt autoremove # remove some packages, which were used to as dependence of other packages formely but are not useful now
$ sudo apt autoclear # remove some old packages of installed software

snap

Accroding to my experience, the software packages will be managed by the manager - 'snap', if they are installed by the UGI Installer - 'Ubuntu Software', and you can find they in /home/user/snap. Actually, installing by the command snap directly is also able.

1
2
3
4
$ sudo snap list
$ sudo snap find [SnapName]
$ sudo snap install [SnapName]
$ sudo snap remove [SnapName]

Solution about a Problem:

Unable to install "XXX" | error: snap "YYY" has "install-snap" change in progress

1
2
3
4
5
6
7
$ snap changes
ID Status Spawn Ready Summary
... ... ...
13 Doing today at 20:55 CST today at 20:58 CST Install "YYY" snap
... ... ...
$ sudo snap abort 13
$ sudo snap install YYY

Update System

If your system is Ubunntu 16.04 LTS, and the machine hasn't powerful hardware resources, such RAM, I'll suggest update system to Ubuntu 18.04 LTS by conmand lines instead of re-installing.

Keep your Ubuntu-16.04LTS is newest.

1
2
3
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade

Start to update system, and make your selection carefully based on the following tips.

1
$ sudo do-release-upgrade

Make Start Disk

GUI Way

A simple way is to using 'Startup Disk Creator' if you have it, or you could install it from 'Ubuntu Software'. And using CLI way is also valid.

startup-disk-creator.png

CLI Way

Download system image that you need, such as Ubuntu 18.04.1 LTS DeskTop.

1
2
3
$ cd ~/Downloads/
$ ls
ubuntu-18.04.1-desktop-amd64.iso

Show all the storage device and find your USB.

1
2
3
4
5
6
7
8
9
$ sudo fdisk -l
... ...
Disk /dev/sdb: 7.5 GiB, 8011120640 bytes, 15646720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcad4ebea
... ...

Format USB and change form of it to FAT.

1
2
$ sudo umount /dev/sdb*
$ sudo mkfs.vfat /dev/sdb -I

Make start USB.

1
$ sudo dd if=~/Downloads/ubuntu-18.04.1-desktop-amd64.iso of=/dev/sdb

Broswer - Chromium

Download and install Chrome for 64-bit os.

1
2
3
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo dpkg -i google-chrome-stable_current_amd64.deb
$ rm google-chrome-stable_current_amd64.deb

Add source of software and install Chromium for 64-bit os.

1
2
3
$ sudo add-apt-repository ppa:chromium-daily
$ sudo apt-get update
$ sudo apt-get install chromium-browser

GUI SSR - electron-ssr

Download

Download the latest version .deb file from erguotou520/electron-ssr (another valid address). And you can learn more about the project by reading this blog.

1
2
3
$ cd ~/Downloads
$ ls
electron-ssr-0.2.5.deb

Dependence

Associate local python package.

1
2
3
4
$ su root
# apt-get install --reinstall python
# apt-get -f install
$ su user

Install necessary library - libappindicator1 & libsodium.

1
2
3
4
5
6
7
$ sudo apt-get install libappindicator1 # maybe you need execute 'apt-get -f install' command by using root permission
$ sudo apt-get install build-essential
$ wget https://github.com/jedisct1/libsodium/releases/download/1.0.15/libsodium-1.0.15.tar.gz
$ tar xf libsodium-1.0.15.tar.gz
$ cd libsodium-1.0.15
# ./configure && make -j2 && make install
# ldconfig

Install

Install electron-ssr.

1
2
3
$ cd ~/Downloads
$ sudo dpkg -i electron-ssr-0.2.5.deb
$ export http_proxy="http://127.0.0.1:12333"

Configure

Paste subscription link if you have. And you also can add VPN node.

Q & A

It probably to meet this following error when using command apt or apt-get on Ubuntu.

1
2
E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

In fact, there is a similar error you may see:

1
2
3
4
E: Could not ge lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

There could be many reasons why you see this error. The first and most obvious reason is that some other process is using APT package management tool.

The following command will show the id of process running apt or apt-get. Byt the way, the last line contains ‘grep –color=auto’ is your current process, which mustn't be killed.

1
$ ps -aux | grep apt

Using kill command to kill some process.

1
$ sudo kill -9 <PID>

The killall command is also valid.

1
$ sudo killall apt apt-get

Click this link to see more.


Unfinished