.slides, .slides a, .slides p, .slides ul , .slides li{ font-si">
The $5^{th}$ Computing Summer School for High Energy Physics 08/23/2024
--- ## Outline
---- ### Linux? GNU/Linux? - 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 ---- ### Linux Distributions
---- ### An Old Linux Global Map
---- ### What's Your Favorite Distribution? Popular Linux distributions:
- 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
---- ### 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 whoami: display who your are $ whoami
biyj pwd: display where you are $ pwd [-P]
/afs/ihep.ac.cn/users/b/biyj id: identity yourself or other user $ id
uid=12142(biyj) gid=600(u07) groups=600(u07),340(lhaasorun),580(lhaaso),1027(lqcd),1055(qc)...
$ id lihaibo
uid=10515(lihaibo) gid=600(u07) groups=600(u07),290(physics),580(lhaaso),470(offlinerun)...
passwd: change your password (or other accounts). Change from Login page for IHEP cluster $ passwd
Changing password for user biyj.
Current password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
/: the root directory.: the current directory..: the prarent of current directory~: home of current user, like $HOME~jack: the home of user jack-: the the last directory you visited$ cd ~; cd $HOME; cd # return to HOME $ cd .. # go to parent dir $ cd /path/to/dir # enter other dir $ cd - # return previous dir $ 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 $ mkdir dir # create a blank dir under current dir $ mkdir -p dir1/dir2 # recursively create dirs $ rmdir dir # rm an empty dir $ rmkdir -rf dir # rm a dir and files/dirs in it ln to create links$ 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 cat/tac: print a file normally or reversely $ cat a.txt # print normally asfasfd ryturdg $ tac a.txt # print reversely ryturdg asfasfd more: print a file in a page-by-page mannerless: like more, but can scroll up/downview: view a file with vi/vim in ro mode$ cat /dev/null > a.txt $ echo -n > a.txt $ > a.txt $ : > a.txt $ truncate -s 0 a.txt head: print the first few lines of files $ 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 tail: displays the last few lines of a file $ 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 cp: copy files/dirs (-r) to another place$ cp a.txt b.txt # copy a file $ cp -r a.txt c/ d/ # copy a.txt and c/ into dir d $ cp -l a.txt h.txt # hard link with -l $ cp -s a.txt s.txt # soft link with -s $ cp -p a.txt p.txt # mode,ownership,timestamps $ cp --preserve=all a.txt f.txt # all attributes # 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 $ ls a.txt b.txt c.txt $ cp -b a.txt b.txt; ls a.txt b.txt b.txt~ c.txt mv: move or rename files or dirs# move file/dir to dir $ mv a.txt b/ c/ # rename a file $ mv a.txt b.txt # rename dir, dir must not exist $ mv b non-exist-dir $ 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~ $ mv -vb a.txt b.txt renamed 'a.txt' -> 'b.txt' (backup: 'b.txt~') find [path] [options] [exp]$ find . -type f -name "test*" test.1.txt $ find . -type f \( -mtime -10 -o -ctime -10 \) ctime.within.10.txt mtime.within.10.txt $ find . -type f \( -mtime +10 -o +ctime +10 \) ctime.older.10.txt mtime.older.10.txt $ find . -type f -size +1G size.large.1G.txt -exec option{} to replace files found$ find . -type f -empty -exec rm -f {} \; $ find . -type f -size +1G -exec echo -n {} \; $ find . -type f -mtime +365 -exec rm -f {} \; $ find . -type f -mtime +365 -delete biyj and change permission $ find . -type f -user biyj -exec chmod +x {} \; $ find . -type f -name "file*" -print0 \; # '\0' $ find . -type f -name "file*" -print \; # '\n' ps and other commands to view process infos $ ps aux | grep process kill can be used to send signals to processes. Common signals include: $ my_command > my.log 2>&1 & nohup $ nohup my_command > my.log 2>&1
---- ## The Holy War of Editors
let g:mapleader=";"
let mapleader=";" $ view f1 f2 ... $ vimdiff f1 f2 $ vim -O f1 f2 ...
$ vim -o f1 f2 ... $ sed -i 's/old/new/' filename # one line
$ sed -i 's/old/new/g' filename # all lines $ sed -i '3d' filename # del 3rd line
$ sed -i '2,10d' filename # del line 3 to 10 # Insert before 3rd line
$ sed -i '3 i\new_line' filename
# Print only lines matching a pattern
$ sed -n '/pattern/p' filename
# Print a specific line
$ sed -n 'Np' filename
$ sed 's/[0-9]/#/g' example.txt $ sed -e "command1" -e "command2" filename $ grep 'pattern' filename
$ grep -n 'pattern' filename # with line number
$ grep -i 'pattern' filename # ignore case
$ grep -R 'pattern' dir # recursive search
$ grep -w 'world' filename $ grep -v 'pattern' filename
$ grep -c 'pattern' filename
$ grep -o 'pattern' filename
$ grep -E 'foo|bar' filename $ grep '^pattern' filename # beginning
$ grep 'pattern$' filename # ending $ grep -e 'pattern1' -e 'pattern2' filename $ grep -C 5 'pattern' filename
$ grep -A 10 'pattern' filename
$ grep -B 20 'pattern' filename $ grep -h 'pattern' file1 file2 ... $ awk '{print $4}' $ awk '/pattern/ {print $3}' filename $ awk -F _ '{print $0}' $ awk '{print NR, NF}' filename
$ awk '{print $1 + $3}' filename
$ awk '{if ($2 > 100) print $0}' filename $ grep '^pattern' filename # beginning
$ awk '{sum += $3} END {print sum}' filename $ awk 'NR>=3' filename $ awk -v var=value '{print var, $0}' filename $ awk '{$2="new_value"; print $0}' filename Log in to remote server with password:
```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). ```Avoid password with SSH key pair
```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 SSHCreate or modify ~/.ssh/config
```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 ```And log into login servers like:
```bash= $ ssh lxlogin ...... Last login: Sun Aug 18 07:53:08 2024 from 10.100.0.75 [biyj@lxlogin003 ~]$ ``` ---- ### Terminal MultiplexerPeople always say:
Terminal multiplexers give you
Popular Terminal multiplexers
c % " $ ↑|↓|←|→ p # previous
n # next $ test d
unbind ^b
set -g prefix ^a setw -g mode-keys vi bind k selectp -U
bind j selectp -D
bind h selectp -L
bind l selectp -R $ tmux ls $ tmux a[tt] [-t id]
# User info
$ git config --global user.name "John Smith"
$ git config --global user.email "johnsmith@example.com"
# Editor
$ git config --global core.editor vim
$ git config --list $ man git config /etc/gitconfig $HOME/.gitconfig .git/config [alias]
a = add .
v = !gitk
br = branch
ci = commit -m
cm = commit -m
co = checkout
df = diff
dump = cat-file -p
hs = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
last = log -1 HEAD
pl = pull
ps = push
st = status
type = cat-file -t
sum = shortlog -sn ## Initializing one or using existing dir
$ git init demo
$ cd demo; git init ## Clong local repo
$ git clone /path/to/existing/repo/
## Clone remote repo
$ git clone username@host:/path/to/my/repo $ 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 $ git add README $ git status On branch ... Changes to be committed:... new file: README .gitignore to skip unwanted files or directories $ 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 $ 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 $ git commit -m "Add README; Update RELEASE.md" $ git branch dev; git checkout dev $ git checkout -b dev $ git checkout main; git merge dev $ git branch -d dev $ git tag -l v1.0 $ git tag [commit] $ git tag -d $ git log --pretty --graph --date=short <<<<<<< HEADE:index.html Contact: ======= Please contact us at support@gitlab.com >>>>>>> 1a4f:index.html Please contact us at support@gitlab.com $ git add index.html $ git commit -am 'fix conflication' $ git push origin main
---- ### Adding Your SSH Pubkey to Gitlab
Host code
Hostname code.ihep.ac.cn
User git
Identityfile ~/.ssh/id_rsa $ ssh -T code Welcome to GitLab, @biyujiang!
$ git clone code:biyujiang/demo
Cloning into 'demo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done. $ cd demo; git checkout -b dev
Switched to a new branch 'dev' $ echo 'This is a demo project' > README.md $ git status
On branch dev
Changes not staged for commit:
......
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a") $ git add .
$ git commit -m "Import notice"
[dev 01e0c49] Important notice
1 file changed, 1 insertion(+), 93 deletions(-) $ git push origin dev
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (1/1), done.
Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
......
To code:biyujiang/demo
5dbb2fb..ef455c4 dev -> dev
$ git checkout main
Switched to branch 'main' Your branch is up to date with 'origin/main'. $ git merge dev
Updating 5dbb2fb..ef455c4
Fast-forward
README.md | 94 +------------------------......-
1 file changed, 1 insertion(+), 93 deletions(-)
/cvmfs/container.ihep.ac.cn/ /cvmfs/container.ihep.ac.cn/bin/ to $PATH to use hep_container directly $ echo 'export PATH=$PATH:/cvmfs/container.ihep.ac.cn/bin' >> ~/.bashrc hep_container exec $ hep_container images
Hep_container support images:
SL5 : Scientific Linux 5
SL6 : Scientific Linux 6
SL7 : Scientific Linux 7
CentOS7 : CentOS Linux 7.9
CentOS78 : CentOS Linux 7.8
CentOS79 : CentOS Linux 7.9
Alma9 : Alma Linux 9.4
MYIMAGE : Custom Image file name
HepcMyImage : Custom Image file name
hep_container groups -g , corresponding directories will be mounted in container. $ hep_container groups Hep_container support groups: u07|atlas|atlasrun|comet|offline|physics|bes3|higgs|ams|cms... hep_container shell $ hep_container shell Alma9
Apptainer> cat /etc/redhat-release
AlmaLinux release 9.4 (Seafoam Ocelot) hep_container exec $ hep_container exec Alma9 cat /etc/redhat-release
AlmaLinux release 9.4 (Seafoam Ocelot) MYIMAGE variable $ export MYIMAGE=/cvmfs/container.ihep.ac.cn/userimages/raser-1.2.sif
$ hep_container shell MYIMAGE