<style type="text/css">
.slides, .slides a, .slides p, .slides ul , .slides li{
font-size: 32px;
color: #f0f0f0 !important;
}
.slides pre code {
max-height: 800px;
line-height: 125%;
font-size: 24px;
}
.slides code{
font-size: 24px;
color: #fefefe !important;
}
.slides h1 {
font-size: 72px;
}
.slides h2 {
font-size: 64px;
text-align: center;
text-decoration: underline white 3px;
}
.slides h3 {
font-size: 56px;
text-align: center;
text-decoration: underline gray 2px;
}
.slides h4 {
font-size: 48px;
margin: 1em auto;
}
.slides h5 {
font-size: 36px;
}
.slides h6 {
font-size: 28px;
}
.reveal section img {
vertical-align: middle;
background: none;
box-shadow: none;
border: none;
margin: 0;
width: 80%;
text-align: center;
}
.reveal .slides > section > section {
width: 100%;
margin:auto;
}
.section-flex {
display: flex;
width: 100%;
flex-direction: row;
justify-content: space-evenly;
color: #f0f0f0;
}
.section-flex > div > ul {
margin-top:5px;
margin-bottom:5px;
display: flex;
flex-direction: column;
justify-content: space-evenly;
}
.section-flex > div > ul > li {
padding: 5px;
}
.img-flex {
display: flex;
flex-direction: row-reverse;
justify-content: space-evenly;
color: #f0f0f0;
}
.img-flex img {
max-height: 800px;
}
.img-flex > div > ul {
min-height: 400px;
margin-right: 0.5em;
display: flex;
flex-direction: column;
justify-content: space-evenly;
color: #f0f0f0;
}
.img-row {
height: 140px;
width: 90%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
margin: 5px auto;
}
.img-row img, .img-row > a > img {
padding: 15px 15px 15px 15px;
width: 140px;
height: 160px;
}
</style>
# Linux Basics and Efficient Tools
<br />
<a href="mailto:biyujiang@ihep.ac.cn">Yujiang Bi</a>
CC@IHEP, CAS
<br />
<p>
The $5^{th}$ Computing Summer School for High Energy Physics
08/23/2024
</p>
---
## Outline
<br />
- Linux Intro<br />
- Linux Environment<br />
- Text Editors<br />
- Remote Access Tools<br />
- Git & IHEP Code<br />
- Container Technology<br />
---
## Linux Intro
<!-- .slide: data-transition="zoom" -->
<!-- <img src='/uploads/2f8e0112-bac2-4143-b2eb-1492c88a2b25.jpeg' style="width:90%; margin-top:0em;"> -->
----
### Welcome to the World of Linux
<img src='/uploads/2f8e0112-bac2-4143-b2eb-1492c88a2b25.jpeg' style="width:90%; margin-top:0em;">
<!-- <img src='/uploads/cc2c1bec-3d29-467b-a7e7-ced116572ca5.png' style="width:90%; margin-top:1em;"> -->
----
### Linux? GNU/Linux?
<!-- .slide: data-transition="zoom" -->
- Linux is the open-sourced kernel of GNU OS, created by Linus Torvalds in 1991, providing
- Management for processes, memory and file system ...
- Devices drivers, networking, security and interprocess communication ...
- GNU OS was created by Richard Stallman to be a free replacement for Unix
- It has an official kernel called GNU Mach, the kernel of GNU Hurd
- GNU/Linux Distribution
- A complete operation system with different components, like RHEL and Debian
- One distribution might be quite different from another one in UE and management
- GNU/Linux is the most successful open-sourced OS
----
### The Most Successful Open-sourced OS
- Advantages and applications of GNU/Linux
- Open-sourced and free to everyone. Flexible and
- Run on hardwares of various architectures and used in different areas
- Data center,network infrastructure,mobile and embedded devices
- Cloud computing, supercomputing, scientific computing ...
- Comparision with other OSs like Windows and macOS
- More open! More free! More flexible!
- Users can freely choose and customize own distributions
- More stable and secure than other operating systems
----
<!-- .slide: data-transition="fade-in convex-out" -->
### Linux Distributions
<img src='/uploads/0704f7d3-c915-4c0d-a059-6b6b6cee69e5.png' style="width:100%; margin-top:1em;">
----
### An Old Linux Global Map
<img src='/uploads/939afde8-24ae-42d6-98b5-3279599b2554.png' style="text-align: center;width:82%; margin:auto;">
----
### What's Your Favorite Distribution?
<p style="align:left;">
Popular Linux distributions:
</p>
- Debian
- **Ubuntu**, Kubuntu, Linux Mint, Xubuntu, **Armbian** ......
- RedHat
- CentOS, **Fedora**, **AlmaLinux**, Rocky, Oracle Linux ......
- ArchLinux
- Manjaro, Artix, Chakra, Endeavour ......
- OpenSUSE
- Gecko, Kamarada ...
---
<!-- ================================================================================ -->
## Linux Environment
----
### A First Look at Linux
<img src='/uploads/07e7bef5-8554-4017-a3b8-c010b9d5452e.png' />
----
### Who Am I? Where Am I?
- Username: the passport to Linux world
- Username with uid is unique to identify who you are
- Using correct username & password to log into linux system and entering your home.
- Group: a logical collection of users with the same characteristics
- To have same permissions to specific dir/files, like view or edit some file or directory
- One can belong to multiple groups, but only have one primary group
<div class="section-flex" style="margin-top:0.5em;">
<div style="width:50%;">
<ul>
<li><code>whoami</code>: display who your are
<code class="wrap bash hljs">
$ whoami<br/>
biyj
</code>
</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li> <code>pwd</code>: display where you are</li>
<code class="wrap bash hljs">
$ pwd [-P]<br/>
/afs/ihep.ac.cn/users/b/biyj
</code>
</ul>
</div>
</div>
<div style="width:95%;text-align:left;margin: 0 auto 0 auto;">
<li><code>id</code>: identity yourself or other user
<code class="wrap bash hljs">
$ id<br/>
uid=12142(biyj) gid=600(u07) groups=600(u07),340(lhaasorun),580(lhaaso),1027(lqcd),1055(qc)...<br/>
$ id lihaibo<br/>
uid=10515(lihaibo) gid=600(u07) groups=600(u07),290(physics),580(lhaaso),470(offlinerun)...<br/>
</code>
</li>
<li><code>passwd</code>: change your password (or other accounts). Change from <a href='https://login.ihep.ac.cn'>Login</a> page for IHEP cluster
<code class="wrap bash hljs">
$ passwd<br/>
Changing password for user biyj.<br/>
Current password:<br/>
New password:<br/>
Retype new password:<br/>
passwd: all authentication tokens updated successfully.<br/>
</code>
</li>
</div>
----
### Where is my C Drive?
<br />
<h5>If you user headless environment:</h5>
```bash=
[biyj@n200 ~]$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
[biyj@n200 ~]$ ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
```
<h5>If you use DE: </h5>
<div class="section-flex">
<div style="width:52.5%; height:70%;">
<img src='/uploads/90e84be0-52f3-4c0f-b580-c654428187cb.png' >
</div>
<div style="width:50%; height:70%;">
<img src='/uploads/ba027192-76ec-4c37-ac63-52c98dad426b.png' >
</div>
</div>
----
### Linux Filesystem - Hierarchy
- <h6 style="margin-bottom:-0.25em;" >Linux filesystems are organized in a tree structure with the root directory (/) at the top</h6>
- <h6 style="margin-bottom:-1.5em;"> Modern Linux Filesystem have some typical directories, and part of the directory tree looks like:</h6>
```graphviz
digraph hierarchy {
nodesep=1.0
node [color=Red,fontname=Courier,shape=box]
edge [color=black, style=dashed]
"/" -> { "/bin" "/boot" "/dev" "/etc" "/home" "/lib" "/lib64" "/opt" "/proc" "/root" "/sbin" "/sys" "/tmp" "/usr" "/var" }
"/boot" -> { efi grub2 }
"/home" -> { biyj }
"/usr" -> { bin include lib lib64 libexec local sbin share src }
"/opt" -> { eos "eos-folly" nvidia rh }
}
```
<div class="section-flex" style="padding-top:0em; margin-top:-1em;">
<div style="width:50%;">
<ul>
<li> / : the root of whole system</li>
<li> /bin and /sbin
<ul>
<li>Locations of system executable files</li>
<li>Links of /usr/bin and /usr/sbin</li>
</ul>
</li>
<li> /home and /root
<ul>
<li>Home directory of users and root</li>
</ul>
</li>
<li> /lib and /lib64
<ul>
<li>Locations of system libraries</li>
<li>Links of /usr/lib and /usr/lib64</li>
</ul>
</li>
<li> /opt: locations of 3-party softwares</li>
<li> /tmp: locations of temorary files and dirs</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li> /dev: location of devices like disk, cpu</li>
<li> /etc: system management and config files</li>
<li> /proc: virtual fs storing system infos</li>
<li> /sys: virtual fs, an interface to the kernel.</li>
<li> /var: storing variable files like logs</li>
<li> Other storage directories:
<ul>
<li> /afs: afs mount point</li>
<li> /cvmfs: collections of softwares </li>
<li> /eos: EOS filesystem </li>
<li> /hpcfs, /junofs, /ihepfs ...</li>
</ul>
</li>
</ul>
</div>
</div>
----
### Everything is A FILE
<div style="width:90%;text-align:left;margin: 2em auto 0 auto;">
<li>In Linux everything is considered a <strong>FILE</strong>
<ul>
<li>Including hardware devices, processes, directories, regular files, sockets, links...</li>
<li>Many kinds of file types, like regular file, directory, block, links ...
<ul>
<li>Each type of file has a specific purpose and properties</li>
</ul>
</li>
</ul>
</li>
<br />
<li>Aliases for directories
<div class="section-flex" style=" margin-top:0em;">
<div style="width:50%;">
<ul>
<li><code>/</code>: the root directory</li>
<li><code>.</code>: the current directory</li>
<li><code>..</code>: the prarent of current directory</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li><code>~</code>: home of current user, like $HOME</li>
<li><code>~jack</code>: the home of user jack</li>
<li><code>-</code>: the the last directory you visited</li>
</ul>
</div>
</div>
</li>
</div>
----
### Linux Filesystem - Directory and Links
<div class="section-flex" style="margin-left:-1em; margin-top:-0.5em;">
<div style="width:52%;">
<ul>
<li> Entering a directory
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;">$ cd ~; cd $HOME; cd # return to HOME
$ cd .. # go to parent dir
$ cd /path/to/dir # enter other dir
$ cd - # return previous dir
</code></pre>
</li>
<li> List a directory
<pre style="margin:0 5px 0 5px;"><code class="wrap bash hljs" style="font-size:18px;">$ ls dirname # list files under dirname
$ ls -l dirname # list files in detail
total 4
-rw-r--r-- 1 biyj u07 2 Aug 22 15:54 testfile
$ ls -lS dirname # list files by size descending
total 8
-rw-r--r-- 1 biyj u07 8 Aug 22 16:12 a.txt
-rw-r--r-- 1 biyj u07 2 Aug 22 16:18 d.txt
$ ls -ld dirname # show info of dirname
$ ls -A dirname # list files including hidden files
.hidden testfile
</code></pre>
</li>
<li> Creating a directory
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:18px;">$ mkdir dir # create a blank dir under current dir
$ mkdir -p dir1/dir2 # recursively create dirs
</code></pre>
</li>
<li> Delete a directory
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:18px;">$ rmdir dir # rm an empty dir
$ rmkdir -rf dir # rm a dir and files/dirs in it
</code></pre>
</li>
</ul>
</div>
<div style="width:55%; margin-left:-2em;">
<ul>
<li> Two kindes of links in linux
<ul>
<li> Hard link and soft link (or symbolic link) </li>
<li> Using command <code>ln</code> to create links</li>
</ul>
</li>
<li> Hard link
<ul>
<li>A file to linked file with same inode</li>
<li>Must within the same filesystem</li>
<li> Valid even if the targeted file deleted</li>
</ul>
</li>
<li> Soft link
<ul>
<li> A special file containing path of linked file/dir</li>
<li> Will break if targeted file/dir deleted</li>
</ul>
</li>
<li> Example
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;">$ ln a.txt b.txt # hard link
$ ln -sf a.txt c.txt # soft link
$ ls -l a.txt c.txt
total 8
-rw-r--r-- 2 biyj u07 8 Aug 22 16:12 a.txt
lrwxrwxrwx 1 biyj u07 5 Aug 22 16:13 c.txt -> a.txt
</code></pre>
</li>
</ul>
</div>
</div>
----
### Linux Filesystem - File Operations
<div class="section-flex" style="margin-left:0em;">
<div style="width:50%;">
<ul>
<li> <code>cat/tac</code>: print a file normally or reversely
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;">$ cat a.txt # print normally
asfasfd
ryturdg
$ tac a.txt # print reversely
ryturdg
asfasfd
</code></pre>
</li>
<li> <code>more</code>: print a file in a page-by-page manner</li>
<li> <code>less</code>: like more, but can scroll up/down</li>
<li> <code>view</code>: view a file with vi/vim in <strong>ro</strong> mode</li>
<li> truncate a file
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-heigth:120%;">$ cat /dev/null > a.txt
$ echo -n > a.txt
$ > a.txt
$ : > a.txt
$ truncate -s 0 a.txt
</code></pre>
</li>
</ul>
</div>
<div style="width:55%; margin-left:0em;">
<ul>
<li> <code>head</code>: print the first few lines of files
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-heigth:120%;">$ seq 1 1 100 > a.txt
$ head a.txt # first 10 lines
...
10
$ head -n 1 a.txt # first line
1
$ head -n -99 a.txt # all but the last 99 line
1
$ head -c 2 a.txt # first 2 bytes
1
</code></pre>
</li>
<li> <code>tail</code>: displays the last few lines of a file
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-heigth:120%;">$ tail a.txt # last 10 lines
91
...
$ tail -n 1 a.txt # last line
100
$ tail -n +99 a.txt # all but the first 98 line
99
100
$ tail -c 4 a.txt # last 4 bytes
100
$ tail -f a.txt # track appending contents
</code></pre>
</li>
</ul>
</div>
</div>
----
### Linux Filesystem - File Operations
<div class="section-flex" style="margin-left:0em;">
<div style="width:50%;">
<ul>
<li> <code>cp</code>: copy files/dirs (-r) to another place</li>
<li> Normal copy
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ cp a.txt b.txt # copy a file
$ cp -r a.txt c/ d/ # copy a.txt and c/ into dir d
</code></pre>
</li>
<li> Link mode
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ cp -l a.txt h.txt # hard link with -l
$ cp -s a.txt s.txt # soft link with -s
</code></pre>
</li>
<li> Permissions
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ cp -p a.txt p.txt # mode,ownership,timestamps
$ cp --preserve=all a.txt f.txt # all attributes
</code></pre>
</li>
<li> Archive mode
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;"># same as -dR --preserve=all
$ cp -a a.txt a.archive.txt
# only attributes, don't copy contents
$ cp --attributes-only a.txt c.txt
$ cp -ar src/ dst/ # archive a directory
</code></pre>
</li>
<li> Backup: create a backup if target exists
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ ls
a.txt b.txt c.txt
$ cp -b a.txt b.txt; ls
a.txt b.txt b.txt~ c.txt
</code></pre>
</li>
</ul>
</div>
<div style="width:50%; margin-left:0em;">
<ul>
<li> <code>mv</code>: move or rename files or dirs</li>
<li> Normal mode
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;"># move file/dir to dir
$ mv a.txt b/ c/
</code></pre>
</li>
<li> Rename mode
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;"># rename a file
$ mv a.txt b.txt
# rename dir, dir must not exist
$ mv b non-exist-dir
</code></pre>
</li>
<li> Backup: create a backup if target exists
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ ls
a.txt b.txt c.txt d.txt
$ mv -b a.txt b.txt; ls # simple with a ending ~
b.txt b.txt~ c.txt d.txt
$ mv --backup=t b.txt c.txt; ls # numbered
b.txt~ c.txt c.txt.~1~ d.txt
$ mv --backup=nil c.txt d.txt; ls # follow existing
b.txt~ c.txt.~1~ d.txt d.txt~
</code></pre>
</li>
<li> Verbose: explain what is being done
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ mv -vb a.txt b.txt
renamed 'a.txt' -> 'b.txt' (backup: 'b.txt~')
</code></pre>
</li>
</ul>
</div>
</div>
----
### Linux Filesystem - find
<div class="section-flex" style="margin-left:0em;">
<div style="width:50%;">
<ul>
<li> Search a directory for specific files
<ul>
<li>Usage: <code>find [path] [options] [exp]</code></li>
<li>Default path is current directory if ommited</li>
</ul>
</li>
<li> Find files but dirs starting with "test"
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -name "test*"
test.1.txt
</code></pre>
</li>
<li> Find files created/modified within 10 days
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f \( -mtime -10 -o -ctime -10 \)
ctime.within.10.txt
mtime.within.10.txt
</code></pre>
</li>
<li> Find files created/modified 10 days ago
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f \( -mtime +10 -o +ctime +10 \)
ctime.older.10.txt
mtime.older.10.txt
</code></pre>
</li>
<li> Find files of size larger than 1GB
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -size +1G
size.large.1G.txt
</code></pre>
</li>
</ul>
</div>
<div style="width:50%; margin-left:0em;">
<ul>
<li> Search files and execute operations
<ul>
<li> Using find with <code>-exec</code> option</li>
<li> Using <code>{}</code> to replace files found</li>
</ul>
</li>
<li> Find and delete empty file
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -empty -exec rm -f {} \;
</code></pre>
</li>
<li> Find and truncate files larger than 1G
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -size +1G -exec echo -n {} \;
</code></pre>
</li>
<li> Find and delete files older than 1 year
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -mtime +365 -exec rm -f {} \;
$ find . -type f -mtime +365 -delete
</code></pre>
</li>
<li> Find files owned by <code>biyj</code> and change permission
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -user biyj -exec chmod +x {} \;
</code></pre>
</li>
<li> Find files starting with file and print with '\0' or '\n'
<pre style="margin:0px;"><code class="wrap bash hljs" style="font-size:18px;line-heigth:110%;">$ find . -type f -name "file*" -print0 \; # '\0'
$ find . -type f -name "file*" -print \; # '\n'
</code></pre>
</li>
</ul>
</div>
</div>
----
### Linux Filesystem - Permissions
- Type of permissions
- Three main permission types: `read(r,4)`, `write(w,2)` and `excution(x,1)`
- Can be assigned to the owner and the group it belongs to, and to others
- Special permissions:
- SUID: A file with SUID always executes as the user who owns the file, like `passwd`
```bash
$ ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 32656 Apr 14 2022 /usr/bin/passwd
```
- SGID
- For a file, it allows the file to be executed as the group that owns the file
- For a dir, any files created in the dir have same group ownership with dir owner
- Sticky bit
- Only the owner (and root) of a file can remove the file within that director
- A common example of this is the `/tmp` directory:
```bash!
$ ls -ld /tmp/
drwxrwxrwt. 15 root root 4096 Aug 22 14:33 /tmp/
```
- Changing permission with `chmod`:
- using number, like `chmod 755 filename`
- using chars, like `chmod u+x filename`
----
### Special Characters in Shell
- `$`: indicates the beginning of a variable, like `$PATH`
- `*`: wildcards for any character (including space)
- `|`: PIPE. Taking the output of command before `|` as the input of command after `|`
- `>`: redirecting command output to a file. If the file already exists, it will be overwritten
- `>>`: redirect command output to a file or appendeding to the end of the file if existing
- `<`: taking the contents of a file as input to a command
- `\`: escaping characters so that they lose their special meaning
- `;`: command seperator. Seperating multiple commands in one line
----
### Process and Process Management
<div style="width:95%; margin-top:-0.5em;">
<ul>
<li>What is a Process?
<ul>
<li>An instance of a program that is currently running on a computer</li>
<li>It is the basic unit for resource allocation and task execution in a computer</li>
<li>Each process has its own memory space, execution context, and state.</li>
</ul>
</li>
<li> Process Identification
<ul>
<li>Each process has a unique Process ID (PID) and Parent PID (PPID)</li>
<li>Using <code>ps</code> and other commands to view process infos
<code class="wrap bash hljs" style="font-size:18px;">
$ ps aux | grep process
</code>
</li>
<li> <code>kill</code> can be used to send signals to processes. Common signals include:
<ul>
<li>SIGTERM: Terminate the process.</li>
<li>SIGKILL: Forcefully terminate the process.</li>
<li>SIGSTOP: Pause the process.</li>
</ul>
</li>
</ul>
</li>
<li> Running Processes in the Background
<ul>
<li>Background Execution with `&`. Process will be killed if terminal is closed
<code class="wrap bash hljs" style="font-size:18px;">
$ my_command > my.log 2>&1 &
</code>
</li>
<li> Using <code>nohup</code>
<code class="wrap bash hljs" style="font-size:18px;">
$ nohup my_command > my.log 2>&1
</code>
</li>
</ul>
</li>
</ul>
</div>
---
### Text Editors
----
### Classical Editors
<img src='/uploads/bca8e868-8508-42e7-8741-373831f7539f.jpg' style="text-align: center;width:80%;">
----
## The Holy War of Editors
<br /><br /><br /> <br /> <br /><br /><br /><br /> <br /> <br />
<!-- .slide: data-background-image="/uploads/3094a6db-342a-42eb-a164-38bc5887edd2.png" data-background-size="115%"-->
----
### Vim - the God of Editors
<!--
<h6 style="margin-bottom: 0em; margin-top: -0.5em;">
A highly configurable text editor used for efficiently creating and modifying any type of text.
</h6> -->
- Vim has **SEVEN** modes
- Normal. Insert. Visual. Command-line. Replace. Binary. Org.
- Ways to Exit Vim in Command Mode
- `:q` and `:q!`: exit and forcele exit
- `:wq` and `:wq!`: save and (forcely) exit
- `:x` and `ZZ` : write if only modified and quit
- `:qa`: quit all
- Various shortcut of operations in command-line mode
- `dd`: delete the current line
- `u`: undo the last operation
- `p`: paste
- `diw`: delete whole word the cursor is in
- `yy`: copy current line
- Switch from normal to edit mode using the Insert, `a`, `i`, or `o` keys.
- Display Line Numbers in Command Mode
- `:set nu` to show line number, and `:set nonu` to cancel line number display
<!--
- 在命令模式中(默认模式),通过 Insert、a、i、o 键可以切换到编辑模式
- 在编辑模式中,通过 ESC 键切换到命令模式
- 在命令模式下,输入/word, 可以在全文中搜索包含word的地方,并且高亮显示 -->
----
### Vim Cheatsheet
<div class="img-flex" style="margin-top:2em; margin-lef:-1em; ">
<img src='/uploads/e87dd86a-917b-450c-920d-cd7740f835cb.png' style="margin-bottom:0em; margin-lef:0em; width: 62%; height: 62%;">
<div>
<ul style="padding:10px;">
<li>Change Leader
<code class="wrap vim hljs">
let g:mapleader=";"<br/>
let mapleader=";"
</code>
</li>
<li> View a file in RO mode:
<code class="wrap bash hljs">$ view f1 f2 ... </code>
</li>
<li>Diff mode
<code class="wrap bash hljs">
$ vimdiff f1 f2</code>
</li>
<li> Split mode
<code class="wrap bash hljs">
$ vim -O f1 f2 ...<br/>
$ vim -o f1 f2 ...
</code>
</li>
</ul>
</div>
<!--
<a href='/uploads/376eaa65-a941-4fe9-b9f6-4552340697dd.png' target="_blank" alt="Click to see another one."><img src='/uploads/e87dd86a-917b-450c-920d-cd7740f835cb.png' style="margin-top:-0.5em; margin-bottom:-0.5em; width: 72%;"> </a>
-->
</div>
----
### Emacs - the God's Editor
----
### Modern Editor
- VS Code
- Sublime
- Brackets
- PyCharm, Jetbrains
- Cursor with AI
- Zed with AI
----
### Regular Expression Tools
----
### Sed
<h6>
A stream editor used for parsing and transforming text from input stream.
</h6>
<div class="section-flex" style=" margin-top:1em;">
<div style="width:50%;">
<ul>
<li>Substitute Text
<code class="wrap bash hljs" style="font-size:18px;">
$ sed -i 's/old/new/' filename # one line<br />
$ sed -i 's/old/new/g' filename # all lines
</code>
</li>
<li> Delete lines
<code class="wrap bash hljs" style="font-size:18px;">
$ sed -i '3d' filename # del 3rd line<br />
$ sed -i '2,10d' filename # del line 3 to 10
</code>
</li>
<li> Insert lines
<code class="wrap bash hljs" style="font-size:18px;">
# Insert before 3rd line<br />
$ sed -i '3 i\new_line' filename<br />
</code>
</li>
</ul>
</div>
<div style="width:55%;">
<ul>
<li>Print Specific Lines
<code class="wrap bash hljs" style="font-size:18px;">
# Print only lines matching a pattern<br />
$ sed -n '/pattern/p' filename<br />
# Print a specific line<br />
$ sed -n 'Np' filename<br />
</code>
</li>
<li>Using RE
<code class="wrap bash hljs" style="font-size:18px;">
$ sed 's/[0-9]/#/g' example.txt
</code>
</li>
<li> Multiple Commands
<code class="wrap bash hljs" style="font-size:18px;">
$ sed -e "command1" -e "command2" filename
</code>
</li>
</ul>
</div>
</div>
----
### Grep
<h6>
A powerful text search tool used to search for matching lines in a file or input stream
</h6>
<div class="section-flex" style=" margin-top:1em;">
<div style="width:50%;">
<ul>
<li>Search pattern
<code class="wrap bash hljs" style="font-size:18px;">
$ grep 'pattern' filename<br />
$ grep -n 'pattern' filename # with line number<br />
$ grep -i 'pattern' filename # ignore case<br />
$ grep -R 'pattern' dir # recursive search <br />
</code>
</li>
<li> Search for Whole Words
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -w 'world' filename
</code>
</li>
<li> Invert Match
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -v 'pattern' filename<br />
</code>
</li>
<li> Count matched lines
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -c 'pattern' filename<br />
</code>
</li>
<li>Show Only Matching Part
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -o 'pattern' filename<br />
</code>
</li>
</ul>
</div>
<div style="width:55%;">
<ul>
<li>Using RE
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -E 'foo|bar' filename
</code>
</li>
<li> Search Lines starting or ending with pattern
<code class="wrap bash hljs" style="font-size:18px;">
$ grep '^pattern' filename # beginning<br />
$ grep 'pattern$' filename # ending
</code>
</li>
<li> Search multiple patterns
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -e 'pattern1' -e 'pattern2' filename
</code>
</li>
<li> Show Context Lines
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -C 5 'pattern' filename<br />
$ grep -A 10 'pattern' filename<br />
$ grep -B 20 'pattern' filename
</code>
</li>
<li> Suppress Filename in Output
<code class="wrap bash hljs" style="font-size:18px;">
$ grep -h 'pattern' file1 file2 ...
</code>
</ul>
</div>
</div>
----
### Awk
<h6>
A powerful text processing tool and programming language for data extraction and reporting
</h6>
<div class="section-flex" style=" margin-top:1em;">
<div style="width:50%;">
<ul>
<li>Print Specific Column like 4th col
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{print $4}'
</code>
</li>
<li> Print specific column of matched line
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '/pattern/ {print $3}' filename
</code>
</li>
<li> Specifica field separator like "_"
<code class="wrap bash hljs" style="font-size:18px;">
$ awk -F _ '{print $0}'
</code>
</li>
<li> Built-in Variables
<ul>
<li>NR: line number</li>
<li>NF: Number of fields</li>
</ul>
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{print NR, NF}' filename<br />
</code>
</li>
<li>Calculations
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{print $1 + $3}' filename<br />
</code>
</li>
</ul>
</div>
<div style="width:55%;">
<ul>
<li>Conditional Statements
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{if ($2 > 100) print $0}' filename
</code>
</li>
<li> BEGIN / END Blocks to initialize and clean up
<code class="wrap bash hljs" style="font-size:18px;">
$ grep '^pattern' filename # beginning<br />
</code>
</li>
<li> Sum a Column
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{sum += $3} END {print sum}' filename
</code>
</li>
<li> Print Specific Lines
<code class="wrap bash hljs" style="font-size:18px;">
$ awk 'NR>=3' filename
</code>
</li>
<li> Use External Variables
<code class="wrap bash hljs" style="font-size:18px;">
$ awk -v var=value '{print var, $0}' filename
</code>
</li>
<li> Replace a Column
<code class="wrap bash hljs" style="font-size:18px;">
$ awk '{$2="new_value"; print $0}' filename
</code>
</li>
</ul>
</div>
</div>
---
## Remote Access Tools
----
### Remote Secure Shell Tools
<br />
- WSL
- Windows 10/11 required, with WSLg installed by default
- XShell/XManager
- 7 required for lxlogin.
- MobaXterm
- Homeedition is good enough. But no IPv6 for X11
- Tabby
- A morden terminal simulator
- Putty
- Solar Putty
- ......
----
### Default SSH Config is not User-friendly
<p style="text-align: left; margin-left:3em;"> Log in to remote server with password: </p>
```bash!=
$ ssh myuser@myhost
myuser@myhost's password:
Permission denied, please try again.
myuser@myhost's password:
Permission denied, please try again.
myuser@myhost's password:
myuser@myhost: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
```
<p style="text-align: left; margin-left:3em;"> Avoid password with SSH key pair</p>
```bash!=
$ ssh-keygen -f ~/.ssh/id_rsa -t rsa -b 4096
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:9B+5DBkw/dYGYt06/gbzl7IJBSwkgPvgwb3n1OYAvUk root@myserver
The key's randomart image is:
......
```
----
### Custom Your SSH
<p style="text-align: left; margin-left:2em;"> Create or modify ~/.ssh/config </p>
<span>
```ssh
# $HOME/.ssh/config
Host *
PubkeyAcceptedKeyTypes +ssh-rsa,ssh-ed25519
Serveraliveinterval 60
StrictHostKeyChecking no
Host lxlogin*
Hostname %h.ihep.ac.cn
User biyj
ForwardX11 yes
Host *
Identityfile ~/.ssh/keys/id_rsa
Addressfamily inet
```
<!-- .element: class="fragment" data-fragment-index="1" -->
</span>
<span>
<p style="text-align: left; margin-left:2em;"> And log into login servers like:</p>
<!-- .element: class="fragment" data-fragment-index="2" -->
```bash=
$ ssh lxlogin
......
Last login: Sun Aug 18 07:53:08 2024 from 10.100.0.75
[biyj@lxlogin003 ~]$
```
<!-- .element: class="fragment" data-fragment-index="3" -->
</span>
----
### Terminal Multiplexer
<div style="width:90%;margin: 1em auto 0 auto;">
<p style="text-align:left;margin:auto; "> People always say:</p>
<span>
<h5 style="padding:10px; margin:5px; color:#a0b2a2;">More Windows! More Terminals! More Desktops!</h5>
<!-- .element: class="fragment" data-fragment-index="1" -->
</span>
</div>
<div style="width:90%;margin: 0em auto 0em auto;">
<span>
<p style="text-align:left;margin: 0.5em auto 0.5em auto; ">Terminal multiplexers give you</p>
<!-- .element: class="fragment" data-fragment-index="2" -->
</span>
<span>
<div style="text-align:left; margin:auto;">
<ul>
<li>Persistent sessions that can be attached and detached
<ul>
<li>regardless of unstable conntection or disconnection</li>
<li>long-time job can safely run in stable without interruption</li>
</ul>
</li>
<li>Multiple panes and windows in one terminal instead of multiple terminals</li>
<li>Collaborative work by attaching an existing session as they see fit</li>
</ul>
</div>
<!-- .element: class="fragment" data-fragment-index="3" -->
</span>
</div>
<div style="width:90%;margin: 0em auto 0 auto;">
<span>
<div>
<p style="text-align:left;margin: 0.5em auto; ">Popular Terminal multiplexers</p>
<div class="section-flex" style=" margin-top:0em;">
<div style="width:50%;">
<ul>
<li><a href='//github.com/tmux/tmux/wiki' target="_blank">Tmux</a></li>
<li>Screen</li>
<li>Byobu</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li>Terminator</li>
<li>Konsole</li>
<li>dvtm</li>
</ul>
</div>
</div>
</div>
<!-- .element: class="fragment" data-fragment-index="4" -->
</span>
</div>
----
### Tmux - Basic Usage
<div class="img-flex" style="margin-left:0.em; margin-top:0em; padding:1em 0 0 0;">
<img src="/uploads/290bb100-e0af-48d6-a3e2-5040ecad9141.png" style="width:65%; height:100%; margin-right:0.5em;">
<div style="font-size:28px;">
<ul>
<li>Create window:
<code class="wrap bash hljs" style="font-size:20px; margin:0; padding:2px;"><CTRL-b> c</code>
</li>
<li> Split window virtically:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"> <C-b> %</code>
</li>
<li> Split window horizontally:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"><C-b> "</code>
</li>
<li> Move between panes:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;">$ <C-b> ↑|↓|←|→</code>
</li>
<li> Switch between windows
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"><C-b> p # previous<br />
<C-b> n # next</code>
</li>
<li> Rename session
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"><C-b> $ test</code>
</li>
<li> Detach a session
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"><C-b> d</code>
</li>
</ul>
</div>
</div>
----
### Tmux Cheatsheet
<div class="img-flex" style="margin-left:0.em; margin-top:1em;">
<img src="/uploads/09cc0c29-5624-4d22-811c-1e92873c5fb6.png" style="width:60%; height:80%; margin-right:0.5em;">
<div>
<ul>
<li>Change prefix:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;">
unbind ^b<br/>
set -g prefix ^a
</code>
</li>
<li> Set VI mode:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;"> setw -g mode-keys vi </code>
</li>
<li>Bind key:
<code class="wrap bash hljs" style="font-size:20px;">
bind k selectp -U<br/>
bind j selectp -D<br/>
bind h selectp -L<br/>
bind l selectp -R
</code>
</li>
<li> List sessions:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;">$ tmux ls </code>
</li>
<li> Attach session:
<code class="wrap bash hljs" style="font-size:20px;margin:0; padding:2px;">$ tmux a[tt] [-t id] </code>
</li>
<li> <strong>Remeber where your sessions are </strong></li>
</ul>
</div>
</div>
---
## Git & IHEP Code
----
### What is Git?
<div class="section-flex" style=" margin-top:1em;">
<div style="width:50%;">
<ul>
<li>A distributed code management tool
<ul>
<li>Like Mercurial, Bazaar and Darcs</li>
</ul>
</li>
<li> Git mode: Local + remote repositories </li>
<li>Local repository: a complete local copy
<ul>
<li>Almost all operations can performed</li>
<li>Push codes to remote common repo</li>
</ul>
</li>
<li> Remote repo: common copy shared with others
<ul>
<li>Users pull from or push to common repo</li>
</ul>
</li>
<img src='/uploads/a1a27188-a909-4f26-b3e1-42dfb930ef3e.png' style="height:350px;width:600px;margin-left:5%; margin-top:1em;">
</ul>
</div>
<div style="width:55%;">
<ul>
<li> Three areas for local repository:
<ul>
<li>Working area: Files you are working on</li>
<li>Staging area: files waiting for to be committed</li>
<li>.git dir: metadata + database </li>
</ul>
</li>
<li> Three kinds of file status:
<ul>
<li>File is changed</li>
<li>File is staged</li>
<li>File is committed</li>
</ul>
</li>
<li> Getting git
<ul>
<li>Linux
<code class="wrap bash hljs" style="font-size:20px;">
$ sudo apt install -y git ### for debian/ubuntu <br/>
$ sudo dnf install -y git ### for fedora/alma/rhel <br />
$ sudo yum install -y git ### for old rhel/centos <br />
</code>
</li>
<li>macOS: using brew or download <a href='https://git-scm.com/download/mac' target="_blank">installer</a>
<code class="wrap bash hljs" style="font-size:20px;"> $ brew install git </code>
</li>
<li>windows
<ul>
<li>Download <a href='https://git-scm.com/download/mac' target="_blank">installer</a> or using WSL</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
----
### Configuring Git
<div class="section-flex" style="padding-top:1em;">
<div style="width:50%;">
<ul>
<li> git config
<code class="wrap bash hljs" style="font-size:20px;">
# User info<br/>
$ git config --global user.name "John Smith"<br/>
$ git config --global user.email "johnsmith@example.com"<br/>
# Editor<br/>
$ git config --global core.editor vim<br />
</code>
</li>
<li> Show all git config
<code class="wrap bash hljs" style="font-size:20px;">
$ git config --list
</code>
</li>
<li> Show config usage
<code class="wrap bash hljs" style="font-size:20px;">
$ man git config
</code>
</li>
<li> Git config files
<ul>
<li>system:<code>/etc/gitconfig</code> </li>
<li>global:<code>$HOME/.gitconfig</code> </li>
<li>local:<code>.git/config</code> </li>
</ul>
</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li> Useful aliases for git
<code class="wrap bash hljs" style="font-size:20px;">
[alias]<br />
a = add .<br />
v = !gitk<br />
br = branch<br />
ci = commit -m<br />
cm = commit -m<br />
co = checkout<br />
df = diff<br />
dump = cat-file -p<br />
hs = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short<br />
last = log -1 HEAD<br />
pl = pull<br /><br />
ps = push<br />
st = status<br />
type = cat-file -t<br />
sum = shortlog -sn
</code>
</li>
</ul>
</div>
</div>
----
### Basic Git Operations (I)
<div class="section-flex" style="margin-top:0em;">
<div style="width:50%; margin-left:0em;">
<ul>
<li>Prepare local repository
<ul>
<li> Using local dir
<code class="wrap bash hljs" style="font-size:20px;">
## Initializing one or using existing dir<br/>
$ git init demo<br/>
$ cd demo; git init
</code>
</li>
<li> Cloning existing repo
<code class="wrap bash hljs" style="font-size:20px;">
## Clong local repo <br/>
$ git clone /path/to/existing/repo/<br/>
## Clone remote repo<br/>
$ git clone username@host:/path/to/my/repo
</code>
</li>
</ul>
</li>
<li>Workspace operations:
<ul>
<li> Project status
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git status
On branch main...
$ git status -s ## Status
M README # M : modified and staged
M lib/a.cpp # M : modified but not staged
MM lib/b.cpp # MM : staged but modified again
A lib/c.cpp # A : staged new file
?? lib/c.o # ?? : file not tracked</code></pre>
</li>
<li> Staging modified file
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git add README
$ git status
On branch ...
Changes to be committed:...
new file: README</code></pre>
</li>
</ul>
</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li> Workspace operations
<ul>
<li> Using <code>.gitignore</code> to skip unwanted files or directories
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ cat .gitignore
my_passwd # Password file
*.o # tmp files when compiling
tmp/ # tmp directory
config* # Config file or directory
dist* # distribution dir
*.pyc # binary python code file
node_modules # node module directory</code></pre>
</li>
</ul>
</li>
<li> Commit operations
<ul>
<li>Prepare your commit
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git commit
Add README; Update RELEASE.md
......
# On branch main
# Your branch is up-to-date with 'origin/main'
......
# Changes to be committed:
# new file: README
# modified: RELEASE.md
#
......
README RELEASE.md</code></pre>
</li>
<li>Commit your commit
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%;">$ git commit -m "Add README; Update RELEASE.md"</code></pre>
</li>
</ul>
</li>
</ul>
</div>
</div>
----
### Basic Git Operations (II)
<div class="section-flex" style="margin-top:0em;">
<div style="width:55%; margin-left:0em;">
<ul>
<li> Branch operations
<ul>
<li>Let developers work unaffected in parallel</li>
<ul>
<li>Default main/master to store main code</li>
<li>Others for developing features, fixing bugs ...</li>
</ul>
<li>Creation
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git branch dev; git checkout dev
$ git checkout -b dev</code></pre>
</li>
<li>Merging
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git checkout main; git merge dev</code></pre>
</li>
<li>Deletion
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git branch -d dev</code></pre>
</li>
</ul>
</li>
<li> Tag important commits with special name
<ul>
<li>List all tags with name
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git tag -l
v1.0</code></pre>
</li>
<li>Tag the selected commit
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git tag <tag-name> [commit]</code></pre>
</li>
<li>Delet a tag
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git tag -d <tag-name></code></pre>
</li>
</ul>
</li>
</ul>
</div>
<div style="width:45%;">
<ul>
<li>Commits
<ul>
<li>List commits gracefully
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:20px;line-height:120%; ">$ git log --pretty --graph --date=short </code></pre>
</li>
</ul>
</li>
<li> Confliction
<ul>
<li>Confliction may occur when merging other branches. </li>
<li>Special patterns inidicating confliction
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:22px;line-height:120%; "><<<<<<< HEADE:index.html
Contact: <mailto:support@gitlab.com>
=======
Please contact us at support@gitlab.com
>>>>>>> 1a4f:index.html</code></pre>
</li>
<li>Modifying the conflicted file manually
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:22px;line-height:120%; ">Please contact us at support@gitlab.com</code></pre>
</li>
<li>Re-adding the modified file
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:22px;line-height:120%; ">$ git add index.html</code></pre>
</li>
<li> Committing your change,and push to remote repo
<pre style="margin:5px;"><code class="wrap bash hljs" style="font-size:22px;line-height:120%; ">$ git commit -am 'fix conflication'
$ git push origin main</code></pre>
</li>
</ul>
</li>
</ul>
</div>
</div>
----
### What is IHEP Code?
<div style="text-align:left; margin-left:8%;">
<ul>
<li> A self-hosted community-version communal gitlab platform.
<ul>
<li><a href='https://code.ihep.ac.cn/' target="_blank" style="font-size:28px;">https://code.ihep.ac.cn</a></li>
</ul>
</li>
<li> Login using IHEP SSO account, email or username</li>
<ul>
<li><a href='https://login.ihep.ac.cn/' target="_blank" style="font-size:28px;">Click to apply an IHEP SSO account</a></li>
</ul>
</ul>
</div>
<img src='/uploads/a7db32fc-0317-4f0a-a8a4-63639f89cccb.png' style='width:80%; margin-top:0.5em;'>
----
### Adding Your SSH Pubkey to Gitlab
<div style="text-align:left; margin-left:4%;">
<ul>
<li> Gitlab prefers SSH keys to push or pull codes without username/password</li>
<li> User can add multiple pubkeys to gitlab</li>
<ul>
<li>User logo -> Preferencs -> SSH Keys -> Add new key</li>
</ul>
</ul>
</div>
<div class="img-flex" style="margin-top:1em; margin-lef:-1em; ">
<img src='/uploads/94e02b6e-7736-4a47-bb6f-771fb5a0e50d.png' style="margin-bottom:0em; margin-right:0em; width: 48%; height: 50%;">
<div>
<ul style="padding:10px;">
<li>Adding code.ihep.ac.cn to your ssh config
<code class="wrap ssh hljs">
Host code<br />
Hostname code.ihep.ac.cn<br />
User git<br />
Identityfile ~/.ssh/id_rsa
</code>
</li>
<li> Test your config:
<code class="wrap bash hljs">
$ ssh -T code
Welcome to GitLab, @biyujiang!
</code>
</li>
</ul>
</div>
<!--
<a href='/uploads/376eaa65-a941-4fe9-b9f6-4552340697dd.png' target="_blank" alt="Click to see another one."><img src='/uploads/e87dd86a-917b-450c-920d-cd7740f835cb.png' style="margin-top:-0.5em; margin-bottom:-0.5em; width: 72%;"> </a>
-->
</div>
----
### Creating A Project or Group
<div style="text-align:left; margin-left:8%;">
<ul style="font-size:48px;">
<li> Project: for single project or task</li>
<li> Group: a workspace for a collection of similar tasks, complicated projects...</li>
</ul>
</div>
<img src='/uploads/c5651c1e-b755-40a1-a763-0031f5024455.png' style="width:84%; padding-top:1em;">
<div class="img-row" style="height:80%; width:86%;">
<img src="/uploads/67e17b0a-4756-405d-ba43-ccc663cc944d.png" style="height:80%; width:50%;padding-right:2em;">
<img src="/uploads/72c679a3-e4c0-4e6e-9380-0c52ecae7c65.png" style="height:75%; width:48%;padding-left:2em;">
</div>
----
### Using Gitlab to Manage Your Codes
<div class="section-flex" style="margin-top:1em;">
<div style="width:50%; margin-left:-2em;">
<ul>
<li>Clone your code:
<code class="wrap bash hljs" style="font-size:20px;">
$ git clone code:biyujiang/demo<br/>
Cloning into 'demo'...<br/>
remote: Enumerating objects: 3, done.<br/>
remote: Counting objects: 100% (3/3), done.<br/>
remote: Compressing objects: 100% (2/2), done.<br/>
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)<br/>
Receiving objects: 100% (3/3), done.
</code>
</li>
<li>Create and enter an branch:
<code class="wrap bash hljs" style="font-size:20px;">
$ cd demo; git checkout -b dev<br/>
Switched to a new branch 'dev'
</code>
</li>
<li> Do someth important work:
<code class="wrap bash hljs" style="font-size:20px;">$ echo 'This is a demo project' > README.md </code>
</li>
<li> Check status:
<code class="wrap bash hljs" style="font-size:19px;">
$ git status<br />
On branch dev<br />
Changes not staged for commit:<br />
......<br />
modified: README.md<br />
<br />
no changes added to commit (use "git add" and/or "git commit -a")
</code>
</li>
</ul>
</div>
<div style="width:50%;">
<ul>
<li> Add and commit you modification:
<code class="wrap bash hljs" style="font-size:20px;">
$ git add . <br />
$ git commit -m "Import notice" <br />
[dev 01e0c49] Important notice <br />
1 file changed, 1 insertion(+), 93 deletions(-)
</code>
</li>
<li> Push your work to gitlab
<code class="wrap bash hljs" style="font-size:20px;">
$ git push origin dev <br />
Enumerating objects: 5, done.<br />
Counting objects: 100% (5/5), done.<br />
Delta compression using up to 16 threads<br />
Compressing objects: 100% (1/1), done.<br />
Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.<br />
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0<br />
......<br />
To code:biyujiang/demo<br />
5dbb2fb..ef455c4 dev -> dev<br />
</code>
</li>
<li> Merge your work to main branch
<code class="wrap bash hljs" style="font-size:18px;">
$ git checkout main<br/>
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git merge dev<br/>
Updating 5dbb2fb..ef455c4<br/>
Fast-forward<br/>
README.md | 94 +------------------------......-<br/>
1 file changed, 1 insertion(+), 93 deletions(-)<br/>
</code>
</li>
</ul>
</div>
</div>
---
## Container Technology
----
### What is Container Technology?
<div style="margin:auto; width:100%;">
<ul style="padding-top:5px;padding-bottom:5px;">
<span>
<li style="padding-top:5px;padding-bottom:5px;">A lightweight, portable and self-contained way to package and run software
<ul>
<li>Using linux virtualization technology to sperarte apps from host</li>
<li>Run apps in containers without modification on VMs, physical or cloud servers</li>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="1" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:10px;"> Properties of Container
<ul >
<li>Lightweight, portability, isolation, expandability, security</li>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="2" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:10px;"> Types of containerization platform
<ul style="font-size: 28px;">
<li>Docker, Podman, Singularity, LXC ... </li>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="3" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:10px;"> Singularity over Docker
<ul style="font-size: 28px;">
<li> Singularity is specifically designed for HPC and scientific computing</li>
<li> Run with user privilege, avoiding the root privilege issues </li>
<li> Support HPC features such as MPI and GPU acceleration</li>
<li> Integrate better with the host filesystems than docker</li>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="4" -->
</span>
</ul>
</div>
----
### Containers in IHEP Cluster
<div style="margin:auto; width:100%;">
<ul style="padding-top:5px;padding-bottom:5px;">
<span>
<li style="padding-top:5px;padding-bottom:5px;"> IHEP Container envrionment deployed on <code>/cvmfs/container.ihep.ac.cn/</code>
<ul>
<li>Providing `SL5/6/7`, Alma 9 and custom images to support various computing need</li>
<li style="padding-bottom:5px;">Adding <code>/cvmfs/container.ihep.ac.cn/bin/</code> to $PATH to use <code> hep_container</code> directly</li>
<code class="wrap bash hljs" style="font-size:20px;">
$ echo 'export PATH=$PATH:/cvmfs/container.ihep.ac.cn/bin' >> ~/.bashrc
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="1" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:10px;"> User Manual
<ul style="font-size: 36px;">
<li style="padding-top:5px;padding-bottom:5px;">http://afsapply.ihep.ac.cn/cchelp/zh/local-cluster/container/</li>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="2" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:10px;">Supported images: <code>hep_container exec <image-name></code>
<ul style="font-size: 28px;">
<li style="padding-top:5px;padding-bottom:5px;"> Included custom images</li>
<code class="wrap bash hljs" style="width:80%; margin-top:0em; font-size:20px;">
$ hep_container images<br/>
Hep_container support images:<br/>
SL5 : Scientific Linux 5<br/>
SL6 : Scientific Linux 6<br/>
SL7 : Scientific Linux 7<br/>
CentOS7 : CentOS Linux 7.9<br/>
CentOS78 : CentOS Linux 7.8<br/>
CentOS79 : CentOS Linux 7.9<br/>
Alma9 : Alma Linux 9.4<br/>
MYIMAGE : Custom Image file name<br/>
HepcMyImage : Custom Image file name<br/>
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="3" -->
</span>
</ul>
</div>
----
### Using Containers in IHEP Cluster
<div style="margin:0em auto 0em auto; line-height:110%;">
<ul style="padding-top:5px;padding-bottom:5px;">
<span>
<li style="padding-top:2px;padding-bottom:5px; font-size:36px;"> List supported groups: <code>hep_container groups</code>
<ul>
<li style="padding-bottom:2px;">By specifying <code>-g <group></code>, corresponding directories will be mounted in container.</li>
<code class="wrap bash hljs" style="font-size:20px; margin:0;padding:2px;">
$ hep_container groups
Hep_container support groups:
u07|atlas|atlasrun|comet|offline|physics|bes3|higgs|ams|cms...
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="1" -->
</span>
<span>
<li style="padding-top:2px;padding-bottom:2px;font-size:36px;"> Using container environment: <code>hep_container shell <image-name></code>
<ul style="font-size: 28px;">
<li style="padding-top:2px;padding-bottom:2px;">Launching a shell in a container to execute complicated commands.</li>
<code class="wrap bash hljs" style="font-size:20px; margin:0;padding:2px;">
$ hep_container shell Alma9<br />
Apptainer> cat /etc/redhat-release<br />
AlmaLinux release 9.4 (Seafoam Ocelot)
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="2" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:5px;font-size:36px;">Executing simple commands: <code>hep_container exec <image-name></code>
<ul style="font-size: 28px;">
<li style="padding-top:2px;padding-bottom:2px;"> Running commands without entering container environment</li>
<code class="wrap bash hljs" style="font-size:20px; margin:0;padding:2px;">
$ hep_container exec Alma9 cat /etc/redhat-release<br />
AlmaLinux release 9.4 (Seafoam Ocelot)
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="3" -->
</span>
<span>
<li style="padding-top:5px;padding-bottom:5px;font-size:36px;">Using custom image
<ul>
<li style="padding-top:2px;padding-bottom:2px;">Specifing your image with <code>MYIMAGE</code> variable</li>
<code class="wrap bash hljs" style="font-size:20px; margin:0;padding:2px;">
$ export MYIMAGE=/cvmfs/container.ihep.ac.cn/userimages/raser-1.2.sif<br/>
$ hep_container shell MYIMAGE<br />
</code>
</ul>
</li>
<!-- .element: class="fragment" data-fragment-index="4" -->
</span>
</ul>
</div>
---
<h1 class="r-fit-text" style="align:center; margin: 15% auto 15% auto; font-size:4em;">Q & A</h1>
{"title":"Linux Basics and Efficient Tools","type":"slide","font-size":"10pt","slideOptions":{"theme":"moon","font-size":"10pt","number":true,"transition":"slide","width":"80%","height":"80%","minScale":0.2,"maxScale":2},"tags":"Linux, Git, Docker, Container, Reveal"}