1 / 73

Part-1

Dr. Jahangir Alam, University Women's Polytechnic, AMU Aligrrh

Download Presentation

Part-1

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. Part 1 Basics: Environment, Access & Usage Dr. Jahangir Alam Computer Engineering Section University Women’s Polytechnic Aligarh Muslim University, Aligarh September 19, 2019

  2. What is linux? ? Linux is a family of open source Unix-like operating systems. ? It is based on the Linux kernel - an operating system kernel devel- oped by Linus Torvalds in 1991. ? The kernel is essentially written in C with a little of assembly code. ? Linux is typically packaged in a Linux distribution (or distro for short). ? A distribution includes the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. ? Popular free Linux distributions include Debian, Fedora, and Ubuntu. ? Commercial distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. ? Desktop Linux distributions include a windowing system such as X11 or Wayland, and a desktop environment such as GNOME or KDE Plasma. Linus B. Torvalds 2 of 73

  3. Structure of Linux ? Linux is a multiprogramming, mltiuser, time sharing and muti- tasking operating system. ? There are two major components of Linux, the kernel and the shell. ? The kernel is the core of the Linux operating system which schedules processes and interfaces directly with the hardware. ? It manages system and user I/O, processes, devices, files, and memory. ? The shell is an interface to the kernel. ? Users input commands through the shell, and the kernel receives the tasks from the shell and performs them. ? The shell tends to do four jobs repeatedly: - Displays a prompt 3 of 73

  4. Structure of Linux (contd...) - Reads a command - Interprets the given command - Then executes the command (Process the command and diaplay the result - certainly with the help of the kernel) - After this, it starts the process all over again. 4 of 73

  5. Structure of Linux (contd...) ? A shell this way is also called a command interpreter. ? The shell also incorporates a powerful programming language. ? This language referred to as "Shell Programming", enables the user to exploit the full power and versatility of Linux. ? Clearly, if we want to work with Linux, we need to access its shell. ? So, in a way we can say that accessing Linux means accessing its shell. 5 of 73

  6. Various Linux Installations (Environments) ? Direct Access - Linux is loaded on the server. - Each user needs a time slot. - Not possible with so many students. - Remove Windows from each computer and install Linux: Not possible.. ? Dual Boot Systems - Each computer in the lab could be configured as a dual boot Linux-windows system. - No concept of centralized security and administration. - May annoy non Linux users. - Complex disk partitioning schemes. - Cross partition security restrictions are hard to implement. 6 of 73

  7. Various Linux Installations (Environments) (contd...) ? Virtualization - Create a virtual machine on each computer. - This may be done using some virtualization S/W (e.g. Oracle VM Virtualbox). - Install Linux on the virtual machine. - Each box this way can have both-Windows and Linux. - Yet again, no concept of centralized security and administra- tion. - May annoy non Linux users. - Virtual machine shares resources with real machine. - This may slowdown both Linux and Windows. ? Remote Login (Terminal Emulation) - Linux is loaded on one machine (preferably server). 7 of 73

  8. Various Linux Installations (Environments) (contd...) - Each user emulates his/her computer into Linux mode using some terminal emulator program (terminal emulator). - A terminal emulator allows a computer to access another computer, including remote ones, through either a command- line interface or a graphical one. - The communication is made possible using protocols such as Telnet, Rlogin, Raw and SSH (Secure Shell). - No need to install Linux on each computer. - Centralized security and administration. - Best example of centralized computing. - Telnet, Raw, Rlogin etc., being insecure are not used with modern setups. - So, we shall use ssh protocol to access the Linux server. 8 of 73

  9. Various Linux Installations (Environments) (contd...) 9 of 73

  10. Accessing Linux from Windows using ssh ? A ssh client is required. ? To run GUI Linux applications a X Windows System Server (X- Server) is also required. ? A variety of ssh clients and X-Server are available: - Putty: A pure ssh client with X11 forwarding. - Xming: A pure X Windows System Server. - VcXsrv: A pure X Windows System Server. ? So, Putty used in combination with Xming or VcXsrv can serve the purpose. ? But, ideal solution must bring ssh client and X-Server as a single package. ? Some option in this category are: 10 of 73

  11. Accessing Linux from Windows using ssh (contd...) - Xmanager: X server for Windows with tabbed SSH client (Best, but carries a cost) - MobaXterm: Free X server for Windows with tabbed SSH client. - SmarTTY: Free X server for Windows with tabbed SSH client. ? We shall use SmarTTY (preferred) or MobaXterm. ? Next few slides demonstrate how some of them are used. 11 of 73

  12. Accessing using Putty ? Download Putty from https://www.putty.org/. ? Install and Run it. 12 of 73

  13. Accessing using Putty & Xming ? No X application could be run using putty. So, ? Download Xming from: https://sourceforge.net/projects/xming/. ? Install and Run it. You must notice a Xming icon on the taskbar. ? Enable X11 forwarding in Putty. (Run Putty → Under Category expand SSH → Select X11 and on right hand side check Enable X11 forwarding button). ? Enter Linux server’s IP address in putty and login in the same way as we have previously exercised. ? We can now run command line as well as X applications. ? Note: VcXsrv can also be used instead of Xming for the same results. 13 of 73

  14. Accessing using Putty & Xming (contd...) 14 of 73

  15. Accessing using MobaXterm ? Download Home Edition of MobaXterm from: https://mobaxterm.mobatek.net/download.html. ? Install and Run it. ? Create new ssh session (Click Session → Click ssh). ? Enter IP address of server in Remote Host field and your user- name in the username field. ? Click OK. Enter your password when prompted and you must get the Linux $ prompt. ? Now you can execute any application X based or command line. 15 of 73

  16. Accessing using MobaXterm (contd...) 16 of 73

  17. Accessing using SmarTTY ? Download SmarTTY from: https://sysprogs.com/SmarTTY/download/. ? Install and Run it. ? Create new ssh session (Click New ssh connection). ? Enter IP address of server in Host Name field and your username ans password in intended fields. ? Leave other settings as default and click Connect button. ? SmarTTY prompts you to start a regular or smart terminal. ? You can run X-based applications in both terminals but Smart terminal offers you extended services over regular terminal. ? Finally, you get the Linux $ prompt. 17 of 73

  18. Accessing using SmarTTY (contd...) 18 of 73

  19. Part 1 Basic Commands Dr. Jahangir Alam Computer Engineering Section University Women’s Polytechnic Aligarh Muslim University, Aligarh September 19, 2019 19 of 73

  20. Changing password ? Irrespective of what method you are using to access the Linux, you must have a valid username and password on the Linux machine. ? Using following steps you can change your current password: 1. To start, type passwd at the command prompt. 2. Enter your old password, the one you are currently using. 3. Type in your new password. 4. Always keep your password complex enough so that nobody can guess it. But make sure, you remember it. 5. You must verify the password by typing it again. ? Have a look at the following figure: 20 of 73

  21. Changing password (contd...) 21 of 73

  22. The cal & ncal Commands ? On Unix-like operating systems, the cal and ncal commands display a formatted calendar in the terminal. ? ncal ("new cal") stands for new calendar. ? It provides the same functions of cal, but it can display the calendar vertically (with weeks in columns). ? On systems with ncal installed, cal is typically a symbolic link to ncal. ? It behaves like the original cal if you we the name cal to run the program. 22 of 73

  23. The cal & ncal Commands (contd...) ? Their general form is: $cal [Options] $ncal [Options] ? If no options are specified, cal and ncal display the current month, with the current day highlighted. cal & ncal: Important Options & Examples - The following are some mostly used options with cal and ncal: 23 of 73

  24. The cal & ncal Commands (contd...) Option Description -h -m month Don’t highlight today’s date. (works with ncal only) Specify a month to display. The month specifier can be a full month name (e.g., Februiary), a month abbreviation of at least three letters (e.g., Feb), or a number (e.g., 2). If you specify a number, followed by the letter f or p, the month of the following or previous year, respectively, will be displayed. For instance, -m 2f displays February of next year. Specify a year to display. For example, -y 1970 displays the entire calendar of the year 1970. Display last month, this month, and next month. Display only this month. This is the default. Display num months occurring after any months already specified. For example, -3 -A 3 displays last month, this month, and four months after this one; and -y 1970 -A 2 displays every month in 1970, and the first two months of 1971. Display num months occurring before any months already speci- fied. For example, -3 -B 2 displays the previous three months, this month, and next month. Operate as if the current month is number MM of year YYYY. -y year -3 -1 -A num -B num -d YYYY-MM 24 of 73

  25. The cal & ncal Commands (contd...) - Execute Following Commands and analyze the result carefully: 1. $ cal 2. $ ncal 3. $ ncal -h 4. $ cal -m february 5. $ cal -m sep 6. $ cal -m 5 7. $ cal -m 2f 8. $ cal -m 10p 9. $ cal -y 1970 (same as cal 1970) 10. $ cal -3 11. $ cal -1 12. $ cal -3 -A 3 13. $ cal -y 1970 -A 2 14. $ cal -3 -B 2 15. $ cal -d 2005-03 25 of 73

  26. The echo Command ? echo command on Unix-like operating systems prints text to standard output, e.g., the terminal. ? This is a built in command that is mostly used in shell scripts to output status text to the screen or a file. ? To confirm this execute following command: $type echo ? The general form of echo command is: $echo [Option][String] ? Following is a list of options available with echo: 26 of 73

  27. The echo Command (contd...) Option Description -n -e -E Do not output a trailing newline. Enable interpretation of backslash escape sequences. Disable interpretation of backslash escape sequences. This is the default. Display a help message and exit. Output version information and exit. - -help - -version ? Following table lists echo backslash escape sequences. They are interpreted only when echo is exercised with -e option: Sequence Interpreted as \\ \a \b \c \e \f \n \r \t \v A literal backslash character ("\"). An alert (The BELL character). Backspace. Produce no further output after this. The escape character; equivalent to pressing the escape key. A form feed. A newline. A carriage return. A horizontal tab. A vertical tab. 27 of 73

  28. The echo Command (contd...) echo Command: Execution & Examples - echo without any option(s) prints the string passed to it on standard output (terminal). $echo Hello World! OR $echo "Hello World!" - In above example output of echo is same but the ways we have passed arguments to echo are different. - In first echo command the argument (Hello World!) are actually two separate arguments (Hello and World!). - In second echo command the argument ("Hello World!" or may also be stated as ’Hello World!’) is treated as a single string. Escape sequences are meant to work with strings. 28 of 73

  29. The echo Command (contd...) - echo is also used to print the values of shell/ environment vari- ables as shown below: $echo $PATH $ x=5 $echo $x - Escape sequences are not interpreted by default e.g.: $echo "Linux \bis \bfun." - However, if we provide the -e option, they will be interpreted: $echo -e "Linux \bis \bfun." - If you need to insert newlines in your echo output, specify the -e option and include the \n escape sequence wherever you want a new line: $echo -e ’Here,\nwe\nhave\ninserted\nnewlines.’ 29 of 73

  30. The echo Command (contd...) - To omit echoing trailing newline, use -n option with echo. $echo -n "Linux for Fun" - To print all files and folders in the present working folder use following form of echo: $echo * This is somewhat equivalent to ls command (yet to be dis- cussed). 30 of 73

  31. The tput Command ? tput command is used to query the terminfo terminal database and check if that terminal supports a specific feature. ? Long ago, when computers were centralized, interactive com- puter users communicated with remote systems by using a phys- ical terminal or a terminal emulator program running on some other system (like we are using). ? In their blooming days, there were many kinds of terminals. ? They all used different sequences of control characters to man- age their screens and keyboards. ? When we start a terminal session on our Linux system, the terminal emulator sets the TERM environment variable with the name of a terminal type. ? If we examine TERM, we can see this: 31 of 73

  32. The tput Command (contd...) $echo $TERM ? In this example, we notice that our terminal type is named "xterm" suggesting that our terminal behaves like the classic X terminal emulator program xterm. ? Other common terminal types are "linux" for the Linux console, and "screen". ? While we will encounter these 3 types most often, there are, in fact, thousands of different terminal types. ? Our Linux system contains a database called terminfo that de- scribes them. ? We can examine a typical terminfo entry using the infocmp command followed by a terminal type name: 32 of 73

  33. The tput Command (contd...) $infocmp xterm OR $infocmp screen ? Terminal(s) information is there in terminfo database in coded form. ? tput command queries this database and produces meaningful terminal information for the user. ? Information so obtained also lead to setting terminal properties. ? It is a vast command and for details you can refer to: http://linuxcommand.org/lc3_adv_tput.php. ? Here we shall look into its most widely used options. 1. Set the cursor position: You can move the cursor to a specific row and column using tput cup. 33 of 73

  34. The tput Command (contd...) $tput cup 2 3 OR $tput cup 5 30 2. Clear the Screen: You can clear the screen using tput clear. $tput clear 3. Get the number of columns/ lines and colors supported by a Terminal: To display the number of columns/rows of your terminal screen use tput cols/tput lines. To find numbers of colours supported by your terminal use tput colors $tput cols $tput lines $tput colors 34 of 73

  35. The tput Command (contd...) 4. Change the Terminal Foreground/Background Color: To change the terminal’s foreground/ background color use tput setf/tput setb. $tput setb 4 $tput setf 7 If you notice reverse colors, first use the command tput rev, to reverse the video. As emulator settings may override the defaults, it is better to exercise these commands in a separate xterm. Note: If you set foreground and background to the same color you cannot see the cursor. So, to reset, execute "tput reset". 5. Turn On and Turn Off Highlighting: tput allows us to turn on/off the text high lighting using tput bold/tput sgr0. When we turn it on, new text in the terminal gets bold. $tput bold $tput sgr0 35 of 73

  36. The tput Command (contd...) 6. Underline Text: tput allows us to turn on/off the text underline mode using tput smul/tput rmul. $tput smul $tput rmul 7. Hide/ Unhide Cursor: tput allows us to turn hide/unhide the cursor using tput civis/tput cnorm. $tput civis $tput norm ? Note: If any of the above tput commands doesn’t execute properly in the emulator, try to execute it in a separate xterm. ? You can start a separate xterm using: $xterm 36 of 73

  37. The date Command ? date command on Unix-like operating systems, is used to print or change the value of, the system’s time and date information. ? Its general form is: $date [Options] ... [+Format] date Command: Options, Execution & Examples - With no options, the date command displays: ? the current date and time, ? including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, ? the time zone name, and the year. $date 37 of 73

  38. The date Command (contd...) ? With -u Option it displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time ) time zone. $date -u ? With −−date or -d Option it displays the given date string in the format of date. ? Also, this doesn’t affect the system’s actual date and time value. Instead, it uses the date and time given in the form of string. $date −−date="2/02/2010" OR $date -d="2/02/2010" OR $date −−date="Feb 2 2010" ? Above options can also be utilized to display past dates as shown in following examples: 38 of 73

  39. The date Command (contd...) 1. Date and time of 2 years ago. $date −−date="2 year ago" 2. Date and time of 5 seconds ago. $date −−date="5 sec ago" 3. Date and time of previous day. $date −−date="yeaterday" 4. Date and time of 2 months ago. $date −−date=""2 month ago" 5. Date and time of 10 days ago. $date −−date=""10 day ago" ? Same options can also be utilized to display future dates as shown in following examples: 1. Date and time of upcoming particular week day. $date −−date="next tue" 2. Date and time after two days. $date −−date="2 day" 3. Date and time of next day. $date −−date="tomorrow" 4. Date and time after 1 year on the current day. $date −−date="1 year" 39 of 73

  40. The date Command (contd...) ? With -s or −−set option we can set the system date and time. Have a look at following commands: $date −−set="Tue Nov 13 15:23:34 PDT 2018" OR $date -s="Tue Nov 13 15:23:34 PDT 2018" Note:It doesn’t work in ubuntu. ? The -f or −−file option is used to display the date string present at each line of file in the date and time format. ? This option is similar to -d or −−date option. ? only difference is that in −−date we can only give one date string but in a file we can give multiple date strings, one each line. ? Execute following command: 40 of 73

  41. The date Command (contd...) $cat dfile.txt Sep 23 2018 Nov 03 2019 » ? Now exercise date command for dfile.txt as follows: $date −−file=dfile.txt ? With -r the date command displays the last modified timestamp of a datefile. $date -r filename ? With -I option the date command displays the date in ISO 8601 format (YYYY-MM-DD). $date -I ? With -R option the date command displays the date and time in RFC 2822 format. 41 of 73

  42. The date Command (contd...) ? Example is: Mon, 07 Aug 2006 12:34:56 -0600. $date -R Date Format ? Format is a sequence of characters which specifies how output will appear. ? General format for specifying a format with the date command is: "+%[format-option]" ? It comprises some combination of the following sequences: 42 of 73

  43. The date Command (contd...) Sequence Description %D %d %a %A %h %b %B %m %y %Y %T %H %M %S Display date as mm/dd/yy. Display the day of the month (01 to 31). Displays the abbreviated name for weekdays (Sun to Sat). Displays full weekdays (Sunday to Saturday). Displays abbreviated month name (Jan to Dec). Displays abbreviated month name (Jan to Dec). Displays full month name(January to December). Displays the month of year (01 to 12). Displays last two digits of the year(00 to 99). Display four-digit year. Display the time in 24 hour format as HH:MM:SS. Display the hour. Display the minute. Display the seconds. ? For a more detailed list of date command options and format sequences you may refer to: https://www.computerhope.com/unix/udate.htm. 43 of 73

  44. The date Command (contd...) ? Execute the following commands and notice the output: 1. $date "+%D" 2. $date "+%D %T" 3. $date "+%Y-%m-%d" 4. $date "+%Y/%m/%d" 5. $date "+%A %B %d %T %y" 44 of 73

  45. The time Command ? time command on Unix-like operating systems, reports how long it took for a command to complete execution. ? It prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates. ? First thing to note is that every Linux command is a program. ? real time is the time elapsed wall clock time taken by a command to get executed. ? user time is the amount of CPU time that the command spends executing its own code. ? For small Linux commands, which take milliseconds to execute, this time is often shown as 0.0. ? sys time is the amount of CPU time that the command spends executing kernal oriented code. 45 of 73

  46. The time Command (contd...) ? Thus we conclude that the actual amount of CPU time spent on executing a command is the sum of its "user" and "sys" times. ? General form of time command is: time [Option] [command] time Command: Important Options & Examples - Two options are available with time command. - They are -p and help. - Execute following commands and notice the output: 1. $time sleep 3 2. $time df 3. $time ls -l 4. $help time. 46 of 73

  47. The time Command (contd...) - In the above example, sleep 3 is used to create a dummy job which lasts 3 seconds. - The df command calculates free disk space and ls -l command list files in present working directory. - If -p option is specified, the timing summary is printed in a portable POSIX format. - The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for main- taining compatibility between operating systems. - Execute following commands: 1. $time -p sleep 3 2. $time -p df 3. $time -p ls -l 47 of 73

  48. Part 1 Knowing Yourself & Other Users Dr. Jahangir Alam Computer Engineering Section University Women’s Polytechnic Aligarh Muslim University, Aligarh September 19, 2019 48 of 73

  49. The who Command ? who command is used to find out the following information: 1. Time of last system boot 2. Current run level of the system 3. List of logged in users and more. ? The command is mostly used to get information about currently logged in user on to the system. ? Its general form is: $who [Options] [File] [am i] ? If FILE is specified, who gathers its information from this file. Otherwise, it reads from a default file location (usually /var/run/utmp). 49 of 73

  50. The who Command (contd...) who Command: Important Options & Examples - If you run who command without any arguments, it will display account information (user login name, user’s terminal, time of login as well as the host the user is logged in from) on your system. $who - To have the headings of the columns displayed, use the -H flag as shown. $who -H 50 of 73

More Related