SlideShare a Scribd company logo
1 of 9
Introduction to Unix - POS420
Unix Lab Exercise Week 3 A
Topics : Input/Output redirection
cut, paste and touch commands
Input/Output redirection :
1. When the shell executes any command, shell also opens three
files called file descriptors for every execution.
They are
stdin 0 Standard input to the
program
stdout 1 Standard output from the
program
stderr 2 Standard error output from
the program
A. Standard Input :
Here, wc -l command takes input from standard input, keyboard
$ wc -l
This is the text that
is typed on the
standard input device.
CTRL-d
3
$
B. Standard Output :
Here, the output of echo and date commands go to the terminal.
$ echo "hello"
hello
$ date
Mon Aug 11 17:57:38 EDT 2014
C. Standard Error :
$ ls myfile.txt
myfile.txt not found
$
ls command does not find myfile.txt in the current directory it
sends the error message to the terminal.
Let us type a command wrongly
$ ecoh hello
ksh: ecoh: not found. --- Standard Error is diverted to
terminal
2. We know that > represents to redirect output
< to redirect input
>> to append to a file
Let us redirect the output of this command to a file.
$ who > users
$
To see the contents
$ cat users
$
$ echo "This is line 1" > myfile
$ cat myfile
This is line 1
$ echo "This is line 2" >> myfile
$ cat myfile
This is line 1
This is line 2
2. Let us create a file called "datafile” in the east directory
under sales.
(We have already created sales and purchases directories in
our first lab). Enter the data through vi.
$ vi datafile
Enter the following data in vi insert mode :
Tom Smith 7.00 15 105.00
Rob Sheryl 8.00 20 160.00
Ken Bradman 7.00 13 91.00
Peter Smith 6.00 15 90.00
Dennis Smith 8.00 13 104.00
Tom Dave 9.00 12 108.00
3. We will append one more entry into this file
$ echo " John Lee 7.50 10 75.0" >> datafile
(If you use > , it will overwrite, but we are appending)
4. Create a file “memo1” with the Sales data in east directory
$ vi memo1
(Enter the following data)
Sales of the Year 2008
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
Create another file memo2 and enter the data
$ vi memo2
Sales of the Year 2007
Grocery $2100.00
Spare Parts $5000.00
Automobile $2999.00
Misc $1000.00
Now we will concatanate both files into Sales_0708.dat
$ cat memo1 memo2
Sales of the Year 2008
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
Sales of the Year 2007
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
This is not what we want, we want to redirect to a file.
$ cat memo1 memo2 > Sales_0708.dat
Now let us see the file
$ cat Sales_0708.dat
Sales of the Year 2007
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
Sales of the Year 2008
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
My manager is unhappy that there is no newline between those
two year's data.
Let us delete the file and recreate it
$ rm Sales_0708.dat
$ echo "" >> memo1
$ cat memo1 memo2 > Sales_0708.dat
Now let us see the file
$ cat Sales_0708.dat
Sales of the Year 2007
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.00
Sales of the Year 2008
Grocery $2000.00
Spare Parts $3000.00
Automobile $2678.00
Misc $1200.005.
$ echo "This is line 1" > file1
$ cat file1
This is line 1
$ echo "This is line 2" >> file2
$ cat file2
This is a line in file2.
$ cat file1 >> file2
$ cat file2
This is line in file2.
This is line in file1.
5. Another example :
$ cat file1
This is line in file1.
$ cat file2
This is line in file2.
$ cat file1 file2 > file3
$ cat file3
This is line in file1.
This is a line in file2.
6. Let us see input redirection
$ wc -l users
7 users
$
Now let us redirect the input of file to wc command.
$ wc -l < users
7
7. The sort command which we are going tp learn in detail later,
sorts a file alphabetically or numerically.
Type the names of some cities and enter [Return] after each one
and once you are done enter CTRL-d.
$ sort
Newyork
Chicago
Los Angeles
Detroit
CTRL-d
The output will be
Chicago
Detroit
Los Angeles
Newyork
Now we can redirect the input to come from a file (say the file
citylist has a list of cities) rather than the keyboard.
To sort the list of cities, type
Enter the cities in a file 'citylist' with vi
$ vi citylist
and type the following cities
Newyork
Chicago
Los Angeles
Detroit
Now let us sort
$ sort < citylist
Chicago
Detroit
Los Angeles
Newyork
The sorted list will be the output to the screen.
Now let us redirect the ouput to to a file.
$ sort < citylist > citysorted
$
See the contents of the file citysorted
$ cat citysorted
Chicago
Detroit
Los Angeles
Newyork
Let us see some examples :
1. To find out how many users are logged on, type
$ who | wc -l
2. To see top ten files of /etc directory.
$ ls -l /etc | head
3. We want to redirect the man page of ksh to a file.
$ man ksh > ksh_manpage
4. To see lines from 50 to 60 in a file.
$ head -60 filename | tail
5. To look for a particular user
$ who | grep mary
6. To count number of files in the /etc directory
$ ls -l /etc | wc -l
7. Sort the users currently logged into the system
$ who | sort
8. Create a file “ phonebook” in your home directory.
Tom Smith
732-330-1111
Kay George
732-300-0000
Penny Smith
973-560-1234
David Korn
908-444-0987
Mary Lisa
732-666-6789
Ashwin Patel
732-786-4567
Tom Kerry
732-456-1456
9. Create another file "intro" in your home directory and type
the following :(enter 4 lines as below)
The UNIX operating system was pioneered by Ken Thomson
and Dennis Ritchie at
Bell Laboratories in the late 1960s.
One of the primary goals in the design of the UNIX system was
to create an environment that (UNIX)promoted efficient
program development.
cut command :
10. Display the current users logged in:
$ who
11. Extract the first 8 characters :
$ who | cut -c1-8
12. Sort the above users
:
$ who | cut -c1-8 | sort
13. Extract the tty number fields from the above who
command :
$ who | cut -c10-16
14. Display the user name and login name :
$ who | cut -c1-8,18-
15. Display the file /etc/passwd on the screen.
$ cat /etc/passwd
16. Extract the first field of the above file (This runs long on
many machines like schools, free internet sites- Use CNTRL C
to stop)
$ cut -d: -f1 /etc/passwd
17. Extract the username and home directory ( 6th field ) :
$ cut -d: -f1,6 /etc/passwd
paste command:
If you do not have the files users1, ssn create the files and enter
the following contents.
$ vi users1
Tsmith Thomson Smith 9/17/02
Betsy Betsy Williams 9/16/02
Sandia Michael Sandiago 9/17/02
Vivian Vivian Richards 9/17/02
James James Blake 8/10/02
John Dev Jhonson 9/10/02
Cramer Ron Cramer 9/17/02
Nichols Ben Nicholos 8/01/02
David David Newton 9/16/02
$ vi ssn
Thomson Smith 111-22-0001
Betsy Williams 111-22-0002
Michael Sandiago 111-22-0004
Vivian Richards 111-22-0005
James Blake 111-22-0006
Dev Jhonson 111-22-0007
Ron Cramer 111-22-0008
Ben Nicholos 111-22-0009
David Newton 111-22-0010
18. First, extract the ssn into a temporary file, tempssn:
$ cut -d" " -f3 ssn > tempssn
19. Now paste the ssn to the end of each line in users1 and store
in a new file users_listing
$ paste users1 tempssn > users_listing
20. Now see the contents of the new file.
$ cat users_listing
Another way is :
$ cut -d" " -f2 ssn | paste users1 > users_listing
touch command :
$ touch filename
-- If filename does not exit it creates with zero
size,otherwise it updates the access time.
21. Let us create a new file, before that we make sure that it
does not exist.
$ ls filename
ls: The file filename does not exist.
22. Now create a file with touch command
$ touch filename
$ ls -l filename
-rw-r--r-- 1 stangira faculty 0 Jul 18 14:14 filename
See the size of the file creatd by touch command
23. Let us update the access time of another file.
$ ls -l users
-rw-r--r-- 1 stangira faculty 348 Jul 17 12:23 users
$ touch users
$ ls -lt users
-rw-r--r-- 1 stangira faculty 348 Oct 31 23:15 users
Syam Tangirala
University of Phoenix Online Faculty
[email protected]732-397-4997(CEL)

