1 / 25

Lecture 3: Utilities ( ch 3)

Lecture 3: Utilities ( ch 3). IT244 - Introduction to Linux / Unix Instructor: Bo Sheng. Outline. Special characters in Linux/Unix Basic utilities Display / copy / delete files Sort / search in files Compare files, obtain file information Pipe . Special Characters. List on Pg 50

onslow
Télécharger la présentation

Lecture 3: Utilities ( ch 3)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3: Utilities (ch 3) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

  2. Outline • Special characters in Linux/Unix • Basic utilities • Display / copy / delete files • Sort / search in files • Compare files, obtain file information • Pipe

  3. Special Characters • List on Pg50 • Avoid unnecessary use • Treat them differently

  4. Special Characters • Examples • echo hello world > hello • cat hello • echo hello * world > hello • cat hello • echo hello ~ world > hello • cat hello

  5. Special Characters • Use quote “ ” or ‘ ’ • echo “hello * world” > hello • echo hello “**” world > hello • echo ‘hello ~ world’ > hello • echo hello ‘~~’ world > hello

  6. Special Characters • Use \ • echo hello \* world > hello • echo hello \*\* world > hello • Invisible/control characters • CTRL-C, CTRL-U, … • Use CTRL-V

  7. Special Characters • Special characters in file names • Create a file “hello world” • echo HELLO WORLD > hello world • ls • cat hello • echo HELLO WORLD > “hello world” • echo HELLO WORLD > hello\ world

  8. Special Characters • List on Pg50 • Avoid unnecessary use • Treat them differently • The safe way is to use “ ” or ‘ ’

  9. Basic Utilities • Preparation • cd /home/your username/it244 • pwd(make sure of the working directory) • /home/shengbo/it244/prep

  10. Basic Utilities • List files • ls –l Size File name

  11. Basic Utilities • Display files • cat linux • more linux • less linux

  12. Basic Utilities • Display files • head linux • tail linux • head –1 linux • tail –5 linux

  13. Basic Utilities • Copy files • cp source-filedestination-file • cp linuxlinux.copy • ls • cp /home/shengbo/it244/welcome welcome • ls • more welcome

  14. Basic Utilities • Copy files • Overwriting • cp hello linux • cat linux • “-i” option • cp –i hello linux • cp linux.copylinux(restore file ‘linux’)

  15. Basic Utilities • Rename files ( mv ) • ls • mvlinux.copymylinux • ls • Overwriting • cat mylinux • cat hello • mvmylinux hello • cat hello • “-i” option

  16. Basic Utilities • Delete files ( rm ) • rm hello • Safe way of deleting (“-i” option) • echo “hello world” > hello • rm –i hello

  17. Basic Utilities • Display a file in order ( sort ) • sort linux • sort days • sort –r months • sort days months • Remove duplicate lines • cat dups • uniqdups

  18. Basic Utilities • Compare two files ( diff ) • diff –u colors.1 colors.2 colors.1 colors.2 red green yellow pink purple orange red blue green yellow orange

  19. Basic Utilities • Compare two files ( diff ) • diff –u colors.1 colors.2 • diff –y colors.1 colors.2 • diff –y colors.1 colors.2 –W 30

  20. Basic Utilities • Identify file types ( file ) • file linux • file hello • file /home/shengbo/it244/exetest • file /home/shengbo/it244/umb.jpg

  21. Basic Utilities • Word counter ( wc ) • wclinux • wc –l months • wc –w hello • Try inputting control characters in a file lines words chars

  22. Basic Utilities • Search a string in files • grep “Linux” linux • grep ‘J’ months • grep n months days

  23. Basic Utilities • Pipe (communication between commands) • command1 | command 2 • sort months | head -4 • ls | wc –w • ls | grep “color” • ls /home | more

  24. Summary • Special characters • Basic utilities • ls, cat, more, less, head, tail • cp, mv, rm(overwrite, ‘-i’) • sort, uniq, diff, file, wc, grep • | (pipe)

  25. Questions • How to display the lines in the middle of a file? For example, in file ‘months’, display from “May” to “Sep”. • uniq can only remove successive duplicate lines. How to remove all the duplicate lines in a file? e.g., display ‘Mary’ only once when operating on file ‘dups’.

More Related