Vb.net Practical No
-
Upload
nouman-m-durrani -
Category
Documents
-
view
228 -
download
0
Transcript of Vb.net Practical No
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 1/41
Microsoft VB.Netand ASP.Net
1
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 2/41
Practical No. 01
Enumeration : Enumeration is a related set of constants. They are used whenworking with many constants of the same type. It's declared with the Enum keyword.
Output of above code is the image below:
Imports System.ConsoleModule Module1Enum SeasonsSummer = 1Winter = 2Spring = 3Autumn = 4End EnumSub Main()Write("Summer is the" & Seasons.Summer & "season")End SubEnd Module
2
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 3/41
Practical No. 02
If....Else statement
If conditional expression is one of the most useful control structures which allows usto execute a expression if a condition is true and execute a different expression if it isFalse. The syntax looks like this:
If condition Then[statements]Else If condition Then[statements]--Else
[statements]End If
If the condition is true, the statements following the Then keyword will be executed,else, the statements following the ElseIf will be checked and if true, will be executed,else, the statements in the else part will be executed.
Imports System.ConsoleModule Module1Sub Main()Dim i As Integer
WriteLine("Enter an integer, 1 or 2 or 3")i = Val(ReadLine())'ReadLine() method is used to read from console
If i = 1 ThenWriteLine("One")ElseIf i = 2 ThenWriteLine("Two")ElseIf i = 3 ThenWriteLine("Three")ElseWriteLine("Number not 1,2,3")End If
End Sub
End Module
3
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 4/41
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 5/41
Practical No. 04
For Loop
The For loop is the most popular loop. For loops enable us to execute a series of
expressions multiple numbers of times. The For loop in VB .NET needs a loop indexwhich counts the number of loop iterations as the loop executes. The syntax for theFor loop looks like this:
For index=start to end[Step step][statements][Exit For][statements]Next[index]
The index variable is set to start automatically when the loop starts. Each time in theloop, index is incremented by step and when index equals end, the loop ends.
Module Module1
Sub Main()Dim d As IntegerFor d = 0 To 2System.Console.WriteLine("In the For Loop")Next dEnd SubEnd Module
5
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 6/41
Practical No. 05
Arrays
Arrays are programming constructs that store data and allow us to access them bynumeric index or subscript. Arrays helps us create shorter and simpler code in manysituations. Arrays in Visual Basic .NET inherit from the Array class in the Systemnamespace. All arrays in VB as zero based, meaning, the index of the first element iszero and they are numbered sequentially.
The following code demonstrates arrays.
Imports System.ConsoleModule Module1Sub Main()Dim sport(5) As String'declaring an arraysport(0) = "Soccer"sport(1) = "Cricket"sport(2) = "Rugby"sport(3) = "Aussie Rules"sport(4) = "BasketBall"sport(5) = "Hockey"'storing values in the arrayWriteLine("Name of the Sport in the third location" & " " & sport(2))'displaying value from array
End SubEnd Module
6
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 7/41
Practical No. 06
Classes and Objects
Classes are types and Objects are instances of the Class. Classes and Objects arevery much related to each other. Without objects you can't use a class. In VisualBasic we create a class with the Class statement and end it with End Class. TheSyntax for a Class looks as follows:
Public Class Test
----- Variables-----Methods-----Properties-----Events
End Class
The above syntax created a class named Test. To create a object for this class we usethe new keyword and that looks like this: Dim obj as new Test(). The followingcode shows how to create a Class and access the class with an Object. Open aConsole Application and place the following code in it.
Module Module1Imports System.Console Sub Main()Dim obj As New Test()'creating a object obj for Test class
obj.disp()'calling the disp method using objRead()End Sub
End Module
Public Class Test'creating a class named TestSub disp()'a method named disp in the classWrite("Welcome to OOP")End SubEnd Class
Output of above code is the image below.
7
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 8/41
Practical No. 07
Inheritance
A key feature of OOP is reusability. It's always time saving and useful if we can reusesomething that already exists rather than trying to create the same thing again andagain. Reusing the class that is tested, debugged and used many times can save ustime and effort of developing and testing it again. Once a class has been written andtested, it can be used by other programs to suit the program's requirement. This isdone by creating a new class from an existing class. The process of deriving a newclass from an existing class is called Inheritance. The old class is called the base classand the new class is called derived class. The derived class inherits some oreverything of the base class. In Visual Basic we use the Inherits keyword to inheritone class from other. The general form of deriving a new class from an existing class
looks as follows:
Public Class One---End Class
Public Class TwoInherits One
------End Class
Using Inheritance we can use the variables, methods, properties, etc, from the base
class and add more functionality to it in the derived class. The following codedemonstrates the process of Inheritance in Visual Basic.
8
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 9/41
Imports System.ConsoleModule Module1
Sub Main()Dim ss As New Two()
WriteLine(ss.sum())Read()End Sub
End Module
Public Class One'base classPublic i As Integer = 10Public j As Integer = 20
Public Function add() As IntegerReturn i + jEnd Function
End Class
Public Class Two Inherits One
'derived class. class two inherited from class onePublic k As Integer = 100
Public Function sum() As Integer'using the variables, function from base class and adding morefunctionalityReturn i + j + kEnd Function
End Class
9
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 10/41
Practical No. 08
Math Functions
Visual Basic provides support for handling Mathematical calculations. Math functionsare stored in System.Math namespace. We need to import this namespace when wework with Math functions. The functions built into Math class helps us calculate the
Trigonometry values, Square roots, logarithm values, etc.
The following code puts some Math functions to work.
Imports System.ConsoleImports System.MathModule Module1
Sub Main()
WriteLine("Sine 90 is" & " " & Sin(90))'display Sine90 valueWriteLine("Square root of 81 is " & " " & Sqrt(81))'displays square root of 81WriteLine("Log value of 12 is" & " " & Log(12))'displays the logarithm value of 12Read()End Sub
End Module
The image below displays output from above code.
10
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 11/41
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 12/41
CheckBox
CheckBoxes are those controls which gives us an option to select, say, Yes/No or True/False. A checkbox is clicked to select and clicked again to deselect some option.
When a checkbox is selected a check (a tick mark) appears indicating a selection. The CheckBox control is based on the TextBoxBase class which is based on the
Control class. The default event of the CheckBox is the CheckedChangeevent. Below is the image of a Checkbox.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_System.EventArgs) Handles Button1.ClickIf CheckBox1.Checked = True ThenTextBox1.Text = "Checked"ElseTextBox1.Text = "UnChecked"End IfEnd Sub
RadioButton
RadioButtons are similar to CheckBoxes but RadioButtons are displayed as roundedinstead of boxed as with a checkbox. Like CheckBoxes, RadioButtons are used toselect and deselect options but they allow us to choose from mutually exclusiveoptions. The RadioButton control is based on the ButtonBase class which is based onthe Control class. A major difference between CheckBoxes and RadioButtons is,
RadioButtons are mostly used together in a group. The default event of the
RadioButton is the CheckedChange event
12
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 13/41
Below is the image of a RadioButton.
Code to check a RadioButton's state
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_System.EventArgs) Handles Button1.ClickIf RadioButton1.Checked = True ThenTextBox1.Text = "Selected"ElseTextBox1.Text = "Not Selected"End IfEnd Sub
13
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 14/41
Database andInformation System
14
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 15/41
Practical No. 01
SQL Syntax
SELECT Company, Country FROM Customers WHERE Country <> 'USA'
SQL Result
Company Country
Island Trading UK
Galería del gastrónomo Spain
Laughing Bacchus Wine Cellars Canada
Paris spécialités France
Simons bistro Denmark
Wolski Zajazd Poland
SQL WHERE
The SQL WHERE clause is used to select data conditionally, by adding it toalready existing SQL SELECT query. We are going to use the Customerstable from the previous chapter, to illustrate the use of the SQL WHEREcommand.
Table: Customers
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 222-2222
Steven Goldfish [email protected] 4/4/1974 323 455-4545
Paula Brown [email protected] 5/24/1978 416 323-3232
James Smith [email protected] 20/10/1980 416 323-8888
If we want to select all customers from our database table, having last name'Smith' we need to use the following SQL syntax:
15
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 16/41
SELECT *
FROM CustomersWHERE LastName = 'Smith'
The result of the SQL expression above will be the following:
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 222-2222
James Smith [email protected] 20/10/1980 416 323-8888
In this simple SQL query we used the "=" (Equal) operator in our WHEREcriteria:
LastName = 'Smith'
But we can use any of the following comparison operators in conjunction withthe SQL WHERE clause:
<> (Not Equal)
SELECT *
FROM CustomersWHERE LastName <> 'Smith'
> (Greater than)
SELECT *FROM CustomersWHERE DOB > '1/1/1970'
>= (Greater or Equal)
SELECT *FROM CustomersWHERE DOB >= '1/1/1970'
16
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 17/41
< (Less than)
SELECT *FROM Customers
WHERE DOB < '1/1/1970'
<= (Less or Equal)
SELECT *FROM CustomersWHERE DOB =< '1/1/1970'
LIKE (similar to)
SELECT *FROM CustomersWHERE Phone LIKE '626%'
17
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 18/41
Practical No. 02
SQL UPDATE
The SQL UPDATE general syntax looks like this:
UPDATE Table1SET Column1 = Value1, Column2 = Value2WHERE Some_Column = Some_Value
The SQL UPDATE clause changes the data in already existing databaserow(s) and usually we need to add a conditional SQL WHERE clause to ourSQL UPDATE statement in order to specify which row(s) we intend to
update.
If we want to update the Mr. Steven Goldfish's date of birth to '5/10/1974' inour Customers database table
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 222-2222
Steven Goldfish [email protected] 4/4/1974 323 455-4545
Paula Brown [email protected] 5/24/1978 416 323-3232
James Smith [email protected] 20/10/1980 416 323-8888
we need the following SQL UPDATE statement:
UPDATE CustomersSET DOB = '5/10/1974'WHERE LastName = 'Goldfish' AND FirstName = 'Steven'
If we don’t specify a WHERE clause in the SQL expression above, allcustomers' DOB will be updated to '5/10/1974', so be careful with the SQL
UPDATE command usage.
We can update several database table rows at once, by using the SQL WHEREclause in our UPDATE statement. For example if we want to change thephone number for all customers with last name Smith (we have 2 in ourexample Customers table), we need to use the following SQL UPDATEstatement:
18
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 19/41
UPDATE CustomersSET Phone = '626 555-5555'
WHERE LastName = 'Smith'
After the execution of the UPDATE SQL expression above, theCustomers table will look as follows:
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 555-5555
Steven Goldfish [email protected] 4/4/1974 323 455-4545
Paula Brown [email protected] 5/24/1978 416 323-3232
James Smith [email protected] 20/10/1980 626 555-5555
19
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 20/41
Practical No. 03
SQL DELETE
The SQL DELETE command has the following generic SQL syntax:
DELETE FROM Table1WHERE Some_Column = Some_Value
If you skip the SQL WHERE clause when executing SQL DELETE
expression, then all the data in the specified table will bedeleted. The following SQL statement will delete all the datafrom our Customers table and we’ll end up with completely empty
table:
DELETE FROM Table1
If you specify a WHERE clause in your SQL DELETE statement, onlythe table rows satisfying the WHERE criteria will be deleted:
DELETE FROM Customers
WHERE LastName = 'Smith'
The SQL query above will delete all database rows having LastName'Smith' and will leave the Customers table in the followingstate:
FirstName LastName Email DOB Phone
Steven Goldfish [email protected] 4/4/1974 323 455-4545
Paula Brown [email protected] 5/24/1978 416 323-3232
20
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 21/41
Practical No. 04
SQL JOIN
The SQL JOIN clause is used whenever we have to select data from 2 ormore tables.
To be able to use SQL JOIN clause to extract data from 2 (or more) tables,we need a relationship between certain columns in these tables.
We are going to illustrate our SQL JOIN example with the following 2 tables:
Customers:
CustomerID FirstName LastName Email DOB Phone
1 John Smith [email protected] 2/4/1968 626222-2222
2 Steven Goldfish [email protected] 4/4/1974323455-4545
3 Paula Brown [email protected] 5/24/1978416323-3232
4 James Smith [email protected] 20/10/1980416323-8888
Sales:
CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/7/2004 $99.95
3 5/7/2004 $122.95
3 5/13/2004 $100.00
4 5/22/2004 $555.55
As you can see those 2 tables have common field called CustomerID andthanks to that we can extract information from both tables by matching theirCustomerID columns.
Consider the following SQL statement:
21
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 22/41
SELECT Customers.FirstName, Customers.LastName,SUM(Sales.SaleAmount) AS SalesPerCustomerFROM Customers, SalesWHERE Customers.CustomerID = Sales.CustomerIDGROUP BY Customers.FirstName, Customers.LastName
The SQL expression above will select all distinct customers (their first and lastnames) and the total respective amount of dollars they have spent. The SQL JOIN condition has been specified after the SQL WHERE clause andsays that the 2 tables have to be matched by their respective CustomerIDcolumns.
Here is the result of this SQL statement:
FirstName LastName SalesPerCustomers
John Smith $99.95
Steven Goldfish $100.22
Paula Brown $222.95
James Smith $555.55
The SQL statement above can be re-written using the SQL JOIN clause likethis:
SELECT Customers.FirstName, Customers.LastName,SUM(Sales.SaleAmount) AS SalesPerCustomerFROM Customers JOIN SalesON Customers.CustomerID = Sales.CustomerIDGROUP BY Customers.FirstName, Customers.LastName
There are 2 types of SQL JOINS – INNER JOINS and OUTER JOINS. If youdon't put INNER or OUTER keywords in front of the SQL JOIN keyword, thenINNER JOIN is used. In short "INNER JOIN" = "JOIN" (note that differentdatabases have different syntax for their JOIN clauses).
The INNER JOIN will select all rows from both tables as long as there is amatch between the columns we are matching on. In case we have a customerin the Customers table, which still hasn't made any orders (there are noentries for this customer in the Sales table), this customer will not be listed inthe result of our SQL query above.
If the Sales table has the following rows:
22
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 23/41
CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/6/2004 $99.95
And we use the same SQL JOIN statement from above:
SELECT Customers.FirstName, Customers.LastName,SUM(Sales.SaleAmount) AS SalesPerCustomerFROM Customers JOIN SalesON Customers.CustomerID = Sales.CustomerIDGROUP BY Customers.FirstName, Customers.LastName
We'll get the following result:
FirstName LastName SalesPerCustomers
John Smith $99.95
Steven Goldfish $100.22
Even though Paula and James are listed as customers in the Customers tablethey won't be displayed because they haven't purchased anything yet.
But what if you want to display all the customers and their sales, no matter if they have ordered something or not? We’ll do that with the help of SQLOUTER JOIN clause.
The second type of SQL JOIN is called SQL OUTER JOIN and it has 2 sub-types called LEFT OUTER JOIN and RIGHT OUTER JOIN.
The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTERkeyword in most databases), selects all the rows from the first table listedafter the FROM clause, no matter if they have matches in the second table.
If we slightly modify our last SQL statement to:
SELECT Customers.FirstName, Customers.LastName,SUM(Sales.SaleAmount) AS SalesPerCustomerFROM Customers LEFT JOIN SalesON Customers.CustomerID = Sales.CustomerIDGROUP BY Customers.FirstName, Customers.LastName
and the Sales table still has the following rows:
23
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 24/41
CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/6/2004 $99.95
The result will be the following:
FirstName LastName SalesPerCustomers
John Smith $99.95
Steven Goldfish $100.22
Paula Brown NULL
James Smith NULL
As you can see we have selected everything from the Customers (first table).For all rows from Customers, which don’t have a match in the Sales (secondtable), the SalesPerCustomer column has amount NULL (NULL means acolumn contains nothing).
The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT JOIN, except that it returns all rows from the second table (the right table inour SQL JOIN statement).
24
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 25/41
Practical No. 05
SQL AND & OR
The SQL AND clause is used when you want to specify more than onecondition in your SQL WHERE clause, and at the same time you want allconditions to be true.For example if you want to select all customers with FirstName "John" andLastName "Smith", you will use the following SQL expression:
SELECT * FROM CustomersWHERE FirstName = 'John' AND LastName = 'Smith'
The result of the SQL query above is:
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 222-2222
The following row in our Customer table, satisfies the second of theconditions (LastName = 'Smith'), but not the first one (FirstName = 'John'),and that's why it's not returned by our SQL query:
FirstName LastName Email DOB Phone
James Smith [email protected] 20/10/1980 416 323-8888
The SQL OR statement is used in similar fashion and the major differencecompared to the SQL AND is that OR clause will return all rows satisfying anyof the conditions listed in the WHERE clause.
If we want to select all customers having FirstName 'James' or FirstName'Paula' we need to use the following SQL statement:
SELECT * FROM CustomersWHERE FirstName = 'James' OR FirstName = 'Paula'
25
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 26/41
The result of this query will be the following:
FirstName LastName Email DOB Phone
Paula Brown [email protected] 5/24/1978 416 323-3232
James Smith [email protected] 20/10/1980 416 323-8888
You can combine AND and OR clauses anyway you want and you can useparentheses to define your logical expressions.Here is an example of such a SQL query, selecting all customers withLastName 'Brown' and FirstName either 'James' or 'Paula':
SELECT * FROM CustomersWHERE (FirstName = 'James' OR FirstName = 'Paula') AND LastName= 'Brown'
The result of the SQL expression above will be:
FirstName LastName Email DOB Phone
Paula Brown [email protected] 5/24/1978 416 323-3232
26
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 27/41
Practical No. 06
SQL ORDER BY
The SQL ORDER BY clause comes in handy when you want to sort your SQLresult sets by some column(s). For example if you want to select all thepersons from the already familiar Customers table and order the result bydate of birth, you will use the following statement:
SELECT * FROM CustomersORDER BY DOB
The result of the above SQL expression will be the following:
FirstName LastName Email DOB Phone
John Smith [email protected] 2/4/1968 626 222-2222
Steven Goldfish [email protected] 4/4/1974 323 455-4545
Paula Brown [email protected] 5/24/1978 416 323-3232
James Smith [email protected] 20/10/1980 416 323-8888
As you can see the rows are sorted in ascending order by the DOB column,but what if you want to sort them in descending order? To do that you willhave to add the DESC SQL keyword after your SQL ORDER BY clause:
SELECT * FROM CustomersORDER BY DOB DESC
The result of the SQL query above will look like this:
FirstName LastName Email DOB Phone
James Smith [email protected] 20/10/1980 416 323-8888
Paula Brown [email protected] 5/24/1978 416 323-3232
Steven Goldfish [email protected] 4/4/1974 323 455-4545
John Smith [email protected] 2/4/1968 626 222-2222
If you don't specify how to order your rows, alphabetically or reverse, thanthe result set is ordered alphabetically, hence the following to SQLexpressions produce the same result:
27
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 28/41
SELECT * FROM CustomersORDER BY DOB
SELECT * FROM CustomersORDER BY DOB ASC
You can sort your result set by more than one column by specifying thosecolumns in the SQL ORDER BY list. The following SQL expression will orderby DOB and LastName:
SELECT * FROM CustomersORDER BY DOB, LastName
28
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 29/41
Networking with Red
Hat Linux &Wireless
Communication
29
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 30/41
Basic Linux Commands:
Command
Example Description
cat Sends file contents to standard output. This is away to list the contents of short files to thescreen. It works well with piping.
cat .bashrc Sends the contents of the ".bashrc" file to thescreen.
cd Change directory
cd /home Change the current working directory to /home. The '/' indicates relative to root, and no matterwhat directory you are in when you executethis command, the directory will be changed to"/home".
cd httpd Change the current working directory to httpd,relative to the current location which is"/home". The full path of the new workingdirectory is "/home/httpd".
cd .. Move to the parent directory of the currentdirectory. This command will make the currentworking directory "/home.
cd ~ Move to the user's home directory which is"/home/username". The '~' indicates the usershome directory.
cp Copy files
cp myfile yourfile Copy the files "myfile" to the file "yourfile" inthe current working directory. This commandwill create the file "yourfile" if it doesn't exist. Itwill normally overwrite it without warning if itexists.
cp -i myfile yourfile With the "-i" option, if the file "yourfile" exists,you will be prompted before it is overwritten.
cp -i /data/myfile . Copy the file "/data/myfile" to the currentworking directory and name it "myfile". Promptbefore overwriting the file.
cp -dpr srcdirdestdir
Copy all files from the directory "srcdir" to thedirectory "destdir" preserving links (-p option),
file attributes (-p option), and copy recursively(-r option). With these options, a directory andall it contents can be copied to anotherdirectory.
dd dd if=/dev/hdb1of=/backup/
Disk duplicate. The man page says thiscommand is to "Convert and copy a file", butalthough used by more advanced users, it canbe a very handy command. The "if" means
30
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 31/41
input file, "of" means output file.
df Show the amount of disk space used on eachmounted filesystem.
lessless textfile
Similar to the more command, but the user canpage up and down through the file. Theexample displays the contents of textfile.
ln Creates a symbolic link to a file.
ln -s test symlink Creates a symbolic link named symlink thatpoints to the file test Typing "ls -i test symlink"will show the two files are different withdifferent inodes. Typing "ls -l test symlink" willshow that symlink points to the file test.
locate A fast database driven file locator.
slocate -u This command builds the slocate database. Itwill take several minutes to complete thiscommand. This command must be used beforesearching for files, however cron runs this
command periodically on most systems.locate whereis Lists all files whose names contain the string
"whereis".
logout Logs the current user off the system.
ls List files
ls List files in the current working directory exceptthose starting with . and only show the filename.
ls -al List all files in the current working directory inlong listing format showing permissions,ownership, size, and time and date stamp
more Allows file contents or piped output to be sentto the screen one page at a time.
more /etc/profile Lists the contents of the "/etc/profile" file to thescreen one page at a time.
ls -al |more Performs a directory listing of all files and pipesthe output of the listing through more. If thedirectory listing is longer than a page, it will belisted one page at a time.
mv Move or rename files
mv -i myfile yourfile Move the file from "myfile" to "yourfile". Thiseffectively changes the name of "myfile" to"yourfile".
mv -i /data/myfile . Move the file from "myfile" from the directory"/data" to the current working directory.
pwd Show the name of the current working directory
more /etc/profile Lists the contents of the "/etc/profile" file to thescreen one page at a time.
shutdown
Shuts the system down.
31
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 32/41
shutdown -h now Shuts the system down to halt immediately.
shutdown -r now Shuts the system down immediately and thesystem reboots.
whereis Show where the binary, source and manualpage files are for a command
whereis ls Locates binaries and manual pages for the lscommand.
32
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 33/41
Practical No. 01
Cal
1. Namecal - displays a calendar and the date of easter
2. Synopsis
cal [-3jmy] [[month] year]
3. Frequently used options
-3 Print the previous month, the current month, and the next month all onone row.
4. Examples
cal without any options displays current month in current year:$ cal
If we would like to see November in 2009:$ cal 11 2009
How about to see all months of year 2010:$ cal 2010
33
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 34/41
Cal is also able to predict vary distant future, not sure if any of us will everneed it, but here is month Jun for year 10001, so make sure that you do not
miss your appointment !:$ cal 6 10001
Display one months before and after current September 2007 :$ cal -3 9 2007
34
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 35/41
Practical No. 02
cd:
1. Namecd - change directory
2. Frequently used options
- change to previous directory
3. Examples
In unix systems there two most frequently used commands, one is "ls" andthe other is "cd". Command "cd" allows us to navigate through file system. Tonavigate to /etc/ directory simply enter:$ cd /etc
To navigate to previous directory we can enter:$ cd -
By entering cd without any arguments navigate to home directory:$ cd
4. Relative Path
5. Absolute Path
35
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 36/41
Practical No. 03
Touch
1. Name
touch - change file timestamps
2. Synopsis
touch [OPTION]... FILE...
3. Frequently used options
-a change only the access time-m change only the modification time-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
4. Examples
touch command enables us to change access and modification time for agiven files. Also touch command can be use to create files. Lets create filenamed touchfile.txt:$ touch touchfile.txt
To investigate more about this file we can use stat command.$ stat touchfile.txt
now we can use touch command to change access and modification time tocurrent time:$ touch touchfile.txt
To change only modification time we can use -m option:$ touch -m touchfile.txt
36
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 37/41
Or if we want to change just access time we use -a option$ touch -a touchfile.txt
Now lets say that we would like to change access and modification time backto 29 January 2005 13:45.45$ touch -t 200501291345.45 touchfile.txt
37
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 38/41
Practical No. 04
Tail
1. Name
tail - output the last part of files
2. Synopsis
tail [OPTION]... [FILE]...
3. Frequently used options
-c, --bytes=Noutput the last N bytes
-f, --follow[={name|descriptor}]output appended data as the file grows; -f, --follow, and--follow=descriptor are equivalent
-n, --lines=Noutput the last N lines, instead of the last 10
4. Examples
Lets create sample file. This file will contain names of all directories in /var/.We can also number each line for better overview.for f in $( ls /var/ ); do echo $f; done | nl > file1
By default a tail command displays last 10 lines of given file.tail
To display just last 3 lines from this file we use -n option:
38
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 39/41
tail -n 3 file1
Moreover the same output can be produced by command:
tail -3 file1
To use tail command on byte level we can use -c option. This option will maketail command to display last 4 bytes (4 characters) if a given file:
tail -c 4 file1
If you wonder why we can see only 3 characters, use od command to seewhere the 4th byte is:tail -c 4 file1 | od -a
Another very useful option for tail command is -f. This option will continuouslydisplay a file as it is dynamically edited by another process. This option isvery useful for watching log files.tail -f /var/log/syslog
39
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 40/41
Practical No. 05
Time
1. Name
time - run programs and summarize system resource usage
2. Synopsis
time [ -apqvV ] [ -f FORMAT ] [ -o FILE ][ --append ] [ --verbose ] [ --quiet ] [ --portability ][ --format=FORMAT ] [ --output=FILE ] [ --version ][ --help ] COMMAND [ ARGS ]
3. Examples
Measure time for running program time itself:$ time
Measure execution time of "find" command and redirect stderr to /dev/null:$ time find / -name resolv.conf 2>/dev/null
40
8/8/2019 Vb.net Practical No
http://slidepdf.com/reader/full/vbnet-practical-no 41/41
Practical No. 06
pwd
1. Name
pwd - print name of current/working directory
2. Synopsis
pwd [OPTION]
3. Examples
Pwd linux command prints name of current/working directory.pwd
Alternative to the pwd command could be dirs which prints the same output:dirs -l