More Related Content

Similar to Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx

Similar to Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx (20)

Bozorgmeh os lab
Bozorgmeh os labBozorgmeh os lab
Bozorgmeh os lab
 
Devry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-filesDevry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-files
 
Devry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-filesDevry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-files
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
 
Unix notes
Unix notesUnix notes
Unix notes
 
Redhat 6 & 7
Redhat 6 & 7Redhat 6 & 7
Redhat 6 & 7
 
Presentation aix basic
Presentation   aix basicPresentation   aix basic
Presentation aix basic
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
Introduction to UNIX
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
 
Linux.pdf
Linux.pdfLinux.pdf
Linux.pdf
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
Linux admin interview questions
Linux admin interview questionsLinux admin interview questions
Linux admin interview questions
 

More from mariuse18nolet

IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docx
IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docxIRM 3305 Risk Management Theory and PracticeFall 2014Proje.docx
IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docxmariuse18nolet
 
Ironwood Company manufactures cast-iron barbeque cookware. During .docx
Ironwood Company manufactures cast-iron barbeque cookware. During .docxIronwood Company manufactures cast-iron barbeque cookware. During .docx
Ironwood Company manufactures cast-iron barbeque cookware. During .docxmariuse18nolet
 
IRM 3305 Risk Management Theory and PracticeGroup Project.docx
IRM 3305 Risk Management Theory and PracticeGroup Project.docxIRM 3305 Risk Management Theory and PracticeGroup Project.docx
IRM 3305 Risk Management Theory and PracticeGroup Project.docxmariuse18nolet
 
