Basic Linux Guide

该指南涵盖了Ubuntu操作系统的基础知识,包括使用.desktop文件创建应用快捷方式,22.04版本中添加拼音输入法的步骤,理解文件系统结构,Bashshell的命令行操作,如路径导航、文件管理及权限设置,用户和组管理,进程管理和编辑器vim的使用,以及环境变量和软件管理。此外,还涉及网络测试工具和归档备份方法。
摘要由CSDN通过智能技术生成

Normal Ubuntu User Guide!

Concepts

  • Everything is file.

  • Open source.

Useful knowledge

.desktop file - short icon

A .desktop file is simply a shortcut that is used to launch applications
in Linux. Without the .desktop file, your application won’t show up in
the Applications menu and can’t be launched with third-party launchers
such as Ulauncher and Albert

# create desktop file
# Store .desktop file to .local/share/applications/ 

[Desktop Entry]
Type=Application
Name=Personal File
Exec=/home/user/file
Icon=gedit

add pinyin

Note: These instructions are ONLY meant for vanilla Ubuntu and ONLY for 22.04 for basic pinyin input for simplified characters.

Ubuntu has never provided an easy, well-documented option for adding
pinyin input support. However, to get basic pinyin support in 22.04 you
can simply:

  1. Open Settings, go to Region & Language -> Manage Installed Languages -> Install / Remove languages.
  2. Select Chinese (Simplified). Make sure Keyboard Input method system has Ibus selected. Apply.
  3. Reboot
  4. Log back in, reopen Settings, go to Keyboard.
  5. Click on the “+” sign under Input sources.
  6. Select Chinese (China) and then Chinese (Intelligent Pinyin).

You should now have a little “en” (or whatever the language code of your Ubuntu install is) at the top right of your main screen which you can click on and get a list of available input methods, including Chinese (Intelligent pinyin).
Open anything that can receive text (like gedit, openoffice, vim, FF,…) and try it out. You can also change between them with Super/Win + space.

  1. Reboot to make sure it is still there after a reboot.
  2. Be happy that you didn’t lose any more time on this ridiculously trivial issue that is still a massive pain in 2022!

If you don’t need extra bells and whistles then do NOT bother with fcitx (and the supposedly excellent “google pinyin”), uim or any other exotic option! They are extremely hit-and-miss trying to install, and finding a guide that is relevant to 22.04 is almost
impossible. Some claim to have “tested with 22.04” but they have done upgrades of previous versions that they had working, not fresh installs.

File System

Concepts

  • Just one file tree.

  • Disk is mounted under any directory.

Disk

# report file system disk space usage
$ df -hT

# display a list of the file systems currently mounted
$ mount

# Mount some device on a new directory
$ mount -t _fs_type _source _diretory

# Unmount a device 
$ umount _source

Struct

SCOPE + CATEGORY + APPLICATION -- Linux Pocket GUide

[外链图片转存失败,源站可能有防盗链机制,建议在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
将图片保存下来直接上传(img-mdemK5vO-1674400585395)(sta1.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2Lre89GF-1674400585395)(sta2.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vxOjO3wn-1674400585396)(sta3.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UXXgLZfr-1674400585396)(sat4.png)]

Operates

# working directory path
$ pwd

# cd old pwd
$ cd - 

# cd current user's root directory
$ cd ~

# all, long, human-readable
ls -alh _directory

# determine file type
file _file

mkdir _name

cp _source _dest / _source... _directory

mv _source _dest / _source... _directory / _old_name _new_name

rm -iv _files... / -riv directory 

# create hard links(is backup)
ln _target _link_name

# create symbolic links(just a pointer)
ln -s _target _link_name

Using Bash

Concept of shell

  • The command-line user interface of the operating system

Features of bash

Expansions
# Command arguments will be expanded before execution

# 1. space & word splite expansion
$ echo a      b c  -> a b c

