Linux
Ubuntu Releases
Everything in Linux is considered to be either a file or a process:
process
A process is an executing program identified by a unique process identifier, called aPID
. Processes may be short in duration, such as a process that prints a file to the screen, or they may run indefinitely, such as a monitor program.file
A file is a collection of data, with a location in the file system called a path. Paths will typically be a series of words (directory names) separated by forward slashes, /. Files are generally created by users via text editors, compilers, or other means.
GNU Core Utilities
- Conda
- Curl
- Disk
- Docker
- File
- Flutter
- Git
- Gitlab
- Grafana & Loki
- Kubenetes
- Network
- Nginx
- Npm
- MONGO
- MYSQL
- PostgreSQL
- Samba
- SSL
- SSH
- RABBITMQ
- REDIS
- UFW
- VPN
User
# create user and home dir
adduser <someone>
# grant sudo priviledge
sudo usermod -aG sudo <username>
man <program or command>
man 1
一般命令。常见的 linux 命令,例如ls
,cd
,cat
等等man 2
用来放内核提供的系统调用或者函数。例如man 2 fork
等man 3
C 库函数man 4
特殊文件,例如设备和驱动程序man 5
文件格式。包括完全使用文本配置文件定制系统的操作,大量的配置文 件,网络服务列表,可用的 shell 列表等等man 6
游戏和屏幕保护程序。man 7
杂类文件。man 8
系统管理命令,超级用户可能需要用到它们
man page layout
layout | description |
---|---|
NAME | a one-line description of what it does. |
SYNOPSIS | basic syntax for the command line. |
DESCRIPTION | describes the program’s functionalities. |
OPTIONS | lists command line options that are available for this program. |
EXAMPLES | examples of some of the options available. |
SEE ALSO | list of related commands. |
man man
# `-k` option will print the short man page descriptions for any pages that match the command
man -k who
# docker-trust-signer (1) - Manage entities who can sign Docker images
# w (1) - Show who is logged on and what they are doing.
# who (1) - show who is logged on
# whoami (1) - print effective userid
Command options ??
sys | description |
---|---|
UNIX | which may be grouped and must be preceded by a dash |
BSD | which may be grouped and must not be used with a dash |
GNU long | which are preceded by two dashes |
I/O and Redirection
stdin
standard input, the stream of data going into a program. By default, this is input from the keyboard.stdout
standard output, the output stream where data is written out by a program. By default, this output is sent to the screen.stderr
standard error, another output stream (independent of stdout) where programs output error messages. By default, error output is sent to the screen.
# save the output (stdout) from a program to a file
ls > output_file.txt
# append the output file instead of rewriting it
ls >> output_file
# Input can also be given to a command from a file
mycommand < params.txt
# The pipe will link stdout from one command to stdin of another command
ifconfig | grep 192
# When performing normal redirection of the standard output of a program (stdout), stderr will not be redirected because it is a separate stream
# redirect only stderr to a separate file
./my_script.sh 2> my_error_file
# merge stderr with stdout
./my_script.sh > combined_output_file 2>&1
# To have the output go to both a file and the screen, use the tee command
./my_script.sh | tee log.txt
./my_script.sh 2>&1 | tee log.txt
Job control
# To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely
# To see every process on the system using BSD syntax:
ps ax
ps axu
# To print a process tree:
ps -ejH
ps axjf
# To get info about threads:
ps -eLf
ps axms
# To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM
# To see every process running as root (real & effective ID) in user format:
ps -U root -u root u
# To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -Ao pid,tt,user,fname,tmout,f,wchan
# Print only the process IDs of syslogd:
ps -C syslogd -o pid=
# Print only the name of PID 42:
ps -q 42 -o comm=
###
Ctrl + C
send an interrupt signal to the processCtrl + Z
suspend the process, can be resumed in the background withbg
# a process can be invoked and immediately sent to the background by adding an `&` at the end of the command
./longscript.sh &
# A running job can be brought to the foreground with `fg`
fg # `man fg` see more
# display currently running jobs, similar to `ps`
jobs
# view details about running processes
top
# more interactive, alternative to `top`
htop
# stop a process
kill PID
bash script
- variables
$0
the invoked name of the bash script$1
~$9
first 9 arguments to a script$#
Number of arguments passed to the script$?
The exit status of the most recent process$@
All the arguments supplied to the Bash script$$
The process ID of the current script$LINENO
Returns the current line number in the Bash script
#!/bin/bash
# define variable
WRITEDIR=mydir
# [] is shorthand for the "test" command, see `man test` for details
# Double will do variable substitution, single will not
if [-d "$WRITEDIR"]
then
# action
echo "$WRITEDIR" created
else
# action
exit 1
fi
vim
Navigation in normal mode
h
move leftj
move downk
move upl
move right0
Move to the beginning of the line$
Move to the end of the linew
Move to the beginning of the next word,5w
moves 5 words forwarde
Move to the end of the current word,3e
Editing features
- Undo the previous command, even the last edit in insert mode, with the command
u
- Redo the previous command (after undo) with
Ctrl-R
- Copy (yank) characters, words, or lines:
yl
to copy a single character under the cursoryy
to copy the current liney#y
or#yy
where # is replaced with the number of lines you want to copy (i.e.y25y
will copy 25 lines). - Paste (put) characters, words, or lines:
p
will paste after the cursor for characters and words, or on the next line (regardless of the cursor location within a line) if you are pasting lines.P
will paste before the cursor for characters and words, or on the preceding line (regardless of the cursor location within a line) if you are pasting lines. - Delete or Cut characters, words, or lines (that can then be pasted elsewhere):
x
to delete a single character under the cursordd
to delete the current lined#d
or#dd
where # is replaced with the number of lines you want to delete (similar to copy). - Search for strings throughout a file and optionally replace:
A basic search for a word is simply
/word
followed byEnter
. This will jump to the first occurrence of the word after the cursor. Phrases can also be used. Once a search is active, you can usen
to jump to the next occurrence andN
to jump to the previous occurrence. Search and replace has many options, but one example is to find all occurrences of “foo” in the file and replace (substitute) them with “bar” with the command: :%s/foo/bar/g
- Split the screen vertically or horizontally to view multiple files at once in the same shell:
:sp <filename>
will open the specified file above the current active file and split the screen horizontally.:vsp <filename>
will open the specified file to the left of the current active file and split the screen vertically Navigate between split-screen files by pressingCtrl-W
followed by navigation keys (i.e.Ctrl-W h
orCtrl-W ←
to move to the left file) Also note that you can open several documents at once from the shell using appropriate flags. Seeman vim
for more information
# Any of the editing commands can easily be combined with navigation commands
# delete the next 5 words
5de
# copy from the current cursor location to the end of the line
y$
kernel release
major components of Linux
kernel
The kernel is the core of the Linux operating system that schedules processes(A task executing on a given processor at a given time. The operating system treats each process as an independent entity and schedules it to run on system resources. Each process maintains its own virtual address space, which the OS maps into physical memory.) and interfaces directly with the hardware. It manages system and user I/O, processes, devices, files, and memory.shell
The shell is a text-only interface to the kernel. Users input commands through the shell, and the kernel receives the tasks from the shell and performs them. The shell tends to do four jobs repeatedly: display a prompt, read a command, process the given command, then execute the command. After which it starts the process all over again.
INSTALLING the kernel source:
-
If you install the full sources, put the kernel tarball in a directory where you have permissions (eg. your home directory) and unpack it:
`gzip -cd linux-3.X.tar.gz | tar xvf -`
or
bzip2 -dc linux-3.X.tar.bz2 | tar xvf -
Replace “XX” with the version number of the latest kernel.
Do NOT use the /usr/src/linux area! This area has a (usually incomplete) set of kernel headers that are used by the library header files. They should match the library, and not get messed up by whatever the kernel-du-jour happens to be.
-
You can also upgrade between 3.x releases by patching. Patches are distributed in the traditional gzip and the newer bzip2 format. To install by patching, get all the newer patch files, enter the top level directory of the kernel source (linux-3.x) and execute:
`gzip -cd ../patch-3.x.gz | patch -p1`
or
bzip2 -dc ../patch-3.x.bz2 | patch -p1
(repeat xx for all versions bigger than the version of your current source tree, in_order) and you should be ok. You may want to remove the backup files (xxx~ or xxx.orig), and make sure that there are no failed patches (xxx# or xxx.rej). If there are, either you or me has made a mistake.
Unlike patches for the 3.x kernels, patches for the 3.x.y kernels (also known as the -stable kernels) are not incremental but instead apply directly to the base 3.x kernel. Please read Documentation/applying-patches.txt for more information.
Alternatively, the script patch-kernel can be used to automate this process. It determines the current kernel version and applies any patches found.
`linux/scripts/patch-kernel linux`
The first argument in the command above is the location of the kernel source. Patches are applied from the current directory, but an alternative directory can be specified as the second argument.
-
If you are upgrading between releases using the stable series patches (for example, patch-3.x.y), note that these “dot-releases” are not incremental and must be applied to the 3.x base tree. For example, if your base kernel is 3.0 and you want to apply the 3.0.3 patch, you do not and indeed must not first apply the 3.0.1 and 3.0.2 patches. Similarly, if you are running kernel version 3.0.2 and want to jump to 3.0.3, you must first reverse the 3.0.2 patch (that is, patch -R) before applying the 3.0.3 patch. You can read more on this in Documentation/applying-patches.txt
-
Make sure you have no stale .o files and dependencies lying around:
`cd linux` `make mrproper`
You should now have the sources correctly installed.
Buildroot
tmux cheatsheet
commands | description |
---|---|
C-b | Send the prefix key (C-b) through to the application. |
C-o | Rotate the panes in the current window forwards. |
C-z | Suspend the tmux client. |
! | Break the current pane out of the window. |
” | Split the current pane into two, top and bottom. |
# | List all paste buffers. |
$ | Rename the current session. |
% | Split the current pane into two, left and right. |
& | Kill the current window. |
’ | Prompt for a window index to select. |
( | Switch the attached client to the previous session. |
) | Switch the attached client to the next session. |
, | Rename the current window. |
- | Delete the most recently copied buffer of text. |
. | Prompt for an index to move the current window. |
0 to 9 | Select windows 0 to 9. |
: | Enter the tmux command prompt. |
; | Move to the previously active pane. |
= | Choose which buffer to paste interactively from a list. |
? | List all key bindings. |
D | Choose a client to detach. |
L | Switch the attached client back to the last session. |
[ | Enter copy mode to copy text or view the history. |
] | Paste the most recently copied buffer of text. |
c | Create a new window. |
d | Detach the current client. |
f | Prompt to search for text in open windows. |
i | Display some information about the current window. |
l | Move to the previously selected window. |
m | Mark the current pane (see select-pane -m). |
M | Clear the marked pane. |
n | Change to the next window. |
o | Select the next pane in the current window. |
p | Change to the previous window. |
q | Briefly display pane indexes. |
r | Force redraw of the attached client. |
s | Select a new session for the attached client interactively. |
t | Show the time. |
w | Choose the current window interactively. |
x | Kill the current pane. |
z | Toggle zoom state of the current pane. |
{ | Swap the current pane with the previous pane. |
} | Swap the current pane with the next pane. |
~ | Show previous messages from tmux, if any. |
Page Up | Enter copy mode and scroll one page up. |
Up, Down Left, Right |
Change to the pane above, below, to the left, or to the right of the current pane. |
M-1 to M-5 | Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled. |
Space | Arrange the current window in the next preset layout. |
M-n | Move to the next window with a bell or activity marker. |
M-o | Rotate the panes in the current window backwards. |
M-p | Move to the previous window with a bell or activity marker. |
C-Up, C-Down C-Left, C-Right |
Resize the current pane in steps of one cell. |
M-Up, M-Down M-Left, M-Right |
Resize the current pane in steps of five cells. |
ali ossutil
vim lang support
# /etc/vim/vimrc
set fencs=utf-8,GB18030,ucs-bom,default,latin1