Introduction to the Linux Command Line September 2012
Presented by Oralee Nudson ARSC User Consultant & Student Supervisor
[email protected]
Presentation Topics Information Assurance and Security Awareness
Linux Overview Navigating the File System Connecting to Remote Systems
Working with Files Working with Active Processes
Customize the User Environment
Feedback and Exercises
Information Assurance and Security Awareness Download the ARSC Information Assurance pdf
document or take the Information Systems Security Awareness course. Both are available here: www.arsc.edu/arsc/support/policy/ia
Linux Overview Unix-like OS developed by Linus Torvalds in 1991 Open Source Software “Runs on more computer hardware platforms than any other OS”
Run on Supercomputers, embedded systems The shell is a command line interface to the OS
Open a “terminal” window Edit files Check the status of running processes Send signals to processes
Navigating the File System Linux is a collection of files and directories (think of folders)
The top directory is called the “root”.
Some directories
contain actual files, others provide access to hardware devices
Commands:
pwd cd ls ls –al ls $HOME mkdir rmdir
Connecting to Remote Systems Login with: ssh –X –Y
[email protected] Example: ssh –X –Y
[email protected]
Copy files with: scp myfiles.tar.gz
[email protected]:~/phys693/
Example: scp myfiles.tar.gz
[email protected]:~/phys693
Use a GUI: filezilla, fetch, winscp
Working with Files Common Text Editors vim or gvim emacs nedit
Quickly view the contents of a file with: cat less Exit with “q”
File Input/Output & Redirection Three forms of input/output: “stdin” from keyboard or a file “stdout” to screen or a file “stderr” to screen or a file
Redirect I/O with Alligators, “>” or “>>” or “&1” mpirun $WORKDIR/wrf.exe > wrf.mix.out 2>&1 &!
File and Directory Permissions Permissions control access to files and directories Three categories of access: user group (type “groups” to determine which you belong to) other Three categories of permissions: read write execute Use “chmod” to modify access permissions chmod u+r myDir chmod g+rx myFile chmod go-rwx myFile
File and Directory Permissions Security Awareness: World write permissions are discouraged. ARSC Security policies on dot file permissions: http://www.arsc.edu/arsc/support/policy/ secpolicy/index.xml#dot !
Working with Active Processes “ps” allows you to view process statuses Useful variations “ps –elf” and “ps –aux”
“top” to view what’s eating up all the CPU resources! Exit with “q”
Send a signal: CTRL+c (kill) CTRL+z (suspend)
Search with “grep”, then “sort”
Common Linux Commands “kill” to terminate processes
% ./loop.sh & [1] 3039 % ps PID TTY 2779 pts/1 3039 pts/1 3041 pts/1 3042 pts/1 % kill 3039 % ps PID TTY 2779 pts/1 3055 pts/1
The & puts the process in the background. TIME 00:00:00 00:00:00 00:00:00 00:00:00
CMD bash loop.sh sleep ps
TIME CMD 00:00:00 bash 00:00:00 ps
The process id for loop.sh is 3039. The sleep process was started by loop.sh and will be killed when loop.sh is killed Kill process 3039. The processes are gone
Customizing the User Environment Environment Variables store short strings of information
Important variables: $PATH, $HOME, $CENTER / $SCRATCH
The shell auto-expands variables Set with
bash: export CHUBBY_BUNNIES=funny! bash: export PATH=${PATH}:/u1/uaf/nudson/bin! csh/tcsh: setenv CHUBBY_BUNNIES funny! csh/tcsh: setenv PATH ${PATH}:/u1/uaf/nudson/bin!
View with echo $CHUBBY_BUNNIES
Customizing the User Environment Important info about $PATH Its how the shell searches for executables, so you don’t have to enter the command’s full path Order is important “.” is intentionally left out for security purposes Use “./fun_script” to run local scripts, or list out the entire path: /u1/uaf/nudson/fun_script
“env” lists all environment variables currently set
User Environment Customize your login by modifying your $HOME “.” files http://www.arsc.edu/arsc/support/news/hpcnews/ hpcnews361/index.xml#article2 Example for bash users: Add the following to your ~/.profile file: export PS1=“Good Morning!% ” Then source the file with “. ~/.profile”
Special Shell Characters “*” matches anything “?” matches a single character “&” backgrounds a running process Bring process back to foreground with “fg” Try with CTRL+Z
Questions?
[email protected]
(907) 450-8602
Evaluation Form: http://www.arsc.edu/arsc/support/training/ trainingevalform/index.xml
Exercises http://people.arsc.edu/~bahls/classes/ exer.tar.gz