Introduction To The Linux Command Line - CSCAR

1y ago
2 Views
1 Downloads
8.41 MB
57 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Kaydence Vann
Transcription

Introduction to theLinux Command LineKen WeissHITS Computational Research Consulting Division

A word from our sponsor This class is brought to you courtesy of:Advanced Research Computing – Technical ServicesARC-TSFor more information please click on:http://arc-ts.umich.edukgw 201621/15

RoadmapThe command shellNavigating the filesystemBasic commands & wildcardingShell redirection & pipeliningEditing text filesPermissionsProcessesEnvironment variables and customizing your sessioncja/kgw 201631/16

Course TextWilliam E Shotts, Jr.,“The Linux Command Line: AComplete Introduction,”No Starch Press, January 2012.Download Creative Commons Licensed version mmand/TLCL/13.07/TLCL-13.07.pdf.cja 2014410/14

The command shellcja 2014510/14

What you are used to usingkgw 201661/16

What you will be usingkgw 201671/16

The command shellThe command shell is an application that reads command linesfrom the keyboard and passes them to the Linux operatingsystem to be executed.When you login to a remote Linux system, using a tool likessh, you will automatically be connected to a shell.Your computing session is kept separate from other user’scomputing sessions, because they are “enclosed” in a“shell”.On your desktop, laptop, or tablet, you may have to find andexecute a terminal emulator application to bring up a shell ina window.cja 2014810/14

The command shellcja e-the-linux-utilities-parts-of-the-kernel-shell

Types of shellsStandard Linux shell (used in this course)bash“Bourne-again” shellOther shellsshcshtcshBourne shell, original AT&T Unix shell“C shell”, common on older Unix systems“Enhanced C shell”, better version of cshWhat shell am I using? echo SHELLFor more details on the differences between shells, nstream-nix-shellscja 20141010/14

The command lineA basic way of interacting with a Linux systemExecute commandsCreate files and directoriesEdit file contentAccess the webCopy files to and from other hostsRun HPC jobs do things you can’t do from the conventional pointand-click Graphical User Interface (GUI)cja 20141110/14

Why command line?1.Linux was designed for the command line2. You can create new Linux commands using the commandline, without programming3. Many systems provide only the command line, or poorlysupport a GUI interface Such as most HPC systems4. Many things can be accomplished only through thecommand line Much systems administration & troubleshooting5. You want to be coolcja 20141210/14

