1 / 25

Unix File Organization and Basic Commands

Learn about Unix file structure, commands, permissions, and wildcards. Explore different file types, pathnames, and file manipulation techniques. Understand file permissions and how to manage them effectively.

rundell
Download Presentation

Unix File Organization and Basic Commands

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. File Basics

  2. Outline • Unix File Organization • Basic Commands • Permission • Wildcard – Filename Expansion Csc352-Summer03, Stanley Yao

  3. / usr bin dev home tmp include lib man mike joe cs352 music memo hw1.c Legend A dir A file Unix File Organization • A tree of folders and files • Directory and subdirectory • Parent and children • Root (only one) • Standard directories • Home directory • Working directory: cwd • Initial cwd for a process • Initial cwd for a shell • pwd command Csc352-Summer03, Stanley Yao

  4. File Types • Normal file: executables, text files, C source files, spreadsheets, etc. • Directory: actually is a file containing a list of (file name, file location) pairs • . • .. • Device file: /dev/tty • Link: • Hard Link • Symbolic link (soft link) Csc352-Summer03, Stanley Yao

  5. Pathname • A pathname identifies a particular file or directory uniquely • Absolute pathname • Relative pathname • Current Working directory • pwd Chaniging directory • cd • cd ~alon/352/demo • cd .. (moving up one directory) Csc352-Summer03, Stanley Yao

  6. Outline • Unix File Organization • Basic Commands • Permission • Wildcard – Filename Expansion Csc352-Summer03, Stanley Yao

  7. ls – List Files • ls • –a (show hidden files) • –l (long format) • –F (add one of the following at the end of each file name) • / - Directory • * - Executable • @ - Symbolic link • etc. Csc352-Summer03, Stanley Yao

  8. Directory Related Commands • cd • pwd • mkdir • rmdir • Must be empty • rm –rf dir_name Csc352-Summer03, Stanley Yao

  9. View Text Files • cat • cat mytext1 mytext2 mytext3 … • -n, -b • more • ENTER, SPACE • q • less: a more powerful “more” • ENTER, y • d, u • SPACE, b • q Csc352-Summer03, Stanley Yao

  10. View Text Files (cont.) • head • -number • Multiple files are separated with “==>filenames<==” • tail • +: start relative to the beginning • -: start relative to the end • -f: follow Csc352-Summer03, Stanley Yao

  11. Edit Text Files • emacs • Programming helper mode: C, HTML, TeX, Hex • Working environment: compile, email, Unix shell, time management, etc. • xemacs: version of emacs on X-win • vi • Two modes: edit & command • pico - the easiest to use. Csc352-Summer03, Stanley Yao

  12. Copy, Move, Rename and Delete • cp source_file target_file • -r • -f • mv source_file target_file • Move directory & files • Rename directory & files • rm file_list • -r, -f same as in cp Csc352-Summer03, Stanley Yao

  13. Legend A dir A file Before Talking About Links / usr bin dev home tmp lib man mike joe include Directory only consists of (filename, location) pairs. Where are filesactually stored? cs352 music memo hw1.c ActualData ofa File … Csc352-Summer03, Stanley Yao

  14. Link • Hard link • ln oldfile newlink • ln file(s) directory • Must be within the same file system • Can’t create links for a directory • Symbolic link • ln –s source mylink • Can be across file systems (e.g. NFS) • Can create links for a directory • Like the shortcut in Microsoft Windows Csc352-Summer03, Stanley Yao

  15. Search for strings in files • grep 352 tmp.dat search for the string 352 in the file tmp.dat grep –i hello *.dat would find “hello, HeLlo” in all files ending by .dat (e.g. file1.dat) Csc352-Summer03, Stanley Yao

  16. Find Files • find path [expression] • Recursively descends the directory hierarchy seeking files that match the expression(s) • -name pattern • -size [+/-]n[c] (512 bytes/block) • -atime [+/-]n and -ctime [+/-]n • -prune • -exec • !, -o, -a, () Csc352-Summer03, Stanley Yao

  17. Outline • Unix File Organization • Basic Commands • Permission • Wildcard – Filename Expansion Csc352-Summer03, Stanley Yao

  18. File Permission • Owner, Group & Others • “rwx” for files • “rwx” for directories • To access a file, you must have permission to access all the directories in the pathname. Csc352-Summer03, Stanley Yao

  19. File Permission (cont.) • Change permission: chmod • Absolutely: chmod og=rx * • Incrementally chmod +x a.out • -R • Change ownership: • chown • chgrp • -R Csc352-Summer03, Stanley Yao

  20. Outline • Unix File Organization • Basic Commands • Permission • Wildcard – Filename Expansion Csc352-Summer03, Stanley Yao

  21. Wildcard – Filename Expansion • Specify a group of files at one time by a pattern as a pathname • The shell replaces the pattern with all matching pathnames before executing the command. • Example: • ls sub* • ls sub?.c Csc352-Summer03, Stanley Yao

  22. Wildcards & Abbreviations • ?: any single character • [list]: any character in the list • [lower-upper]: any character in the range between lower and upper (inclusive) • ls a?[c-z]?.c • *: any pattern (including null) • ~: home directory Csc352-Summer03, Stanley Yao

  23. Some Issues with Wildcard • Hidden files and directories • .login, .logout • ls .l* • Report error when no matching • When requiring a single name, can’t use wildcard • cd ja* • Ambiguity • cp invoices bus* • Use “echo” to make it clear Csc352-Summer03, Stanley Yao

  24. Script files • Can create a file containing a list of shall commands (say kuku.1) • To execute the kuku.1 , do either • sourcekuku.1 • Or • chmod +x kuku.1 • kuku.1 Csc352-Summer03, Stanley Yao

  25. Acknowledgement • Stanley Yao • John H. Hartman, Classnotes for Csc352-Spring03, CS Dept., University of Arizona, 2003 • Gail Anderson, Paul Anderson, The Unix C Shell Field Guide, Prentice Hall, 1986 Csc352-Summer03, Stanley Yao

More Related