# 2. path-name expansion
# The mechanism by which wildcards(*) work is called pathname expansion.
$ ls * / $ ls *D / $ ls D* / $ ls /usr/*/bin


# 3. tilde(~) expansion
# expand to user root directory.
$ echo ~(current user) / $ echo ~xx_user_name

# 4. arithmetic expansion(+ - * / % **)
$ echo $((2**5)) 

# 5. brace expansion
{001..5} / a{A{1,2},B{1..5}}b

# 6. parameter expansion
$ echo $any_var_in_env

# 7. command substitution expansion
$ ls -alh $(which cp)  
Quoting
# limit expansion

# double quotes
# Allmost expansions can't work. The exceptions are $, \, and `.
# Use \$ \\ 

# single quotes
# All expansions can't work

Command help

$ type _buitin_command

# option
$ help / --help

$ man _command
$ whatis 

# locate a command
$ which 

# locate the binary, source, and manual page files for a command
$ whereis

# list all alias
$ alias

I/O Redirection

# stdoutput & truncate file
>

# stdoutput & error
&

# stdoutput & don't truncate file
>>

# stdinput
<

# concatenate files and print on the standard output
cat

# pipe, different with >,< to overwriting file
# just transfer result as command parameter
|

# omit repeated lines
uniq

sort

# print newline, word, and byte counts for each file
wc

# filter result 
$ dpkg -l | grep fire*

# !tail -f output appended data as the file grows
head/tail

# duplicating pipe content & write to stdoutput
tee

Keyboard Tricks

Editing
# Move cursor to the beginning or end of the line      
$ ctrl + a
$ ctrl + e

# Move cursor forward or backward one word
$ alt + f
$ alt + b

# Clear screen
$ ctrl + l

# cut text from the cursor location to the end or start of line.
$ ctrl + k
$ ctrl + u

# past 
$ ctrl + y
History
# list all history 
$ history

# !history_num to runing history command

# entery keyworld to seraching history
$ ctrl + r

Permissions

What is permissions ?

Each file has three types of permissions, owner, group, other. We just need to know what permissions we want to share to own group and others when we create the file.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-97DMOzdj-1674400585396)(permission.png)]

Permission Operate

# change default permission 
# every file init permission is 0666, and using umask 0002 to mask bit.
$ umask [mode]

# change file permission
# using u(user), g, o(other), a(all) + - = , r w x to change file mode
$ chmod u+rwx 
$ chmod ug+rx, o=r
$ chmod g-x, o=r

# some special permission
# suid, guid, sticky bit
https://linuxhandbook.com/suid-sgid-sticky-bit/

# change owner or group owner
$ chown _new_owner:_new_group_owner


# run root user
# On Ubuntu, there is no root user account, just can use sudo command.
$ su - 

# run command as root
# commands that sudo can work is settled by /etc/sudoers
$ sudo _command

# list sudo privileges
sudo -l -U _user_name

Manage User

# print real and effective user and group IDs
$ id

# change user password
$ passwd 

# add new user
$ adduser _user_name

# Add a user group
$ addgroup [--gid ID] _GROUP  

# add new sudo user
# default user is not a sudoer,it not in sudo group that can't use sudo.
# just need append to sudo group
$ usermod -aG sudo _user_name

# delete user
$ userdel -rf _user_name

Processes manager

# viewing processes
# snapshot
$ ps aux

# dynamically
$ to

# controlling processes
# list process that start in the bash
$ jobs 

# running in the back ground
$ bg _%jobs_id

# running in the front ground
$ fg _%jobs_id

# linux uses sending signal to control process
# Stop
$ ctrl + z
$ kill -TSTP _pid
$ kill -STOP _pid # rude

# Terminate
$ ctrl + c
$ kill -INT _pid     # interrupt
$ kill [-TERM] _pid  # terminate
$ kill -KILL _pid    # rude

# continue, restore process that was stopped
$ kill -CONT _pid

Editor

vim

# enhanced behavior
$ echo "set nocp" >> ~/.vimrc

# editing mode or execute vim command(ready to set mode after enter esc)
1. i (INSERT MODE)
2. :w (save)
3. :q (quit)

# move cursor(must enter esc)
1. k -> up
2. j -> down
3. h -> left
4. l -> right
5. 0 -> line begin
6. $ -> line end
7. w -> next word
8. G -> end line

# basic editing(must enter esc)
# delete next n line(include cureent line)
ndd

# copy-past
0. p -> past
1. yy -> current line
2. nyy -> next n line
3. y$ -> from current location to line end
4. y0 -> from current location to line begin

# search
step1: /key_word
step2: enter (first match)
step3: n (next match)

# edit mode
# move cursor
# basic editing
# search  

Environment

Concept of environment

Global data for every program(include shell script), the data consist of environment var and shell var.

IMPORTANT VAR PATH: A colon-separated list of directories that are searched when you enter the name of a executable program

Default Environment

Environment will be established when startup shell

  1. Login shell session : /etc/profile, ~/.bash_profile or ~/.bash_login or ~/.profile

  2. Non-login shell session: /etc/bash.bashrc, ~/.bashrc

# list all env var
$ printenv

# Export environment to subsequently executed programs
export PATH

# list all alias
$ alias
$ alias _xx 'ls -alh'

Manage Environment Scheme

  1. PATH or define additional environment variables, place those change in .profile

  2. For everything else, place the change in .bashrc

Manage Software

# set software center mirror 
GUI: softwareupdate > 

# dpkg low tools 
$ dpkg -i/-r/-l 

# apt* hight tools
$ apt update   # update software index cache

# snap is interface of snap store.

Networking

Test tools

# ping
# traceroute

View information

# ip
$ ip a

# netstat
# check tcp connections
$ netstat -at

# check udp conections
$ netstat -au

Archiving and Backup

Compression

# gzip & bzip2 [option] [file]...
# -d decompression 
# -v verbose

Archiving

1. create a tarball
# !no - 
$ tar cvf _output_name.tar _source_directory

2. create a gzip tarball
$ tar cvzf _output_name.tar.gz _source_directory

3. create a bzip2 tarball
$ tar cvjf _output_name.tar.bz2 _source_directory

4. list the contents of a tarball
$ tar tvf _target.tar

5. add more files to a tarball
# you can't forward add file to compressed tarball
$ tar rvf _target.tar _update_directory

6. Extract a tarball
$ tar xvf _target.tar[.gz, .bz2]

7. Extract the tarball to a specific directory
$ tar xvf _target.tar -C _target_dir
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值