Iranian Women and GenderRelations in Los AngelesNAYEREH .docx
Iranian Women and GenderRelations in Los AngelesNAYEREH .docxIranian Women and GenderRelations in Los AngelesNAYEREH .docx
Iranian Women and GenderRelations in Los AngelesNAYEREH .docxmariuse18nolet
 
IRB HANDBOOK IRB A-Z Handbook E.docx
IRB HANDBOOK IRB A-Z Handbook  E.docxIRB HANDBOOK IRB A-Z Handbook  E.docx
IRB HANDBOOK IRB A-Z Handbook E.docxmariuse18nolet
 
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docx
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docxIQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docx
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docxmariuse18nolet
 
iPython 2For Beginners OnlyVersion 1.0Matthew .docx
iPython 2For Beginners OnlyVersion 1.0Matthew .docxiPython 2For Beginners OnlyVersion 1.0Matthew .docx
iPython 2For Beginners OnlyVersion 1.0Matthew .docxmariuse18nolet
 
Iranian Journal of Military Medicine Spring 2011, Volume 13, .docx
Iranian Journal of Military Medicine  Spring 2011, Volume 13, .docxIranian Journal of Military Medicine  Spring 2011, Volume 13, .docx
Iranian Journal of Military Medicine Spring 2011, Volume 13, .docxmariuse18nolet
 
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docx
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docxIoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docx
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docxmariuse18nolet
 
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docx
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docxIP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docx
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docxmariuse18nolet
 
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docx
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docxIranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docx
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docxmariuse18nolet
 
ipopulation monitoring in radiation emergencies a gui.docx
ipopulation monitoring in radiation emergencies a gui.docxipopulation monitoring in radiation emergencies a gui.docx
ipopulation monitoring in radiation emergencies a gui.docxmariuse18nolet
 
In Innovation as Usual How to Help Your People Bring Great Ideas .docx
In Innovation as Usual How to Help Your People Bring Great Ideas .docxIn Innovation as Usual How to Help Your People Bring Great Ideas .docx
In Innovation as Usual How to Help Your People Bring Great Ideas .docxmariuse18nolet
 
Investor’s Business Daily – Investors.comBloomberg Business – Blo.docx
Investor’s Business Daily –  Investors.comBloomberg Business – Blo.docxInvestor’s Business Daily –  Investors.comBloomberg Business – Blo.docx
Investor’s Business Daily – Investors.comBloomberg Business – Blo.docxmariuse18nolet
 
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docx
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docxInvitation to Public Speaking, Fifth EditionChapter 8 Introdu.docx
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docxmariuse18nolet
 
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docx
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docxInvitation to the Life SpanRead chapters 13 and 14.Objectives.docx
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docxmariuse18nolet
 
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docx
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docxIOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docx
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docxmariuse18nolet
 
INVITATION TO Computer Science 1 1 Chapter 17 Making .docx
INVITATION TO  Computer Science 1 1 Chapter 17 Making .docxINVITATION TO  Computer Science 1 1 Chapter 17 Making .docx
INVITATION TO Computer Science 1 1 Chapter 17 Making .docxmariuse18nolet
 
Investment Analysis & Portfolio Management AD 717 OLHomework E.docx
Investment Analysis & Portfolio Management AD 717 OLHomework E.docxInvestment Analysis & Portfolio Management AD 717 OLHomework E.docx
Investment Analysis & Portfolio Management AD 717 OLHomework E.docxmariuse18nolet
 
