Class notes on 9/12/2015 Working with the Bash Shell – Part I / Chapter 2



Yüklə 22,14 Kb.
tarix08.10.2017
ölçüsü22,14 Kb.
#3699

class notes on 9/12/2015





  • To communicate commands to the OS kernel, an interface is needed that sits between the kernel and the end user issuing these commands. . .this interface is known as “the shell”.

  • Several “shells” are available:

--- Bash : short for the Bourne Again Shell. . .the one used in most situations, because it’s compatible with the Bourne shell, commonly found on UNIX servers.

--- command line interface or shell used on most Linux systems

--- incorporates features from sh (the original Bourne shell), csh (the C shell), and ksh (the Korn shell)

--- tcsh : A shell with a scripting language that works like the C programming language. . .very popular with C programmers

--- zsh : A shell compatible with Bash but offers even more features

--- sash : known as stand-alone shell. . .a minimal-feature shell that runs in almost all environments. . .very well suited for system troubleshooting



  • Useful Bash Key Sequences (using keyboard): sometimes, you will enter a command from the Bash command line and nothing or something totally unexpected, will happen. If that occurs, it is good to know that some key sequences are available to perform basic Bash mgmt tasks. . .Here’s a short list of the most useful of these key sequences:

  • Ctrl+C : Cancels the currently running command //// add on: 12 Mar 2015 ///////////




  • Ctrl+D : Logs out of current session //// add on: 12 Mar 2015 ///////////



  • Ctrl+R : This is the reverse search feature of History.

-- useful when you’ve already executed a very long command, you can simply search history using a keyword and re-execute the same command without having to type it fully

-- For example: initially run command: cat /etc/redhat-release

- to use search history: now [Press Ctrl+R from cmd prompt, which will display the reverse-i-search prompt]

- should see: (reverse-i-search) ‘red’: cat /etc/redhat-release

- [Press enter when you see your command, which will execut the command from the history]


  • Ctrl+A : Brings the cursor to the beginning of the current command

  • Ctrl+F : Moves the cursor forward one character //// add on: 12 Mar 2015 ///////////




  • Ctrl+B : moves the cursor backward one character //// add on: 12 Mar 2015 ///////////

  • Ctrl+U : erases the complete line. //// add on: 12 Mar 2015 ///////////




  • Ctrl+Z : used to stop a command. . .but it does not terminate the command. . ..it’s just halted until it is started again with the fg command as a foreground job or with the bg command as a background job.



  • Example: # yes > /dev/null …. Then press “Ctrl + Z

--- Alternative to "Executing a background job" is using ampersand (&)



: For example: find / -ctime -1 > /tmp/changed-file-list.txt &


  • Working with Bash History

  • Another useful aspect of the Bash shell is the “history” feature. This history mechanism displays the last commands you used…… By default, the last 1,000 commands of any user are remembered [Example]

  • use history "n" to see the last "n" commands [Example]# history 10




  • As an administrator, you sometimes need to manage the commands that are in the history list. There are two ways to do this:

  • 1st, you can manage the file “.bash_history” [~/.bash_history or /home/name/.bash_history], which stores all the commands you have used before. . .this is stored in the home directory of the user

  • For example: if you wanted to delete this file for the user “joyce”, just remove it with the command: “rm /home/joyce/.bash_history

  • 2nd way, is by using the history command, with the “-c” option. . .this will clear the history list for the user who uses this command

  • For example: use “history –c” to make sure that your history is cleared.

Additional Options:

  • To repeat the last command in bash, type “!!” – pronounced as bang bang

  • Repeat other commands using one bang [!] followed by one or more characters. . .this shell will repeat the last command that started with those characters

Example: # touch file42

      • then,# cat file42

      • then, # !to

      • command should display last command beginning with “to”

  • typing ! followed by the number preceding the command: Example: !43

  • $HISTSIZE Variable can determine number of commands to be remembered in your current environment. Change History size with command: Example below:

      • # echo $HISTSIZE ---> should see default number (500 or 1000)

      • # HISTSIZE=1200

      • # echo $HISTSIZE

  • $HISTFILESIZE variable can be used to determine number of commands kept in your history file:



Practice Exercise To Do: ( shell history (p-158)

-- do #'s: 1, 2, 3, 4, 8
Yüklə 22,14 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə