1 / 36

Conquering the Bash Shell

Conquering the Bash Shell. Overview. Shell Evironment Linux Command Prompt Viewing System Information Advance Shell Usage and Script. Shell Environment. 2 user interfaces on Linux GUI hosted by X CLI called the shell The most common way to access the shell is via a terminal window

hewitt
Download Presentation

Conquering the Bash Shell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Conquering the Bash Shell

  2. Overview • Shell Evironment • Linux Command Prompt • Viewing System Information • Advance Shell Usage and Script

  3. Shell Environment • 2 user interfaces on Linux • GUI hosted by X • CLI called the shell • The most common way to access the shell is via a terminal window • Start > System Tools > Terminal • Example : $ w • The w command tells Linux to display the system status and a list of all system users

  4. Shell Environment (cont…) • Example : $ date • The date command tell linux to show the current date • How to correct commands • Backspacekey erases characters • Left keydoes not erase characters • Delete key to delete unwanted characters

  5. Shell Environment (cont…) • Reissue previous command using bash's history • Scroll back (the Up arrow key)or • Back down (the Down arrow key) • Bash's history is saved in the user's home directory, ~/.bash_history • Up to 500 command • Make command completion • Type a part of your command • Press Tab key

  6. Shell Environment (cont…) • Useful Control keystrokes • Ctrl-C — cancels execution • Ctrl-D — terminate console input • Ctrl-Z — suspends the currently executing program • Special characters • # — Marks the line as a comment • ; — Separates commands

  7. Linux Command Prompts • Command Prompt Forms • Getting Help • Working with Directories • Working with Files • Working with Compressed Files

  8. Command Prompt Forms • Commands and Arguments in Linux • command [options] [arguments] • 2 kinds of commands • External commands • Stored in /bin, /usr/bin, or /usr/local/bin • System administration commands • stored in /sbin or /usr/sbin - included by default in the path of the root user • Linux commands are case sensitive

  9. Command Prompt Forms (cont…) • Options modify the way that a command works • Example • w -h • w informit • w -h informit • When your command is too long • Type a backslash (\) at the end of a line, then • Press Enter, then • Continue your command in the new line

  10. Getting Help • 2 way of getting help in Linux • man command • apropos command • Both of them access a help database that describes commands and their options • Each Linux command is described by a special file called a manual page • $ man w • To quit from mode man, type “q”

  11. Getting Help(cont…) • The apropos command displays just a one-line summary of each $ apropos samba • Before using apropos, run this $ makewhatis

  12. Working with Directories • Displaying the working directory $ pwd • Changing the working directory $ cd /bin (go to bin directory) $ cd (go to your home directory) $ cd .. (go to the parent directory)

  13. Working with Directories (cont…) • Display directory contents $ ls $ ls –l $ ls /bin $ ls –al • Use less to show output one page at a time $ ls | less • space moves one page forward • b moves one page backward

  14. Working with Directories (cont…) • Creating a directory $ mkdir office # mkdir /tmp/documents • Removing a directory $ rmdir unwanted

  15. Working with Files • Displaying the contents of a file # cat /etc/passwd # less /etc/passwd • Removing a file # rm badfile • Copying a file # cp /etc/passwd sample • Renaming or moving a file # mv old new • Finding a file # find . -name 'missing' -print # find / -name '*iss*' -print # locate pass # which ls

  16. Working with Files(cont…) • To link a new name to an existing file or directory # ln -s old new • To run the program # bigdeal or # ./bigdeal or # /home/bob/bigdeal

  17. Working with Compressed Files • To compress files # gzip bigfile.gz • To expand a compressed file # gunzip bigfile • To create a tarfile # tar -cvf backup.tar /home/informit • To list the contents of a tarfile #tar -tvf tarfile | less • To extract the contents of a tarfile #tar -xvf tarfile

  18. Further with File Permissions • To set the access modes of a directory or file # chmod nnn directory-or-file • To assignnewuser as the owner of the file hotpotato # chown newuser hotpotato • To assigns newgroup as the new group of the file hotpotato # chgrp newgroup hotpotato • To change user login group to the group named secondgroup # newgrp secondgroup

  19. Viewing System Information • CLI also provide command to troubleshoot system problems and identify resource bottlenecks • Each supports options and arguments to customize its operation and output • Example : • du, df, free, top, ps, uptime

  20. Advance Shell Usage and Script • Filename Globbing • Shell Aliases • Jobs • Shell Scripts • Redirection and Piping • Filter & Regular Expressions • Shell Variables • The Search Path • Quoted Strings

  21. Filename Globbing • Globbing can make the command writing more quick and effecient • Example : • Common command : $ ls -l file1 file2 file3 file04 • Using File Globbing : $ ls -l file* • Another form of file globbing • List file2 and file3 $ ls -l file[2-3]

  22. Shell Aliases • Make commands easier to use • Establish abbreviated command names • Pre-specify common options and arguments for a command • Form : alias name='command' • Example : $ alias lihat='ls -l' $ unalias lihat

  23. Jobs • Jobs are command execution process • 2 mode of jobs : • Foreground • Background • 4 activities related with jobs : • Run jobs in the background • Notify when a job ends • Bring jobs to the foreground • Stop and Suspend jobs

  24. Jobs (cont…) • Example : • Run jobs in the background $ lpr mydata & • Notify when job ends $ notify %2 • Bring jobs to the foreground $ fg %2 • Stop and Suspend jobs $ kill %2

  25. Shell Scripts • Definition : • A file that contains a set of commands to be run by the shell when invoked • Example : • file name : deleter echo -n Deleting the temporary files rm -f *.tmpecho Done. • Running it$ sh deleter

  26. Shell Scripts (cont…) • 2 kinds of scripts : • Standard Scripts ~provided by Linux • User Scripts ~ created by user

  27. Redirection • 3 standard data streams • stdin (<) • Where program read their input • stdout (>) • Where program write their output • stderr (2>) • Where program write the error message

  28. Redirection(cont…) • Example : • Redirect number of lines, words and character on /etc/passwd into total $ wc /etc/passwd > total • Redirect an error message to /dev/null $ grep localhost * 2> /dev/null • Tell wc to read from a file, rather than the console $ wc < /etc/passwd

  29. Filter • Filters are commands that • Read data • Perform operations on that data • Send the results to the standard output • Example : $ cat complist | lpr $ ls –al | grep root

  30. grep Command • Form : • greppattern filenames-list • Example : $ grep 'text file' preface $ grep data preface intro $ grep data * $ grep while *.c

  31. Regular Expressions • Usually, combined with grep, sed, gawk command • Notation : ^, $, *, ., [] • Example : $ ls -l | grep '^d‘ $ grep ‘t$‘ file1 $ ls –l | grep ‘file[1-3]’

  32. Shell Variables • Provides a convenient way of transferring values from one command to another

  33. Shell Variables (cont…) • To list shell variables : $ set | less • To export a variable : $ export variable-name • Example : $ cd ${HOME} $ cd ${HOME}/work $ echo ${HOME}

  34. The Search Path • The paths that are looked in by shell when issuing an external command • Use a colon (:) to separate each path of the search path • /usr/bin:/bin:/usr/local/bin • To make additional path : $ PATH=${PATH}:/home/bill $ PATH=/home/bill:${PATH} • To find location of program file : $ which program-name

  35. Quoted Strings • Ensures that the shell doesn’t misinterpret a command • argument, file name, variable • Example $ echo $PATH $ echo ’$PATH’ $ echo My home directory contains ‘ls ~|wc -?‘ files.

  36. Summary • In this module, you have learned about : • Shell Command • Linux Command Prompt • Viewing System Information • Advance Shell Usage and Script

More Related