https://bit.ly/3bUvR1s presentation slides Introduction to Linux Dr. Yongjun Choi 03/16/2021 Geting help
• Wiki: https://wiki.hpcc.msu.edu/x/4ACE • Submit a ticket: https://contact.icer.msu.edu/contact External resources to learn Linux http://ss64.com/bash/ "An A-Z Index of the Bash command line for Linux." with links to 'man' manual page for each. It includes many commands that you will never use, or are specifc to certain versions of linux https://fosswire.com/post/2007/08/unixlinux-command-cheat-sheet/ useful cheatsheet organized by topic https://cvw.cac.cornell.edu/linux/ Full intro to Linux http://guide.bash.academy step by step intro with lots of explanatory text MSU HPC runs Linux • We will use the MSU High Performance Computing Cluster for this course. • consistent experience (Windows, Mac laptop diversity) • It’s a system we know • Highly availability • Course is pre-requisite for other HPCC courses Get started • 1. Install/identify laptop software to connect • 2. Connect to HPC with secure shell • 3. Does your account work? Troubleshoot if necessary • 4. Test basic commands • Step 1: Install Software (if you haven’t) • Windows: install ‘MobaXterm’ free Unix emulation app • When installed, start program and then start New Session • Mac OS X: included a unix terminal, but install Xquartz for GUI • Open the application /Applications/Utilities/Terminal.app Get connected • From the terminal/MobaXterm • Type: ssh [email protected] • You can also use: ssh -Y [email protected] • -Y (or -X) is an option for GUI • Enter password - it is hidden and doesn’t look like you are typing, but you are. Linux commands • What is command? • $
• Linux includes a built in manual for nearly all commands. Type ‘man’ followed by the commands. e.g. • $man man • To navigate the man pages use the arrow keys to scroll up and down or use the enter key to advance al ine, space bar to advance a page, letter u to go back a page. Use the q key to quit out of the display. • The manual pages often include these sections: • Name: a one line desctiption of what it does • Synopsis: basic syntax for the command line. • Description: describes the program’s functionalities. • Options: lists commnand line options available for this program. • Example: examples of some of the options available. • See Also: list of related commands. • Note that options can be with single dash ‘-‘ or double dash ‘—’ Learning commands with manual pages • review tha man pages of common fle/directory commnds • ls, mkdir, cp, pwd, cat • How can you list all fles in a folder, including hidden fles that start with a dot (.)? • Which command would create a folder ‘class’ in your home directory? Can you do that? what are the options for this command? • What does pwd do? Shell environment variables • Shell maintains and you can set ‘variables’ that the shell uses for confguration and in your script. • Variables start with $, and can be seen with echo $VARNAME • Explore common variables with the echo command and list what they are • $HOME, $USER, $SHELL, $PATH • Combine variables in an echo command to make a greeting. • Set a variable of your own, then use in the sentence. • GREETING=Hello; echo $GREETING, $USER - welcom to $HOME • https://wiki.hpcc.msu.edu/display/ITH/1.+Variables+-+Part+I • https://wiki.hpcc.msu.edu/display/ITH/1.+Variables+-+Part+II $PATH • BASH looks for programs in each folder listed in $PATH • When you type a program name, how does the shell fnd it? Let’s try the wich command, it shows the location of programs. • which date • which less • which python • each of these folders in the path variable. Command input/output • Most commands take text as input and output results as text • $ ls -l output text to the screen • $ ls -l > flelist.txt redirect text into a new fle ‘flelist.txt’ • $ ls -l >> flelist.txt redirect text into ‘flelist.txt’ (added at the end of the fle) • $ ls -l | grep txt pipe text into another command • $ wc -l < flelist.txt redirect fle as input into command • $ cat flelist.txt |wc -l outputfle, pipe into command • Some commands for data • wc: count words, lines or characters • who | wc -l # number of users logged in • grep: fnd patterns in fles or data, returns just matching lines • who |grep $USER • sort: given a list of items, sort in various ways • who | sort • head: list only top n lines of fle • who > who.txt; head who.txt • tail: list only last n lines of fle Some commands for data • zip: creat zip of multiple fles • unzip: unzip • tar: create (tar -c) or extract (tar -x) ‘tape archive’ fle.
• Exercise : • Using the man pages, fnd out what the default number of lines that head and tail will display, and how to limit those to just one line • Can you tar all fles and folders in workshop folder? Question? Use man. Creating/editing text files • You can create/edit fles on your local machin and transfer them using ftp app. • Downside: very slow process. • need to run command ‘dos2unix’ if the fle is created under Windows system. • Much faster in the long term to learn how to edit fles with Linux editors. Editing a file with editors Editors • There are many editors in Linux • Choice of an editor is really a religion. • emacs (popular, powerful) • vi/vim/gvim (popular, powerful) • nano (simple, easy to learn) • gedit (GUI) • Today, we will learn nano a little. To start, type • nano flename • Commands are in the bottom. (^ means control key) nano • EX: create fle ‘hello.sh’ with nano, and write echo ‘Hello!’, and save it. • nano hello.sh GUI • Windows: MobaXterm works out of the box • Mac: First launch Xquartz, then • ssh -Y [email protected] • Launch GUI editor on a dev-node • gedit hello.sh Shell scripting • https://wiki.hpcc.msu.edu/display/ITH/Learning+the+Shell