mini introduction to linux - sjtucms.sjtu.edu.cn/gs/doc/dft2019/mini-intro-linux.pdf · lingti...
TRANSCRIPT
1896 1920 1987 2006
Mini Introduction to Linux
LT Kong (孔令体)
Dec 18th, 2019
LingTi Kong, [email protected] 2
Operating System
An operating system (OS) is system software that manages
computer hardware, software resources, and provides common
services for computer programs.
LingTi Kong, [email protected] 3
Linux is a Unix clone written from scratch by Linus Torvalds with
assistance from a loosely-knit team of hackers across the Net.
Unix is a multitasking, multi-user computer operating system originally
developed in 1969 by a group of AT&T employees at Bell Labs.
64% of the world’s servers run some variant of Unix or Linux. The
Android phone and the Kindle run Linux.
Network based
What is Linux?
LingTi Kong, [email protected] 4
Linux Distributions
LingTi Kong, [email protected] 6
Remote connection
CMS Server info:
Address: 202.120.49.140
Port: 1022
Username: user???
Password: CMSWin?????
http, ftp, ssh, …
putty, winscp, powershell, MobaXterm
LingTi Kong, [email protected] 7
MobaXterm
LingTi Kong, [email protected] 8
Directory
Directories can hold files and other directories
/
bin etc hometmp
backup
user1user2
… …
usern
public_html
file1
index.html
root
LingTi Kong, [email protected] 9
PermissionsPermission owner group size modification-time name
LingTi Kong, [email protected] 10
A shell is a computer program that interprets the commands you type and
sends them to the operating system. Secondly, it provide a programming
environment consisting of environment variables.
To determine your shell type:
echo $SHELL (shell prints contents of env)
echo “$SHELL” (shell still processes env. variable)
echo ‘$SHELL’ (shell treats env. variable as simple literal)
To determine the path to the shell program, type:
which bash
Shell
LingTi Kong, [email protected] 11
UNIX/Linux paths
“~” (tilde) points to the user’s home directory. Useful if you are logging into a workstation with many users.
Many of the other paths are inaccessible and unimportant to you
~ is the default working directory when you log in.
If you are user “usern”, then /home/usern/file1 is the same as ~/file1.
“.” refers to the current directory
“..” refers to the parent directory.
If you are in /home/usern/, then ../ refers to /home/.
LingTi Kong, [email protected] 12
Basic commands
man: manual. Use “man command” to bring up a manual entry for command or
program command.
clear: clear. Clears the screen.
ls: list. Lists folders/files in a directory
cd: change directory.
Use “cd name” to navigate to directory name.
pwd: print working directory. Prints the path of the current directory.
cd -: go back to the previous directory
echo: display line of text/string that are passed as an argument
LingTi Kong, [email protected] 13
More commands
mkdir: make directory. Use “mkdir name” to create a new directory in the current
directory named name.
cp: copy. Use “cp src dest” to create a new file, dest which is a copy of src. Can
also use “cp srcs directory” to copy all src files to directory.
mv: move. Same as copy, but deletes the original file.
rm: remove. Use “rm file(s)” to delete files
rmdir: remove directory. Use it to delete an empty directory
You can not get your files back after removing them!
LingTi Kong, [email protected] 14
More commands
cat: concatenate files and displays the output to the standard output
seq: Print numbers from FIRST to LAST, in steps of INCREMENT.
Pipe and redirection:
cmd1 | cmd2: cmd2 will take the output of cmd1 as its input.
cmd1 > filename: the output of cmd1 will be redirected to a file named filename; if filename
exists already, it will be rewritten.
cmd1 >> filename: the output of cmd1 will be redirected to a file named filename; if filename
exists already, it will be appended.
cmd1 < filename: the input of cmd1 will be read from a file named filename.
LingTi Kong, [email protected] 15
Some tips
“tab” for auto-complete.
Partly type in a file/directory name, tab will auto-complete it
“*” “?” is used as a wild card.
“rm blah*” removes all files start with blah
“rm blah?” removes all files start with blah and with one extra letter/number.
Using “cp public/* private/” copies all files in your public directory into your
private directory, and keeps all file names intact.
Always be careful with “rm -f *” and/or “rmdir -f *” and/or “rm –rf *”
LingTi Kong, [email protected] 16
Shell programming: script Script: a collection of commands/programs to run.
Loop:
• for var in list; do; things to do repeatedly; done
Branches:
• if condition then; things to do; else; other things to do; endif
Variable substitution:
• varname=“var-value”
• ${varname} or $varname
LingTi Kong, [email protected] 17
Programs
Some basic/common UNIX programs:
emacs: text editing
vim: text editing
gcc: C compiler
gfortran: fortran compiler
gnuplot: 2D drawing and scripting; data fitting
LaTeX: A document preparation system, a high-quality typesetting system
LingTi Kong, [email protected] 18
Job submission on clusters
In general, a queueing system is needed for large computer clusters to
use the computational resources efficiently/fairly/economically.
PBS/Torque is used on CMS.
• Job submission:
• qsub: native command, man qsub
• submit: convenient script, submit –h
submit –n 4 lmp
submit –n 4 –S ./run
• Job status: qstat
• Cancel job: qdel job-id
1896 1920 1987 2006
Enjoy & Thanks