docs

a slatepencil documentail site

View on GitHub

Linux

Ubuntu Releases

Everything in Linux is considered to be either a file or a process:

GNU Core Utilities

User

# create user and home dir
adduser <someone>
# grant sudo priviledge
sudo usermod -aG sudo <username>

man <program or command>

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

#  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=

###

# 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

#!/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

Editing features

# 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

INSTALLING the kernel source:

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