Sobell ch02 – Getting Started PDF

Document Details

Uploaded by Deleted User

UTD

2018

Matthew Helmke and Mark G. Sobell

Tags

Linux commands shell programming computer science textual interface

Summary

This document is a chapter from a book about Linux commands, editors, and shell programming. It provides an outline and introduction to connecting to and using Linux, including how to log in, change your password, and check the system status. The document covers topics such as file systems, paths, and commands used within the Linux environment .

Full Transcript

Sobell Chapter 02 A Practical Guide to Linux Commands, Editors, and Shell Programming, 4ed. By Matthew Helmke and Mark G. Sobell. © 2018 Prentice Hall. ISBN: 9780134774626. ** Available online via UTD ebook Safari Sobell ch02 – Getting Started A Practical Guide to Linux® C...

Sobell Chapter 02 A Practical Guide to Linux Commands, Editors, and Shell Programming, 4ed. By Matthew Helmke and Mark G. Sobell. © 2018 Prentice Hall. ISBN: 9780134774626. ** Available online via UTD ebook Safari Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Outline Log in on a Linux system using the textual interface Describe the advantages of the textual interface Correct typing mistakes on the command line Use kill to abort program execution using the termination signal Repeat and edit previous command lines Understand the need to be careful when working with root privileges Use man and info to display information about utilities Use the ––help option to display information about a utility Change your password from the command line Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. How to get connected (log into Linux system) a graphical user interface (GUI) or the command-line interface (CLI). We will study CLI throughout this book and this course. For GUI (log in and use Linux), use a terminal emulator such as xterm, Konsole, GNOME Terminal, Terminal (under macOS), a virtual console, or mobaXterm. Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Logging In from a Terminal Emulator (e.g., Windows command) ssh cs1.utdallas.edu –l rkm010300 Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Logging In from a Terminal (Emulator) ssh cs1.utdallas.edu –l rkm010300 Type password Note. As you type your password, the cursor is not moving. Now you are in cs1, ready to use cs1 Linux system. Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Try a few commans: whoami hostname date Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Once you are done, to log out, type: exit Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. If you like to check whether cs1.utdallas.edu is up and running (and whether your laptop is connected to Internet), type: ping cs1.utdallas.edu Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. If cs1 is down, try to check or log in to cs2 (instead of cs1) ping cs2.utdallas.edu ssh cs2.utdallas.edu -l rkm010300 Note. If you use ssh first time to cs2, cs2 will ask you to continue. Say yes. Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Once you log in, you are in a shell (an environment provided by Linux) so that you can use the system (without so much overhead or setup). Try the following echo commands to display your default settings (set by your sys admin) for: (1) shell environment, (2) home directory, (3) path echo $SHELL echo $HOME echo $PATH Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. To set a local variable (in shell), For example, a variable named x and set its value to be 1. {cslinux1:~} x=1 {cslinux1:~} echo $x 1 {cslinux1:~} x=2 {cslinux1:~} echo $x 2 Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Remember that a shell is a command-line interpreter that reads user input and executes commands. The user input to a shell is (1) normally from the terminal (an interactive shell) or (2) sometimes from a file (called a shell script). For (2), It is a shell-script program (containing a series of commands to be run). We study shell-script later in Chapters 8 and 10 in detail. Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Linux file system Linux maintains files and directories (as you create, update, delete it). File system The UNIX file system is a hierarchical arrangement of directories and files. Everything starts in the directory called root, whose name is the single character /. Filename The names in a directory are called filenames. The only two characters that cannot appear in a filename are the slash character (/) and the null character. The slash separates the filenames that form a pathname (described next) and the null character terminates a pathname. For portability, POSIX.1 recommends restricting filenames to consist of the following characters: letters (a-z, A-Z), numbers (0-9), period (.), dash (-), and underscore (_). Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Pathname A sequence of one or more filenames, separated by slashes and optionally starting with a slash, forms a pathname. A pathname that begins with a slash is called an absolute pathname; otherwise, it’s called a relative pathname. For example, Unix/Linux keeps the userid information in a file (passwd) in directory (/etc). That is, the absolute path name of this file is: /etc/passwd If you created a file named hello.c, then its relative path name is:./hello.c Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Working Directory Every process has a working directory, sometimes called the current working directory. This is the directory from which all relative pathnames are interpreted. A process can change its working directory with the chdir function. For example, if you change your current working directory to /etc by cd /etc then your current working directory is now: /etc Home Directory The working directory is set to be one’s home directory when logged in. One’s home directory is set in /etc/password file for each user, set by Sys Admin. echo $HOME cd $HOME Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Try ls command to list all the files and directories of current directory. With option -l, ls will display detailed information for each file and directory. ls ls -l ls -l hello.c ls hello* ls *.c Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. Try a few more commands man command apropos command touch filename which command cat filename info head rm filename tail mkdir directoryname ps cd directoryname kill rmdir directoryname su cp filename1 filename2 sudo passwd cat --help Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. The --help Option Another tool you can use in a textual environment is the ––help option. Most GNU utilities provide a ––help option that displays information about the utility. A nonGNU utility might use a –h or –help option to display information about itself. $ cat --help Usage: cat [OPTION] [FILE]... Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, --number-nonblank number nonempty output lines, overrides -n -e equivalent to -vE -E, --show-ends display $ at end of each line... If the information that ––help displays runs off the screen, send the output through the less pager (page 34) using a pipeline (page 60): $ ls --help | less Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. The bash help Command The bash help command displays information about bash commands, control structures, and other features. From the bash prompt, give the command help followed by the keyword you are interested in. Following are some examples. $ help help help: help [-dms] [pattern...] Display information about builtin commands. Displays brief summaries of builtin commands. If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise the list of help topics is printed.... Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. $ help echo echo: echo [-neE] [arg...] Write arguments to the standard output. Display the ARGs on the standard output followed by a newline. Options: -n do not append a newline... $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a test succeeds.... Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. HOW TO BUILD -- UNIX Type 'make'. This builds the library libbz2.a and then the programs bzip2 and bzip2recover. Six self-tests are run. If the self-tests complete ok, carry on to installation: To install in /usr/local/bin, /usr/local/lib, /usr/local/man and /usr/local/include, type make install... Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. What to Do If You Cannot Log In and a few tips The username and password are case sensitive. Make sure the CAPS LOCK key is off and enter your username and password exactly as specified or as you set them up. You are not logging in on the right machine. The login/password combination might not be valid if you are trying to log in on the wrong machine. On a larger, networked system, you might have to specify the machine you want to connect to before you can log in. Your username is not valid. The login/password combination might not be valid if you have not been set up as a user. A filesystem is full. When a filesystem critical to the login process is full, it might appear as though you have logged in successfully, but after a moment the login prompt reappears. In this situation you must boot the system in rescue/recovery mode and delete some files. The account is disabled. On some systems, the root account is disabled by default. An administrator might disable other accounts. Often the root account is not allowed to log in over a network: In this case, log in as yourself and then gain root privileges using su/sudo. Sobell ch02 – Getting Started A Practical Guide to Linux® Commands, Editors, and Shell Programming, 4ed. Helmke and Sobell. © 2018 Prentice Hall. End of Sobell Ch02

Use Quizgecko on...
Browser
Browser