Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Pointers.pdf
Pointers.pdf
Wird geladen in …3
×

Hier ansehen

1 von 73 Anzeige

Weitere Verwandte Inhalte

Aktuellste (20)

Anzeige

Part-1.pdf

  1. 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. 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. 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. 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. 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. 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. 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. 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. 9. Various Linux Installations (Environments) (contd...) 9 of 73
  10. 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. 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. 12. Accessing using Putty Download Putty from https://www.putty.org/. Install and Run it. 12 of 73
  13. 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. 14. Accessing using Putty Xming (contd...) 14 of 73
  15. 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. 16. Accessing using MobaXterm (contd...) 16 of 73
  17. 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. 18. Accessing using SmarTTY (contd...) 18 of 73
  19. 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. 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. 21. Changing password (contd...) 21 of 73
  22. 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. 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. 24. The cal ncal Commands (contd...) Option Description -h Don’t highlight today’s date. (works with ncal only) -m month 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. -y year Specify a year to display. For example, -y 1970 displays the entire calendar of the year 1970. -3 Display last month, this month, and next month. -1 Display only this month. This is the default. -A num 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. -B num 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. -d YYYY-MM Operate as if the current month is number MM of year YYYY. 24 of 73
  25. 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. 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. 27. The echo Command (contd...) Option Description -n Do not output a trailing newline. -e Enable interpretation of backslash escape sequences. -E Disable interpretation of backslash escape sequences. This is the default. - -help Display a help message and exit. - -version Output version information and exit. Following table lists echo backslash escape sequences. They are interpreted only when echo is exercised with -e option: Sequence Interpreted as A literal backslash character (). a An alert (The BELL character). b Backspace. c Produce no further output after this. e The escape character; equivalent to pressing the escape key. f A form feed. n A newline. r A carriage return. t A horizontal tab. v A vertical tab. 27 of 73
  28. 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. 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,nwenhaveninsertednnewlines.’ 29 of 73
  30. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 43. The date Command (contd...) Sequence Description %D Display date as mm/dd/yy. %d Display the day of the month (01 to 31). %a Displays the abbreviated name for weekdays (Sun to Sat). %A Displays full weekdays (Sunday to Saturday). %h Displays abbreviated month name (Jan to Dec). %b Displays abbreviated month name (Jan to Dec). %B Displays full month name(January to December). %m Displays the month of year (01 to 12). %y Displays last two digits of the year(00 to 99). %Y Display four-digit year. %T Display the time in 24 hour format as HH:MM:SS. %H Display the hour. %M Display the minute. %S 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. 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. 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. 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. 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. 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. 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. 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
  51. 51. The who Command (contd...) - To print the login names and total number of logged on users, use the -q flag. $who -q - In case you want to show only hostname and user associated with stdin, use the -m switch. $who -m Note: If the arguments am i are specified, who assumes the -m option. 51 of 73
  52. 52. The who Command (contd...) - To add user’s message status as +, - or ?, use the -T or --message switch option. $who -T OR $who - -message - Terminal number (line) preceded by ’+’ means, associated user is allowed to write the message using ’write’ command. - Preceded by ’-’ means, associated user is not allowed to write the message using ’write’ and by ’?’ means Linux is unable to find the terminal number. - To view the time of last system boot, use the -b flag. 52 of 73
  53. 53. The who Command (contd...) $who -b - Adding the -u option allows for listing of logged on users in the same output. $who -bu - We can check the current system runlevel with the -r option. $who -r - To display all details of current logged in user use -a option. 53 of 73
  54. 54. The who Command (contd...) $who -a - To display a list of all dead processes. $who -d - To display a list of all active processes which are spawned by INIT process use -p option. $who -p 54 of 73
  55. 55. The who Command (contd...) 55 of 73
  56. 56. The logname Command logname command is used to confirm your login name. It displays the login name of the current user. Its general form is: $logname [Option] logname Command: Important Options Examples - It accepts only two options. They are - -help and - -version. - They are self-explanatory. 56 of 73
  57. 57. The finger Command finger command displays information about the users currently logged in to a host. The format of the output varies with the options for the infor- mation presented. Its general form is: $finger [Options] [User(s)|User(s)@Host|@Host] The parameters are as as follows: Item Description @Host Specifies all logged-in users on the remote host. User Specifies a local user ID (used for discretionary access control) or local user login name, as specified in the /etc/passwd file. User@Host Specifies a user ID on the remote host, displayed in long format. 57 of 73
  58. 58. The finger Command (contd...) finger Command: Important Options Examples - If we run finger command without any option, for each user it displays: • Login name, • Full user name, • Terminal name, • Write status (an * (asterisk) before the terminal name indicates that write permission is denied), • Idle time (Idle time is minutes if it is a single integer, hours and minutes if a : (colon) is present, or days and hours if a d is present.), • Login time and • Site-specific information. ‘ $finger 58 of 73
  59. 59. The finger Command (contd...) - With -s option, finger displays the same information as it does without any option. $finger -s - With -l option, finger displays a multi-line format displaying all of the information described for the -s option as well as the user’s home directory, home phone number, login shell, mail status, and the contents of the files ∼/.plan, ∼/.project, ∼/.pgpkey and ∼/.forward from the user’s home directory. - If write permission is denied to the device, the phrase (mes- sages off) is appended to the line containing the device name. 59 of 73
  60. 60. The finger Command (contd...) - One entry per user is displayed with the -l option; if a user is logged on multiple times, terminal information is repeated once per login. - Mail status is shown as No Mail. if there is no mail at all, Mail last read DDD MMM ## HH:MM YYYY (TZ) if the person has looked at their mailbox since new mail arriving $finger -l - The -p option, used with -l option prevents of finger from dis- playing the contents of the ∼/.plan, ∼/.project, ∼/.pgpkey and ∼/.forward files. 60 of 73
  61. 61. The finger Command (contd...) $finger -lp - The -m option, prevents matching of usernames. - The user is usually a login name; however, matching will also be done on the users’ real names, unless the -m option is supplied. - All name matching performed by finger is case insensitive. $finger -m jahangir - To get information about all users logged in to host amucc (or host ip address), enter: 61 of 73
  62. 62. The finger Command (contd...) $finger @amucc - To get information about user ’jahangir’ at host amucc, enter: $finger jahangir@amucc - Note:The last two commands (meant for remote hosts) work only when fingerd demon is running on the intended host(s). If not, connection refused is the message. - This will require the fingerd demon to install and start on that server using commands: $sudo apt-get install inetutils-inetd fingerd. $sudo /etc/init.d/inetutils-inetd start. 62 of 73
  63. 63. The finger Command (contd...) 63 of 73
  64. 64. The whoami Command whoami command is used to confirm your login name. It is similar to logname command. It displays the login name of the current user. Its general form is: $whoami [Option] whoami Command: Important Options Examples - It accepts only two options. They are - -help and - -version. - They are self-explanatory. 64 of 73
  65. 65. The id Command id command on Unix-like operating systems, is used to find user and group names and numeric ID’s (UID or group ID) of the current user or any other user of the system. This command is particularly useful to determine the following information: - user ID - username. - group ID. - group name. - ID of other groups. - names of other groups. Its general form is: $id [OPTION] ... [USER] 65 of 73
  66. 66. The id Command (contd...) id Command: Important Options Examples - The id command reveals all the information listed above, about the current user when run without any option. - Execute id as follows: $id - To reveal same information for any other user say ’sam’, use id as follows: $id sam - With -g or - -group option, it reveals the primary group id for the current user. $id -g or $id - -group 66 of 73
  67. 67. The id Command (contd...) - If you want to see the primary group id for a different user say ’sam’, specify the user’s name as follows: $id -g sam or $id - -group sam - With -G or - -groups option the id command lists the secondary groups a user belongs to. - Execute following commands: $id -G or $id - -groups $id -G sam or $id - -groups sam - With -gn or - -group - -name option the id command lists the name of the primary group for current user or for a specific user. 67 of 73
  68. 68. The id Command (contd...) - Execute following commands: $id -gn or $id - -group - -name $id -gn sam or $id - -group - -name sam - If you want to display the secondary group names and not the id numbers for current user or for a specific user, use -Gn or - -groups - -name option. - Try following commands: $id -Gn or $id - -groups - -name $id -Gn sam or $id - -groups - -name sam 68 of 73
  69. 69. The id Command (contd...) - With -u or - -user option the id command displays the user id for the current user or for some specified user. $id -u or $id - -user $id -u sam or $id - -user sam - You can display the username for the current user by typing the following command: $id -un or $id - -user - -name - Options - -help and - -version have usual meaning with id com- mand. 69 of 73
  70. 70. The w Command w command on Unix-like operating systems is a quick way to see who is logged on and what they are doing. This command shows the information about the users currently on the machine and their processes (running programs). When executed without any option the header shows, in the order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. Following entries are displayed for each user: login name terminal name the user’s host login time idle time 70 of 73
  71. 71. The w Command (contd...) JCPU, PCPU, and the command line of their current process. The JCPU time is the time used by all processes attached to the terminals. It does not include past background jobs but does include currently running background jobs. The PCPU time is the time used by the current process, named in the what field. General form of w command is: $w [OPTIONS] [USER] 71 of 73
  72. 72. The w Command (contd...) w Command: Important Options Examples - With -h option, w command doesn’t print the header. - With -u option, w command, ignores the username while figur- ing out the current process and cpu times. (Note: To practice an example of this, switch to the root user with sudo su and then run both w and w -u.) - Try following commands: $w $w -h $sudo su #w #w -h - With -s option, w command, uses the short format. It doesn’t print the login time, JCPU or PCPU times. 72 of 73
  73. 73. The w Command (contd...) - With -f option, w command, doesn’t displays the FROM (host name/ip address) field. - With -help option, w command, displays the help. - With -V option, w command, displays the version information. - With user option, w command, displays the information about specified user only. - Try following commands: $w -s $w -f $w -help $w -V $w sam 73 of 73

×