Linuxand shell scripting.docx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

**[Operating systems Tools (DCAP 106)]** **1 What are various types of shell in Linux?** **Ans:** **Types of Shell in Linux:** 1. **Bourne Shell** 2. **C Shell** 3. **TC Shell** 4. **Korn Shell** 5. **Bourne-Again Shell** **2 How to manage Process and users in Linux?** **Ans:** An inst...

**[Operating systems Tools (DCAP 106)]** **1 What are various types of shell in Linux?** **Ans:** **Types of Shell in Linux:** 1. **Bourne Shell** 2. **C Shell** 3. **TC Shell** 4. **Korn Shell** 5. **Bourne-Again Shell** **2 How to manage Process and users in Linux?** **Ans:** An instance of a program is called a Process. In simple terms, any command that you give to your Linux machine starts a new process. Hence you start a process (run a command), there are two ways you can run it: - Foreground Processes - Background Processes **Foreground Processes:** By default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen. You can see this happen with the ls command. If I want to list all the files in my current directory, I can use the following command: \$ls ch\*.doc This would display all the files whose name start with ch and ends with.doc: **Background Processes:** A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits. The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another! The simplest way to start a background process is to add an ampersand ( &) at the end of the command. \$ls ch\*.doc & This would also display all the files whose name start with ch and ends with.doc **Listing Running Processes:** It is easy to see your own processes by running the **ps** (process status) command as follows: \$ps One of the most commonly used flags for ps is the **-f** ( f for full) option, which provides more information as shown in the following example: \$ps -f UID PID PPID C STIME TTY TIME CMD **Stopping Processes:** Ending a process can be done in several different ways. Often, from a console-based command, sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works when process is running in foreground mode. If a process is running in background mode then first you would need to get its Job ID using **ps** command and after that you can use **kill** command to kill the process as follows: \$ps -f \$kill 6738 Terminated Here **kill** command would terminate first\_one process. If a process ignores a regular kill command, you can use **kill -9** followed by the process ID as follows: \$kill -9 6738 Terminated **NICE** Linux can **run  a lot of processes at a time** ,which can **slow down the speed of some high priority processes** and result in **poor performance**. To avoid this, you can tell your machine to **prioritize processes as per your requirements** This **priority is called Niceness in Linux** and it has a **value between -20 to 19**. The **lower the Niceness** index the **higher would be priority** given to that task. The **default value** of all the processes **is 0**. To start a process with a niceness value other  than the default value use the following syntax **nice --n 'Nice value' process name** **Top** This utility tells the user about all the running processes on the Linux machine. **User Management commands**: The easiest way to manage users and groups is through the graphical application, **User Manager** (system-config-users) **To create a new user:** \# useradd -c \"My Example User\" username \# passwd username The created user is initially in an inactive state. To activate the user you have to assign a password with **passwd**. **Some useful useradd options include the following:**\ **-c** : sets a comment for the user.\ **-s** : is used in order to define the user's default login shell. If not used, then the system's default shell becomes the user's default login shell.\ **-r** : creates a user with UID\ f. **sort** command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ascii. Using options in sort command, it can also be used to sort numerically. **sort simply sorts the file in alphabetical order**: g. The **rm** command deletes (removes) files and directories. e.g h. Use the **pwd** command to print the working directory (the current directory you are in).Syntax :\$pwd i. The **Change directory (cd)** command is one of the simple commands in Unix (or Linux) and it is very easy to use. The cd command is used to change from the current directory to another directory. The syntax of cd command is j. **Last** searches back through the file **/var/log/wtmp** (or the file designated by the **-f** flag) and displays a list of all users logged in (and out) since that file was created. Names of users and TTY's can be given, in which case **last** will show only those entries matching the arguments. Names of ttys can be abbreviated, thus **last 0** is the same as **last tty0**. k. echo is a command in Linux operating systems that places a string on the computer terminal. It is a built-in command typically used in shell scripts to output status text to the screen or a file. l. ***Whoami*** -- --

Use Quizgecko on...
Browser
Browser