©niit collaborate lesson 1c / slide 1 of 23 collaborate knowledge byte in this section, you will...

23
Lesson 1C / Slide 1 of 23 ©NIIT Collaborate Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Upload: melvyn-bailey

Post on 12-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 1 of 23©NIIT

Collaborate

Collaborate

Knowledge ByteIn this section, you will learn to:

• Use the cal command

• Determine the file types

Page 2: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 2 of 23©NIIT

Collaborate

Collaborate

Using the cal Command• The cal command displays the calendar.

• The syntax to use the cal command is:cal [-smjy13] [[month] year]

• To display the calendar of the current month:$ cal August 2004

Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

Page 3: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 3 of 23©NIIT

Collaborate

Collaborate

Using the cal Command (Contd.)The following are the options that you can use with cal command:

Option Description

-s Displays Sunday as the first day of the week.

-m Displays Monday as the first day of the week.

-j Displays Julian dates.

-y Displays the entire calendar for the current year. The year starts from January 1.

-1 Displays the calendar of the current month.

-3 Displays the calendar for the previous, current, and next month as output.

Page 4: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 4 of 23©NIIT

Collaborate

Collaborate

Determining the File Types

• The file command examines the content of the file and returns the type of file.

• The syntax for file command is: file [options] file_name

• The output of the file command categorizes the content of the file under the following categories :

• Text: If the file contains only printable characters.

• Executable: If the file is a program that can be interpreted by the UNIX kernel.

• Data: If the file contains binary or non-printable characters.

Page 5: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 5 of 23©NIIT

Collaborate

Collaborate

Determining the File Types (Contd.)The following table lists the various options that you can use with the file command:

Option Description

-r Skips the translation of non-printable characters to octal representation

-F Specifies the separator for the output of the file command

-s Identifies the block and character special files

Page 6: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 6 of 23©NIIT

Collaborate

Collaborate

From the Expert’s DeskThis section will introduce the following:

• Tips and tricks on working faster in Linux

• FAQs

Page 7: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 7 of 23©NIIT

Collaborate

Collaborate

Tips and TricksUsing the who – H Command

• The who –H command displays the column headings along with the output of the who command.

$ who -H

NAME LINE TIME COMMENT

steve tty1 Aug 17 11:44

steve :0 Aug 17 12:24

root pts/0 Aug 16 09:10

steve pts/27 Aug 17 12:35 (:0.0)

root pts/45 Aug 18 09:35 (172.17.66.241)

steve pts/56 Aug 18 13:57 (172.17.66.241)

john pts/59 Aug 18 17:12 (172.17.66.241)

Page 8: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 8 of 23©NIIT

Collaborate

Collaborate

Tips and TricksUsing Arrow Keys as Shortcuts

• You can use the arrow keys (, , , and ) to access previously executed commands.

• Press the up arrow key, , to access the previously used commands.

• Press the arrow key, to navigate down.

• Press the and arrow keys to move cursor to the beginning and the end of the command, respectively, one character at a time.

Page 9: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 9 of 23©NIIT

Collaborate

Collaborate

Tips and TricksUsing PageUp and PageDown Keys

• You can use the PageUp key to scroll up and the PageDown key to scroll down the screen.

• You can also use the and arrow keys to move up and down the page one line at a time in a screen.

Page 10: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 10 of 23©NIIT

Collaborate

Collaborate

FAQs• Is it possible to create multiple empty files using one command?

You can create multiple empty files in Linux using touch command. YouCan create any number of files in one command. For example,$touch empty1 empty2 empty3 empty4 empty5

The preceding command creates five empty files.

Page 11: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 11 of 23©NIIT

Collaborate

Collaborate

FAQs (Contd.)• How do you run the calculator at the shell prompt to do calculations?

The bc command is used to start calculator at the shell prompt. bc isthe abbreviation of best calculator. The input to the calculator is takenline by line. The calculator gives the output after each line of input, as illustrated in the following example: $ bc 10+10 20

sqrt(100) 10

quit

Page 12: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 12 of 23©NIIT

Collaborate

Collaborate

FAQs (Contd.)• Is it possible to view the list of users who logged on to a Linux system at a

specified date and time?

To see the list of users who logged on to the Linux system at a particular date and time, give the last command with -t option in the following format:$ last -t YYYYMMDDHHMMSS

Page 13: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 13 of 23©NIIT

Collaborate

Collaborate

FAQs (Contd.)• How can I change the default format of date that is displayed by the date

command?

You can change the default format of the output of date command using the various switches, such as +, %d, and %n. The new format should be enclosed in single quotes and must begin with the + sign. For example, you may want to print the output as follows: Date:20-08-04

Time:11:33:14

You can give the following command:$date '+Date:%d-%m-%y%nTime:%H:%M:%S‘

The strings, %d, %m, and %y represent day, month, and year, respectively.The strings, %H, %M, and %S represent hour, minute, and second,respectively. The string %n is used to print a line break.