Connecting via sshTerminal emulatorsLinux and Mac OS XStart TerminalUse ssh commandWindowsU-M PuTTY/WinSCP (U-M Blue ://www.chiark.greenend.org.uk/ sgtatham/putty/cja 20141310/14

Logging in to a hostWe will be using the host: training-linux.aura.arc-ts.umich.edufor our class.For Mac or other Linux workstation, from a terminal windowtype: ssh uniqname@training-linux.aura.arc-ts.umich.eduOn a PC, start PuTTY. In the“Host Name (or IP address)” boxtype:training-linux.aura.arc-ts.umich.eduClick on the “Open” button.Once connected, you will see:“login as:”. Type in youruniqname and press: enterkgw 20161410/14

Logging in to a hostYou will be ich.edu's password:”Enter your Level 1 password and press enter.You are now logged into a shell on the training-linux hostYour shell prompt looks like this:uniqname@training: cja 20141510/14

The shell promptThe “uniqname@training: “ is the shell promptThis means the shell is waiting for you to typesomethingFormat can vary, usually ends with “ ” , “%” or “#”If or %, you have a normal shellThis shell has your privilegesIf #, you have a so-called “root shell”This shell has administrator privilegesYou can do a great deal of irreversible damagekgw 20161610/14

Typing into the shellBasic input line editing commandsBackspace erases previous characterLeft and right arrow move insertion point on the lineControl-c interrupts whatever command you started and returnsyou to the shell prompt (usually)Control-u erases the line from the beginning to the cursorControl-k erases the line from the cursor to the endEnter executes the line you typedUp and down arrow will access your command historyType “exit” and press Enter without the quotes to exit the shellClick the red "close" icon at the top of the Terminal window to closeit (on a Mac)cja 20141710/14

Lab 1Task: Enter some basic commands date id ps df -kh who topcja 2014# type Control-c or q to exit1810/14

Navigating the filesystemcja 20141910/14

Linux Filesystem ConceptsFiles are stored in a directory (think: folder)Directories may contain other directories aswell as filesA hierarchy of directories is called a directorytreeA directory tree (a connected graph with nocycles) has a single, topmost root directoryA directory tree, rooted at the system rootdirectory “/”, is called a filesystemcja 20142010/14

A Linux Filesystemkgw down/unix/lesson2.html

Linux Filesystem ConceptsA file is accessed using its path nameAbsolute path name/dir1/dir2/ /dirn/filename/usr/X11R6/binRelative path namecurrent-working-directory/filenamebinEvery shell maintains a notion of a current working directoryInitialized at login to your home directoryChanged via cd commandTwo special directories. refers to the current directory. refers to the current directory’s parent directoryMany ways to get “home” refers to your home directory HOME is a synonym for username refers to a user’s home directorycja 20142210/14

Basic commandscja 20142310/14

PrerequisitesSome fundamental commands: file file# what kind of file is file? cat file# display contents of text file less file# paginate text file man command# get info about commandExercise: figure out how to make the date commanddisplay the date in Coordinated Universal Time (UTC)cja 20142410/14

Navigating the filesystemSome fundamental commands: pwd# print working directory cd dir# make dir the current working directory cd# cd to your home dir cd cja# cd to cja’s home dir mkdir dir# create directory dir rmdir dir# remove (empty) directory dir rm -fR dir# remove directory dir (empty or not) tree# display dir treecja 20142510/14

Lab 2Task: navigate the file systemCommands: cd# make your home directorythe current working directory pwd# print working directory mkdir foo# create directory foo cd foo# cd to the foo directory mkdir bar# create directory bar tree# display foo’s directory tree.(Use tree -A in PuTTY)cja 20142610/14

Listing info on filesls – list information about files ls# list contents of cur dir ls dir# list contents of dir ls -l# list details of files in cur dirincluding access, owner & group,size, and last-modified time ls -t# list newest files first ls -R dir# list all files in tree dir ls -lt dir# options can be combined ls -hl dir# list all files in human readableformatcja 20142710/14

Working with filesThese commands manipulate files mv big large# rename file big to large cp big large# copy file big to large cp -r dir1 dir2# copy dir tree dir1 to dir2 cp f1 f2 dir# copy file1 and file2 to directory dir mkdir dir# create empty directory dir rmdir dir# remove empty directory dir rm file# remove file file rm -r dir# remove directory tree dircja 20142810/14

Lab 3Exercise:Create a directory named tutorial in your homedirectory. In that directory, create a directory namedsample and a directory named test . Create a filenamed msg in directory test that contains a copy of thefile /etc/os-release.Extra credit: Make the last-modified time of your copyidentical to that of /etc/os-release. Hint: look at theoptions of the copy commandcja 20142910/14

Permissionscja 20143010/14

File PermissionsThree permission bits, aka mode bitsFiles: Read, Write, EXecuteDirectories: List, Modify, SearchThree user classesUser (File Owner), Group, Otherman chmodcja 20143110/14

File Permissionskgw 201532http://www.csit.parkland.edu/ smauney/csc128/fig permissions.jpg

File Permissions, examples-rw------- cja lsait 40 Oct 1 12:03 foo.bz2file read and write rights for the owner, no access foranyone elsechmod u rw,g r,o file-rw-r----- cja lsait 40 Oct 1 12:03 foo.bz2file read and write rights for the owner, read formembers of the lsait group and no access for othersdrwxr-x--x cja lsait 4096 Oct 1 12:15 barlist, modify, and search for the owner, list and searchfor group, and execute only for otherscja 20143310/14

Lab 4Task: copy sample files for further exercisesCommands: cd# make your home directorythe current working directory pwd# print working directory to verify youare in your home directory mkdir training# create directory training cd training# cd to the training directory cp -rf /home/kgweiss/cmdline/. .# copies sample files to training directorycja 20143410/14

Compression, archiving &wildcardscja 20143510/14

Compressing and archivingThese commands compress and archive files gzip foo# compress foo to foo.gz gunzip foo# uncompress foo.gz to foo bzip2 foo# better compress foo to foo.bz2 bunzip2 foo# uncompress foo.bz2 to foo tar -cf foo.tar bar# archive subtree bar in file foo.tar tar -xf foo.tar# restore archive from file foo.tar tar -tf foo.tar# list files in archive file foo.tar tar -zcf foo.tgz bar # archive and compress tar -jcf foo.tjz bar # archive and compress betterExercise: Archive and compress the files in the training directory to a filenamed examples train.tgzcja 20143610/14

WildcardsThe shell accepts wildcarded argumentsThis is also called "shell globbing"Wildcards:?*[chars][c1-c2][ chars]Matches a single characterMatches zero or more charactersMatches any of the charsMatches chars ‘c1’ through ‘c2’Matches any but the chars ls foo.?# match files named foo.x, where xis any character echo *.[cs]# echo files that end in .c or .s mv [o-z]* save# move files starting with o throughz to directory save echo [ A-Z]?# ?cja 20143710/14

Shell redirection &pipeliningcja 20143810/14

Shell redirectionA Linux command can have its inputs and outputs redirected ls foo# put list of files in currentdirectory into file foo ls bar# add list of files in currentdirectory to end of file foo sort bar# sort lines from file bar sort EOFwhiskeybravotangoEOF# sort lines entered at keyboard# (this is a “here document”) wc -l /etc/os-release /mycounts# count number of lines from file/etc/os-release and put result infile mycounts in my home directorycja 20143910/14

More Linux commandsMore useful Linux tool commands grep string# show lines of input containingstring tail# show last few lines of input head# show first few lines of input sort# sort the input du -sh# report the size of the current directory du -sh dir# report the size of directory dir who# gives a list of the users currentlylogged in# keep the output from a command startingat the xx character in the line and endingat the yy character cut -cxx-yycja 20144010/14

Shell pipeliningA Linux command can have its output connected to theinput of another Linux command ls wc –l# count files in currentdirectory last grep reboot # when did we reboot?Exercises:How many users are currently logged in?How many unique user IDs are currently logged in?cja 20144110/14

Editing text filescja 20144210/14

Editing text filesSimple editornano"What you see is what you get” editorSimple to learn if you want to get started quicklyNo mouse support. Arrow keys for navigationSupported editorsvi or vimemacsPowerful but more complexIf you have time and inclination to become proficient,spend time herecja 20144310/14

Text filesWatch out for source code or data fileswritten on Windows systemsUse these tools to analyze and convert sourcefiles to Linux formatfiledos2unixunix2doscja 20144410/14

File Transferscja 20144510/14

File TransfersEventually, you will need to move/copy files to and from your computer and aserver/workstation/cluster. You can do this using the secure copy command (scp) in a terminalwindow.To transfer files (i.e. foobar.txt) FROM your local host TO a remote host use: scp foobar.txt your username@remotehost.edu:/some/remote/directoryTo transfer files (i.e. foobar.txt) FROM a remote host TO your local host use: scp your username@remotehost.edu:foobar.txt /some/local/directoryTo copy a directory, repeat as above adding the -r flag. ( scp -r )Graphical, drag-and-drop scp programs are available for Windows and Mac platforms.(WinSCP – Windows, Cyberduck – Mac)DemonstrationI will Copy the file headtail.txt from the training directory to /home/kgweissdirectory using SCP on the remote host flux-xfer.arc-ts.umich.educja/kgw 2015461/15

Processescja 20144710/14

ProcessesModern operating systems are usually multitasking, meaning thatthey create the illusion of doing more than one thing at once byrapidly switching from one executing program to another. TheLinux kernel manages this through the use of processes. Processesare how Linux organizes the different programs waiting for theirturn at the CPU.On Linux, every program runs in a processYou can examine these processesman pspsps axtopcja 20144810/14

ProcessesYou can signal a running processTo stop it, or "kill" itman killcja 20144910/14

Additional commands quota -Q -s USER# show disk quota for USER grep “sometext” somefile# find & print sometext if foundin somefile history# displays last n commands entered(execute again with !###) clear# clears the screen diff -w file1 file2# compare file1 with file2ignoring all white space which command# prints the full path to command acommand tee filename# takes the results from acommand andprints them to the screen and tothe file filename(Use tee –a to append to filename)# reads and executes the commands containedin filename source filenamecja 20145010/14

Environment Variables andCustomizing Your Sessioncja 20145110/14

Environment VariablesAn environment variable is a named object that contains data used byone or more applications. In simple terms, it is a variable with a nameand a value.The convention in Linux is for the environment variable to be alluppercase letters.To use an environment variable, prefix the variable name with You can see the value of an environment variable by typing: echo VARIABLENAMEYou can see all the environment variables defined for your sessionby typing: envYou can set an environment variable by typing: export VARIABLENAME valuecja/kgw 2015521/15

Common EnvironmentVariablesUSER# USER -- user login namePATH# PATH -- a list ofdirectories to look into for programsand filesHISTSIZE# HISTSIZE -- number of commandsto keep in historyHOSTNAME# HOSTNAME -- fully enumerated host nameHOME# HOME -- home directory of the userTERM# TERM -- terminal typeSHELL# SHELL -- shell type you are usingcja 20145310/14

Customizing Your SessionYou can modify certain aspects of your session to do your work interms that are easier/more useful for you. See chapter 11 in Schott’sbookChanges can be made in /.bashrc file.It is recommended that you use an external file, (in our class, /.custom) and then source it from the .bashrc fileYou can:Set an aliasExport an environment variableChange directoriesExecute a Linux command or an external programExercises1) Modify the .custom file in the training directory creating a new alias named ‘llh’that gives a directory listing in human readable file sizes2) Create a new environment variable CLASS that points to your training directory3) Source this file and see if your customizations workedkgw 2016541/16