Investment BAFI 1042 Kevin Dorr 3195598 GOODMAN .docx
Investment BAFI 1042  Kevin Dorr 3195598  GOODMAN .docxInvestment BAFI 1042  Kevin Dorr 3195598  GOODMAN .docx
Investment BAFI 1042 Kevin Dorr 3195598 GOODMAN .docxmariuse18nolet
 

More from mariuse18nolet (20)

IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docx
IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docxIRM 3305 Risk Management Theory and PracticeFall 2014Proje.docx
IRM 3305 Risk Management Theory and PracticeFall 2014Proje.docx
 
Ironwood Company manufactures cast-iron barbeque cookware. During .docx
Ironwood Company manufactures cast-iron barbeque cookware. During .docxIronwood Company manufactures cast-iron barbeque cookware. During .docx
Ironwood Company manufactures cast-iron barbeque cookware. During .docx
 
IRM 3305 Risk Management Theory and PracticeGroup Project.docx
IRM 3305 Risk Management Theory and PracticeGroup Project.docxIRM 3305 Risk Management Theory and PracticeGroup Project.docx
IRM 3305 Risk Management Theory and PracticeGroup Project.docx
 
Iranian Women and GenderRelations in Los AngelesNAYEREH .docx
Iranian Women and GenderRelations in Los AngelesNAYEREH .docxIranian Women and GenderRelations in Los AngelesNAYEREH .docx
Iranian Women and GenderRelations in Los AngelesNAYEREH .docx
 
IRB HANDBOOK IRB A-Z Handbook E.docx
IRB HANDBOOK IRB A-Z Handbook  E.docxIRB HANDBOOK IRB A-Z Handbook  E.docx
IRB HANDBOOK IRB A-Z Handbook E.docx
 
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docx
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docxIQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docx
IQuiz # II-Emerson QuizGeneral For Emerson, truth (or.docx
 
iPython 2For Beginners OnlyVersion 1.0Matthew .docx
iPython 2For Beginners OnlyVersion 1.0Matthew .docxiPython 2For Beginners OnlyVersion 1.0Matthew .docx
iPython 2For Beginners OnlyVersion 1.0Matthew .docx
 
