1 / 26

RHA030 Linux Computing Essentials

RHA030 Linux Computing Essentials. Workbook 5 The Linux Filesystem Part 2 – Chapters 5 - 7. Workbook 5. The Linux Filesystem. Last week Chapter 1. File Details Chapter 2. Hard and Soft Links Chapter 3. Directories and Device Nodes Chapter 4. Disks, Filesystems, and Mounting

reegan
Download Presentation

RHA030 Linux Computing Essentials

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. RHA030 Linux Computing Essentials Workbook 5 The Linux Filesystem Part 2 – Chapters 5 - 7

  2. Workbook 5. The Linux Filesystem Last week Chapter 1. File Details Chapter 2. Hard and Soft Links Chapter 3. Directories and Device Nodes Chapter 4. Disks, Filesystems, and Mounting This week Chapter 5. Locating Files with locate and find Chapter 6. Compressing Files: gzip and bzip2 Chapter 7. Archiving Files with tar RHA030 Linux Computing Essentials

  3. Chapter 5. Locating Files with locate and find Key Concepts • The locate command uses a database to quickly locate files on the system by pathname/itemname. • The find command performs a real time, recursive search of the filesystem. • The find command can search for files based on inode information. • The find command can perform arbitrary commands on files. RHA030 Linux Computing Essentials

  4. You can locate information about files using various commands. • Such as with whereis, which, whatis and locate, find • whatiscommand: • Display’s 1st line of the man pages • whereiscommand: • Used to locate the executable, source and man pages for a command. • which command: • Used only on executable files • Finds the directory location on the system where the executable file is located. • Then searches through the System Variable $PATH to see if this location is on it. RHA030 Linux Computing Essentials

  5. Locating the pathnames of items in FSH. • Will search for anything within the entire system FSH pathname structure • locate <item> • You can use any “text” any items which match to anything any pathnames . • Search identifies and displays all FSH pathnames which match to this text. • Uses an indexed database of all files on system - makewhatis • As the Information returned may not fit on screen it is commonly used the less / more commands RHA030 Linux Computing Essentials

  6. find command • It is one of the commands that everyone should master especially system administrators. • The first, and most obvious, use is find's ability to locate old, big, or unused files, or files that you just forgot where they are. • Automatically travels down recursively through subdirectories. 2 simple example’s of find • To lists the names of all the files in the current directory and all it’s subdirectories. find . –name ‘*’ • To list all items which have the word beans in their name find ~ –name beans RHA030 Linux Computing Essentials

  7. Syntax of the Find Command find [starting pathname] [search criteria] [filename] [action] • [starting pathname] • The first argument of the findcommandis the location from which to start the search • This pathname tells the command in which directory to start searching. • In the starting pathname you can make use of any of any of the relative symbol characters using relative addressing. • Such as ~ .. . • [search criteria] • The search criteria options after the starting pathname always start with a minus sign, and give the criteria for the actual search. • [filename] • The filename is the item or items which will be searched for. • [action] • Optional action which you want to execute on the items you find. RHA030 Linux Computing Essentials

  8. Using search criteria • You can nominate different search criteria to be used during the search find ~ -name beans OR find ~ -user sheila find ~ -type d OR find ~ -size 200k Common criteria used with find command RHA030 Linux Computing Essentials

  9. You can combine search criteria • Creating a multiple search criteria in one search. • example 1 find ~ - name “item*” - type f -group 100 • example 2 • The –not is a negative statement to tell NOT to look group 100. find ~ - name “*chapter” - type f - not -group 100 • example 3 find /etc -size +200k -type d 2>/dev/null The 2>/dev/null serves to "throw away" complaints about directories which you do not have permissions to access. RHA030 Linux Computing Essentials

  10. Using -exec to execute actions • The -exec mechanism is powerful: • It allows an action or command to be run on the items found. find /etc -size +200k -exec cp { } /tmp/big \; • Syntax rules • The command you wish to action should be written after the -exec • It uses a literal { } as a placeholder for the item name’s found. • The command is terminated with a literal ; • But as the ;has special significance to the shell, it must be "escaped" by a precending \ RHA030 Linux Computing Essentials

  11. Chapter 6. Compressing Files: gzip and bzip2 • Key Concepts • Compressing seldom used files saves disk space. • The most commonly used compression command is gzip. • The bzip2 command is newer, and provides the most efficient compression RHA030 Linux Computing Essentials

  12. Why use Compression? • Why do we use compression utilities? • Because the Internet only uses compressed files. • Files which are backed up onto another media using a backup utility are also commonly compressed to save space. • Tape devices are the default medium used for archives • Two most common compression utilities: gzip bzip2 • Many compression utilities are available for Linux systems. • Each uses a different compression algorithm • That produces a different compression ratio. RHA030 Linux Computing Essentials

  13. The gzip utility • gzip command: • A GNU utility • Most commonly utility used to compress files. • Used frequently utility for compressed files on the internet. • Adds the .gz filename extension by default • - l Used to display the level of compression achieved. • - v Used to display the level of compression achieved and display a list of the items which have been compressed. • gunzip command: • Used to decompress .gz files RHA030 Linux Computing Essentials

  14. The bzip2Utility • bzip2 command: • Adds the .bz2 filename extension by default • Not as commonly used but still used a lot on the internet. • Because it typically yields better compression than gzip. • Used to compress files only • Cannot compress a directory full of files • bunzip2 command: • Used to decompress files compressed via bzip2 RHA030 Linux Computing Essentials

  15. Seeing how compression works List the file to see the original size $ ls -l bin.file -rw-r--r-- 1 user2 staff 57380 Mar 22 09:17 bin.file Compress the file $ gzip -v bin.file bin.file: compression: 53.81% -- replaced with bin.file.gz List the file to see compressed size $ ls -l bin.file.gz -rw-r--r-- 1 user2 staff 26500 Mar 22 09:17 bin.file.gz Uncompress the file and list again $ gunzip bin.file.gz bin.file.gz: -- replaced with bin.file $ ls -l bin.file -rw-r--r-- 1 user2 staff 57380 Mar 22 09:17 bin.file RHA030 Linux Computing Essentials

  16. Chapter 7. Archiving Files with tar Key Concepts • Archiving files allows an entire directory structure to be stored as a single file. • Archives are created, listed, and extracted with the tar command. • Archive files are often compressed as well. • The fileroller application provides a GUI interface to archiving files. RHA030 Linux Computing Essentials

  17. tar archive files (tarballs) • The tar( “Tape Archive” ) command • It makes a single file out of the input files • An archive file is created or backed up for extraction later. • Used extensively for files on the internet • These compressed archived files are called tarballs. • You should always add a .tarfilename extension to identify it as a tarfile. • Files are not automatically compressed as they are archived. • But adding a – zwill compresses them with gzip. • It adds the .tar.gzfilename extension or .tgz filename extension RHA030 Linux Computing Essentials

  18. The tar utility - mandatory options • The tar syntax • tar function modifier destination.tar sourcefiles RHA030 Linux Computing Essentials

  19. You use – f to modify the default • Remember it is called The tar ( Tape Archive) utility • It defaults to the tapedrive • BUT You can create archive file’s onto any device. • MOST commonly we had the “ f ‘ option as it tells the system to work with a file on the harddrive instead. Table 12-4: Common tape device files RHA030 Linux Computing Essentials

  20. Example 1 1. archive a file $ tar cvf dir1files.tar dir1 2. list contents $ tar tvf dir1files.tar 3. remove dir1 and verify $ rm -r dir1 $ ls 4. extract the archived dir1 to your current directory $ tar xvf dir1files.tar RHA030 Linux Computing Essentials

  21. Example 2 1. compress & archive a file $ tar cvfz dir1files.tar dir1 2. list contents $ tar tvfz dir1files.tar 3. remove dir1 and verify $ rm -r dir1 $ ls 4. extract the archived dir1 to your current directory $ tar xvfz dir1files.tar RHA030 Linux Computing Essentials

  22. Many other options also available Table 12-5: Common options used with the tar utility RHA030 Linux Computing Essentials

  23. Establishing Context • The -C switch is be used to help establish context (location) of the items to be put into the archive file. • This just means the “relative pathname that you wish to use” • Used when you picking up these outside your cwd. [prince@station prince]$ tar cvf net.tar -C /etc/sysconfig networking RHA030 Linux Computing Essentials

  24. Maintaining Pathnames & Context • By default it always stores items using a relative pathname. • Adding a ”big” Pmakes it use an absolute pathname • It just stops it striping the leading “/” from the pathname. tar cvfP net.tar /etc/sysconfig/networking RHA030 Linux Computing Essentials

  25. Maintaining Ownership & Permissions • By default it always will change the ownership & associated group to that of whoever runs the tar command • And reset the items back to the system default permissions. • Using little pstops this. • Now it will keep existing ownership and group attributes • And stop’s it striping the ACL’s so it ignores umask • So it keeps the existing permissions tar cvfp net.tar /etc/sysconfig/networking RHA030 Linux Computing Essentials

  26. Now do these exercises 1. RHA Workbook 5 – online exercises – chapter 5 2. Handout - Understanding the find command 3. RHA Workbook 5 – online exercises - chapter s 6 - 7 4. Handout - Using the tar command & compression 5. Putting it All Together 4 - Find and Permissions RHA030 Linux Computing Essentials

More Related