Page 14: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 14 of 23©NIIT

Collaborate

Collaborate

FAQs (Contd.)• What is the difference between Linux and Unix?

The main difference between Linux and Unix is that Linux is available free of charge and the licensing for Unix is very expensive. Linux is a Unix-clone and provides support for most Unix-based applications. All the shells available for Linux are also based on the Unix shells. However, the shells available with Linux are free and have added features. Linux is becoming increasingly popular, not only for server-side computers but also for desktop use.

• Does open source and Linux mean the same?

No. The open source movement aims at keeping the software source code open and accessible to all. Open source software includes the Linux software.

Page 15: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 15 of 23©NIIT

Collaborate

Collaborate

FAQs (Contd.)• Because Linux is free, how do companies selling Linux earn revenue?

Traditionally, license fees have been the main source of revenue for the software industry. Companies selling Linux, such as Red Hat, usually earn from the support and training they provide to their clients.

Page 16: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 16 of 23©NIIT

Collaborate

Collaborate

Challenge1. Match the features with the respective operating system. Remember that the

operating system should truly support the feature with which you match the operating system.

Features Operating System

Multi-user MS-DOS

Multiprocessing Windows NT

CLI Linux

Page 17: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 17 of 23©NIIT

Collaborate

Collaborate

Challenge (Contd.)2. Create a file called initial with the following content:

first file created

only 2 line of content

Write a single command to create the file, final, and copy the content of the file, initial, to the file, final, using symbolic linking. Display the content of thefile, final, to verify the output. Using ls command, notice the difference in the listing of file, final.

3. In a data processing organization, when an employee resigns and leaves the organization, it is the practice to store the data of that employee in the Linux server of the company under the directory containing the name of the employee who has resigned. Further, the data inside the directory is maintained in subdirectories based on the projects in which the employee has worked.

Page 18: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 18 of 23©NIIT

Collaborate

Collaborate

Challenge (Contd.)

3. (Contd.)For example, the employee who has resigned had the following directory

structure:/steve : home directory containing following sub directoriesproj_ABCproj_dishnetproj_wincableproj_citipersonal_info Each of the above files are related to the project and personalInformation, respectively. You are the system administrator for theorganization and need to do the following: Move all the project files of Steve in a directory called steve_backup underthe directory, /. Delete the entire directory structure of steve using one single command.

©NIIT Collaborate

Page 19: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

©NIIT

Collaborate

Collaborate

Challenge (Contd.)4. A user, Angela, has just logged on to her home directory, which is the

directory, angela, under the directory, user. She then gives the following commands. The results of these commands have been left blank. Fill in the blanks.$pwd ______

$ cd ../.. $pwd ______

$ cd /bin $ pwd _______

$ After the above sequence of commands, the user, Angela, wants to go backto her home directory. Identify the command that she needs to use using thefull path name.

Lesson 1C / Slide 19 of 23©NIIT Collaborate

Page 20: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

©NIIT

Collaborate

Collaborate

Challenge (Contd.)5. Which of the files from the following file list would the command, cat ch,

display? matchpatchchoo1.c.chchch.cpost-script

Lesson 1C / Slide 20 of 23©NIIT Collaborate

Page 21: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 21 of 23©NIIT

Collaborate

Collaborate

Solutions to Challenge

1. Multi-user: Linux Multiprocessing: Windows NTCLI: MS-DOS

2. Create the file, initial, using the following command: $ cat > initial

first file created

only 2 line of content

Copy the content of file, initial, to a new file, final, using the followingcommand:$ cp –s initial final

List the information of the file, final, using the following command: $ ls –l final

Page 22: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

Lesson 1C / Slide 22 of 23©NIIT

Collaborate

Collaborate

Solutions to Challenge (Contd.)

3. To perform the task of making a back up of Steve’s directory, you need to log on as the root user as follows: [root@linuxpc1 root]# cd / [root@linuxpc1 /]#

Create the directory, /steve_backup, using the following command:[root@linuxpc1 /]# mkdir /steve_backup Move the files from directory, /home/steve, to the directory, /steve_backup,using the following command:[root@linuxpc1 /]# mv /home/steve/* /steve_backup Remove the directory structure of the directory, /steve, using the followingcommand:[root@linuxpc1 /]# rm –r /steve

Page 23: ©NIIT Collaborate Lesson 1C / Slide 1 of 23 Collaborate Knowledge Byte In this section, you will learn to: Use the cal command Determine the file types

©NIIT

Collaborate

Collaborate Lesson 1C / Slide 23 of 23©NIIT Collaborate

Solutions to Challenge (Contd.)

4. The output of the command will be as follows: $pwd /user/angela

$ cd ../.. $pwd /

$ cd /bin $ pwd /bin

$ cd /user/angela

5. The command will display the content of the ch file.