Iranian Journal of Military Medicine Spring 2011, Volume 13, .docx
Iranian Journal of Military Medicine  Spring 2011, Volume 13, .docxIranian Journal of Military Medicine  Spring 2011, Volume 13, .docx
Iranian Journal of Military Medicine Spring 2011, Volume 13, .docx
 
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docx
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docxIoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docx
IoT Referenceshttpswww.techrepublic.comarticlehow-to-secur.docx
 
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docx
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docxIP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docx
IP Subnet Design Project- ONLY QUALITY ASSIGNMENTS AND 0 PLAG.docx
 
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docx
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docxIranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docx
IranAyatollahTheocracyTwelver ShiismVilayat-e Faghih (jur.docx
 
ipopulation monitoring in radiation emergencies a gui.docx
ipopulation monitoring in radiation emergencies a gui.docxipopulation monitoring in radiation emergencies a gui.docx
ipopulation monitoring in radiation emergencies a gui.docx
 
In Innovation as Usual How to Help Your People Bring Great Ideas .docx
In Innovation as Usual How to Help Your People Bring Great Ideas .docxIn Innovation as Usual How to Help Your People Bring Great Ideas .docx
In Innovation as Usual How to Help Your People Bring Great Ideas .docx
 
Investor’s Business Daily – Investors.comBloomberg Business – Blo.docx
Investor’s Business Daily –  Investors.comBloomberg Business – Blo.docxInvestor’s Business Daily –  Investors.comBloomberg Business – Blo.docx
Investor’s Business Daily – Investors.comBloomberg Business – Blo.docx
 
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docx
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docxInvitation to Public Speaking, Fifth EditionChapter 8 Introdu.docx
Invitation to Public Speaking, Fifth EditionChapter 8 Introdu.docx
 
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docx
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docxInvitation to the Life SpanRead chapters 13 and 14.Objectives.docx
Invitation to the Life SpanRead chapters 13 and 14.Objectives.docx
 
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docx
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docxIOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docx
IOBOARD Week 2 Lab BPage 2 of 4Name _________________ Gr.docx
 
INVITATION TO Computer Science 1 1 Chapter 17 Making .docx
INVITATION TO  Computer Science 1 1 Chapter 17 Making .docxINVITATION TO  Computer Science 1 1 Chapter 17 Making .docx
INVITATION TO Computer Science 1 1 Chapter 17 Making .docx
 
Investment Analysis & Portfolio Management AD 717 OLHomework E.docx
Investment Analysis & Portfolio Management AD 717 OLHomework E.docxInvestment Analysis & Portfolio Management AD 717 OLHomework E.docx
Investment Analysis & Portfolio Management AD 717 OLHomework E.docx
 
Investment BAFI 1042 Kevin Dorr 3195598 GOODMAN .docx
Investment BAFI 1042  Kevin Dorr 3195598  GOODMAN .docxInvestment BAFI 1042  Kevin Dorr 3195598  GOODMAN .docx
Investment BAFI 1042 Kevin Dorr 3195598 GOODMAN .docx
 

Recently uploaded

IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff17thcssbs2
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeSaadHumayun7
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesashishpaul799
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPragya - UEM Kolkata Quiz Club
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxnuriaiuzzolino1
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 

Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx

  • 1. Introduction to Unix - POS420 Unix Lab Exercise Week 3 A Topics : Input/Output redirection cut, paste and touch commands Input/Output redirection : 1. When the shell executes any command, shell also opens three files called file descriptors for every execution. They are stdin 0 Standard input to the program stdout 1 Standard output from the program stderr 2 Standard error output from the program A. Standard Input : Here, wc -l command takes input from standard input, keyboard $ wc -l This is the text that is typed on the standard input device. CTRL-d 3 $ B. Standard Output : Here, the output of echo and date commands go to the terminal. $ echo "hello" hello $ date Mon Aug 11 17:57:38 EDT 2014 C. Standard Error : $ ls myfile.txt myfile.txt not found $ ls command does not find myfile.txt in the current directory it
  • 2. sends the error message to the terminal. Let us type a command wrongly $ ecoh hello ksh: ecoh: not found. --- Standard Error is diverted to terminal 2. We know that > represents to redirect output < to redirect input >> to append to a file Let us redirect the output of this command to a file. $ who > users $ To see the contents $ cat users $ $ echo "This is line 1" > myfile $ cat myfile This is line 1 $ echo "This is line 2" >> myfile $ cat myfile This is line 1 This is line 2 2. Let us create a file called "datafile” in the east directory under sales. (We have already created sales and purchases directories in our first lab). Enter the data through vi. $ vi datafile Enter the following data in vi insert mode : Tom Smith 7.00 15 105.00 Rob Sheryl 8.00 20 160.00 Ken Bradman 7.00 13 91.00 Peter Smith 6.00 15 90.00 Dennis Smith 8.00 13 104.00 Tom Dave 9.00 12 108.00 3. We will append one more entry into this file $ echo " John Lee 7.50 10 75.0" >> datafile (If you use > , it will overwrite, but we are appending)
  • 3. 4. Create a file “memo1” with the Sales data in east directory $ vi memo1 (Enter the following data) Sales of the Year 2008 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00 Create another file memo2 and enter the data $ vi memo2 Sales of the Year 2007 Grocery $2100.00 Spare Parts $5000.00 Automobile $2999.00 Misc $1000.00 Now we will concatanate both files into Sales_0708.dat $ cat memo1 memo2 Sales of the Year 2008 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00 Sales of the Year 2007 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00 This is not what we want, we want to redirect to a file. $ cat memo1 memo2 > Sales_0708.dat Now let us see the file $ cat Sales_0708.dat Sales of the Year 2007 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00
  • 4. Sales of the Year 2008 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00 My manager is unhappy that there is no newline between those two year's data. Let us delete the file and recreate it $ rm Sales_0708.dat $ echo "" >> memo1 $ cat memo1 memo2 > Sales_0708.dat Now let us see the file $ cat Sales_0708.dat Sales of the Year 2007 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.00 Sales of the Year 2008 Grocery $2000.00 Spare Parts $3000.00 Automobile $2678.00 Misc $1200.005. $ echo "This is line 1" > file1 $ cat file1 This is line 1 $ echo "This is line 2" >> file2 $ cat file2 This is a line in file2. $ cat file1 >> file2 $ cat file2 This is line in file2. This is line in file1. 5. Another example : $ cat file1 This is line in file1.
  • 5. $ cat file2 This is line in file2. $ cat file1 file2 > file3 $ cat file3 This is line in file1. This is a line in file2. 6. Let us see input redirection $ wc -l users 7 users $ Now let us redirect the input of file to wc command. $ wc -l < users 7 7. The sort command which we are going tp learn in detail later, sorts a file alphabetically or numerically. Type the names of some cities and enter [Return] after each one and once you are done enter CTRL-d. $ sort Newyork Chicago Los Angeles Detroit CTRL-d The output will be Chicago Detroit Los Angeles Newyork Now we can redirect the input to come from a file (say the file citylist has a list of cities) rather than the keyboard. To sort the list of cities, type Enter the cities in a file 'citylist' with vi $ vi citylist and type the following cities Newyork Chicago
  • 6. Los Angeles Detroit Now let us sort $ sort < citylist Chicago Detroit Los Angeles Newyork The sorted list will be the output to the screen. Now let us redirect the ouput to to a file. $ sort < citylist > citysorted $ See the contents of the file citysorted $ cat citysorted Chicago Detroit Los Angeles Newyork Let us see some examples : 1. To find out how many users are logged on, type $ who | wc -l 2. To see top ten files of /etc directory. $ ls -l /etc | head 3. We want to redirect the man page of ksh to a file. $ man ksh > ksh_manpage 4. To see lines from 50 to 60 in a file. $ head -60 filename | tail 5. To look for a particular user $ who | grep mary 6. To count number of files in the /etc directory $ ls -l /etc | wc -l 7. Sort the users currently logged into the system $ who | sort 8. Create a file “ phonebook” in your home directory. Tom Smith
  • 7. 732-330-1111 Kay George 732-300-0000 Penny Smith 973-560-1234 David Korn 908-444-0987 Mary Lisa 732-666-6789 Ashwin Patel 732-786-4567 Tom Kerry 732-456-1456 9. Create another file "intro" in your home directory and type the following :(enter 4 lines as below) The UNIX operating system was pioneered by Ken Thomson and Dennis Ritchie at Bell Laboratories in the late 1960s. One of the primary goals in the design of the UNIX system was to create an environment that (UNIX)promoted efficient program development. cut command : 10. Display the current users logged in: $ who 11. Extract the first 8 characters : $ who | cut -c1-8 12. Sort the above users : $ who | cut -c1-8 | sort 13. Extract the tty number fields from the above who command : $ who | cut -c10-16 14. Display the user name and login name : $ who | cut -c1-8,18- 15. Display the file /etc/passwd on the screen.
  • 8. $ cat /etc/passwd 16. Extract the first field of the above file (This runs long on many machines like schools, free internet sites- Use CNTRL C to stop) $ cut -d: -f1 /etc/passwd 17. Extract the username and home directory ( 6th field ) : $ cut -d: -f1,6 /etc/passwd paste command: If you do not have the files users1, ssn create the files and enter the following contents. $ vi users1 Tsmith Thomson Smith 9/17/02 Betsy Betsy Williams 9/16/02 Sandia Michael Sandiago 9/17/02 Vivian Vivian Richards 9/17/02 James James Blake 8/10/02 John Dev Jhonson 9/10/02 Cramer Ron Cramer 9/17/02 Nichols Ben Nicholos 8/01/02 David David Newton 9/16/02 $ vi ssn Thomson Smith 111-22-0001 Betsy Williams 111-22-0002 Michael Sandiago 111-22-0004 Vivian Richards 111-22-0005 James Blake 111-22-0006 Dev Jhonson 111-22-0007 Ron Cramer 111-22-0008 Ben Nicholos 111-22-0009 David Newton 111-22-0010 18. First, extract the ssn into a temporary file, tempssn: $ cut -d" " -f3 ssn > tempssn 19. Now paste the ssn to the end of each line in users1 and store in a new file users_listing $ paste users1 tempssn > users_listing 20. Now see the contents of the new file.
  • 9. $ cat users_listing Another way is : $ cut -d" " -f2 ssn | paste users1 > users_listing touch command : $ touch filename -- If filename does not exit it creates with zero size,otherwise it updates the access time. 21. Let us create a new file, before that we make sure that it does not exist. $ ls filename ls: The file filename does not exist. 22. Now create a file with touch command $ touch filename $ ls -l filename -rw-r--r-- 1 stangira faculty 0 Jul 18 14:14 filename See the size of the file creatd by touch command 23. Let us update the access time of another file. $ ls -l users -rw-r--r-- 1 stangira faculty 348 Jul 17 12:23 users $ touch users $ ls -lt users -rw-r--r-- 1 stangira faculty 348 Oct 31 23:15 users Syam Tangirala University of Phoenix Online Faculty [email protected]732-397-4997(CEL)