Any Questions?Ken WeissHealth Information Technology & umich.edu734 763 7503cja 20145510/14

References1. http://en.wikipedia.org/wiki/History of Linux2. nix/lesson2.html3. William E Shotts, Jr., “The Linux Command Line: A Complete Introduction,” No StarchPress, January 2012. Download Creative Commons Licensed version mmand/TLCL/13.07/TLCL-13.07.pdf.4. Learning the nano editor1. The nano text editor - http://mintaka.sdsu.edu/reu/nano.html2. Beginners guide to nano - . Learning the VI editor1. VIM Adventures - http://vim-adventures.com/2. Graphical cheat sheet - http://www.viemu.com/vi-vim-cheat-sheet.gif3. Interactive VIM tutorial - http://www.openvim.com/cja 20145610/14

Have a Nice Daycja/kgw 2015571/15

The command shell The command shell is an application that reads command lines from the keyboard and passes them to the Linux operating system to be executed. When you login to a remote Linux system, using a tool like ssh, you will automatically be connected to a shell. Your computing session is kept separate from other users

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

Linux in a Nutshell Linux Network Administrator’s Guide Linux Pocket Guide Linux Security Cookbook Linux Server Hacks Linux Server Security Running Linux SELinux Understanding Linux Network Internals Linux Books Resource Center linux.oreilly.comis a complete catalog of O’Reilly’s books on Linux and Unix and related technologies .

Command Library - String Operation Command Command Library - XML Command Command Library - Terminal Emulator Command (Per Customer Interest) Command Library - PDF Integration Command Command Library - FTP Command (Per Customer Interest) Command Library - PGP Command Command Library - Object Cloning

Chính Văn.- Còn đức Thế tôn thì tuệ giác cực kỳ trong sạch 8: hiện hành bất nhị 9, đạt đến vô tướng 10, đứng vào chỗ đứng của các đức Thế tôn 11, thể hiện tính bình đẳng của các Ngài, đến chỗ không còn chướng ngại 12, giáo pháp không thể khuynh đảo, tâm thức không bị cản trở, cái được