Class notes on 20 april 2015 Working with the Bash Shell



Yüklə 18,11 Kb.
tarix08.10.2017
ölçüsü18,11 Kb.
#3698

Class notes on 20 april 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 : use this key sequence to quit a command that is not responding.




  • Ctrl+D : use this key sequence to send the end-of-file (EOF) signal to a command. Use this when the command is waiting for more input.



  • 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+B : moves the cursor to the end of the current command line




  • 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.

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

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



Ctrl+Z Examples:

Sending the current foreground job to the background using CTRL-Z and bg command


You can send an already running foreground job to background as explained below:

  • Press ‘CTRL+Z’ which will suspend the current foreground job.

  • Execute bg to make that command to execute in background.

For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

# find / -ctime -1 > /tmp/changed-file-list.txt


# [CTRL-Z]

[2]+ Stopped find / -ctime -1 > /tmp/changed-file-list.txt


# bg


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

  • A command can also be restarted from an “history” list [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:

Yüklə 18,11 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ə