Presentation is loading. Please wait.

Presentation is loading. Please wait.

Workbook 5 - Part 2 The Linux Filesystem RH030 Linux Computing Essentials.

Similar presentations


Presentation on theme: "Workbook 5 - Part 2 The Linux Filesystem RH030 Linux Computing Essentials."— Presentation transcript:

1 Workbook 5 - Part 2 The Linux Filesystem RH030 Linux Computing Essentials

2 Linux+ Guide to Linux Certification, 2e 2 Objectives chapter 1 - 5 Last week we looked at: How the linux filesystem works  Filesystem structures dentries, inodes, data blocks  ls -i  ls –s  Linking items – hard & soft links  ln  ln –s  Recognising the types of items found in the filesystem regular files, directories, and symbolic links. block and character device nodes.  mount  df

3 Linux+ Guide to Linux Certification, 2e 3 Objectives chapter 5 - 7  THIS WEEK  Searching for files and directories  Compressing Items  Archiving Items

4 Linux+ Guide to Linux Certification, 2e 4 Command Covered  Review - locating information about files and directories whereis, which, whatis,  Searching for files and directories locate, find  Compressing Items gzip bzip2  Archiving Items tar

5 Linux+ Guide to Linux Certification, 2e 5 Files and Directories You can locate information about files using various commands.  Such as locate, whereis, which, whatis and find which command:  Used only on executable files  Lists the directory location on the system where the executable file is located.  Searches through the System Variable $PATH to see if this location is on it.  $PATH allows executable files to be run without specifying absolute or relative path whereis command:  Used to locate the binary, source and man pages for a command. whatis command:  Display’s 1 st line of the man pages

6 Linux+ Guide to Linux Certification, 2e 6 Locating the pathnames of items in FSH. You can use any “text” to display any items which match to anything on any of the systems pathnames. locate :  Will search for anything within the system FSH pathname structure Search identifies and displays all FSH pathnames which match to the text. Shortcut to the slocate command Uses an indexed database of all files on system As the Information returned may not fit on screen it is commonly used the less / more commonds

7 Linux+ Guide to Linux Certification, 2e 7 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.  The other important characteristic is find's ability to automatically travel recursively down through subdirectories.  There are only a few unix commands which can be given a directory name and will automatically search down the directory pathname tree structure, searching each subdirectories. The commands chmod, chgrp, rm, ls and cp will do it as well. But only if the -r or -R option is specified. But the find command does this automatically.

8 Linux+ Guide to Linux Certification, 2e 8 Syntax of the ‘Find Command’ find [starting pathname] [search criteria] [filename] [action] [starting pathname]  The first argument of the find command is 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.

9 Linux+ Guide to Linux Certification, 2e 9 Using search criteria You can nominate different search criteria to be used during the search  Such as can use the find command with “ –name “ to create a search which will list all files which start with the word chapter*. find ~ -name “chapter*?” OR find ~ -type d “bean??” Common criteria used with find command

10 Linux+ Guide to Linux Certification, 2e 10 Combining search criteria Creating multiple search criteria in one search. example 1  1 st – it searchs for items that end in name = “*chapter”  2 nd – further filters the search to find only files NOT directories find ~ - name “*chapter” - 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 The 2>/dev/null serves to "throw away" complaints about directories which you do not have permissions to access. find /etc -size +200k 2>/dev/null

11 Linux+ Guide to Linux Certification, 2e 11 Examples A simple example of find is using it to list the names of all of the files in the nominated directory and all it’s subdirectories. This is done with the simple command find. –name ‘*’ find ~ -name beans find ~ -name “bean??” find /usr/local -name share -type d find /etc -name fstab -type f find /home –type d –user root find. -name “*backups” -type d -user 504 find ~ -name “*chapter” -type f -group 100

12 Linux+ Guide to Linux Certification, 2e 12 Using -exec to execute actions -exec, and its close cousin -ok.  The -exec mechanism is powerful: rather than just printing the names of matching files, secondary commands can be run.  But using the -exec is awkward because the syntax for specifying the command to run is tricky. Syntax rules  The secondary command should be written after the -exec switch,  using a literal { } as a placeholder for the file name.  The command should be terminated with a literal ;  But as the ; has special significance to the shell, it must be "escaped" by a precending \. An example will help clarify the syntax. find /etc -size +200k -exec cp { } /tmp/big \;

13 Linux+ Guide to Linux Certification, 2e 13 SUMMARY OF SEARCH / LOCATE COMMANDS locate command: Searches FSH pathname structure for anything which matchs. whatis command: Display’s 1 st line of the man pages whereis command: Used to locate the binary, source & man pages for a command. which command:  Used only on executable files  Lists the directory location on the system where the executable file is located.  Searches through the System Variable $PATH to see if this location is on it.  $PATH allows executable files to be run without specifying absolute or relative path find command:  Used to locate particular items.  Able to modify searchs with use of selected criteria.  Able to recursively search thru nominated sections of FSH  Able to execute an action on located items.

14 Linux+ Guide to Linux Certification, 2e 14 Next Chapter 6 Understanding compressed files  Creating compressed files  Viewing compressed files  Extracting compress files Chapter 7 Working with archived or backup files  Creating backup files  Viewing backup files  Extracting backup files

15 Linux+ Guide to Linux Certification, 2e 15 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.

16 Linux+ Guide to Linux Certification, 2e 16 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

17 Linux+ Guide to Linux Certification, 2e 17 The bzip2 Utility bzip2 command: Adds the.bz2 filename extension by default Not as commonly used but still used a lot on the internet. Because it t ypically 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

18 Linux+ Guide to Linux Certification, 2e 18 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 -l 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 -l 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

19 Linux+ Guide to Linux Certification, 2e 19 Archiving files to create System Backups Backups:  The Process whereby files are copied to an archive file.  The actual backup copies of directories & files are called archives.  Typically created by a backup utility. Performing System Backups:  You should always backup any important system configuration files.  Plus the user files from their home directories.  Also possibly files used by system services, as well. Media:  They can be created on various media.  They can be created in various locations.  Default media has been tape.  But most popular media now is hardrives, CD’s & DVD’s Several backup utilities available:  tar, cpio, dump/restore, burning software

20 Linux+ Guide to Linux Certification, 2e 20 tar archive files (tarballs) The tar ( “Tape Archive” ) command It is still one of the oldest & most commonly used backup utilities. It allows for the backing up of multiple files or directories in the file system. It makes a single archive file out of the input files it backed up for extraction later. Used extensively for files on the internet  These compressed archived files are called tarballs.  You should always add a.tar filename extension to identify it as a tarfile.  Files are not automatically compressed as they are archived.  Adding a – z will compresses them with gzip.  It adds the.tar.gz filename extension or.tgz filename extension

21 Linux+ Guide to Linux Certification, 2e 21 The tar utility options The tar syntax tar function modifier destination.tar sourcefiles

22 Linux+ Guide to Linux Certification, 2e 22 Maintaining Context By default it always will change the ownership to who ever runs the command and reset the items with default permissions. Using – p stops this. It will keep existing ownership and group attributes And stop it striping the ACL’s so it ignores umask and keeps the existing permissions tar cvfp net.tar /etc/sysconfig/networking Maintaining Pathnames By default it always stores items using a relative pathname. Using – P stops this. It stop it striping the leading “/” from the existing pathname. tar cvfP net.tar /etc/sysconfig/networking

23 Linux+ Guide to Linux Certification, 2e 23 Maintaining Pathnames & Context By default it always stores items using a relative pathname. Adding a – P stops this. Sit sop it striping the leading “/” from the pathname. tar cvfP net.tar /etc/sysconfig/networking Establishing Context.  the -C switch can also be used to help establish or maintain context of multiple items in the filesystem. By changing directory before the archive is constructed. tar cvf net.tar -C /etc/sysconfig file1 file 2 -C /var/logs file 1 file 2

24 Linux+ Guide to Linux Certification, 2e 24 The tar ( Tape Archive) utility Can create archive in a file on a filesystem or directly onto a device. Defaults to tapedrive unless told to output to file onto a harddrive.  You use – f to modify this default and use another device such as the hardrive. Table 12-4: Common tape device files

25 Linux+ Guide to Linux Certification, 2e 25 Options used with the tar utility Table 12-5: Common options used with the tar utility

26 Linux+ Guide to Linux Certification, 2e 26 Options used with the tar utility Table 12-5 (continued): Common options used with the tar utility

27 Linux+ Guide to Linux Certification, 2e 27 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 Example 1

28 Linux+ Guide to Linux Certification, 2e 28 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 Example 2

29 Linux+ Guide to Linux Certification, 2e 29 Workbook5 - Command Summary ls – n –i –s stats ln –s mount umount mkfs df locate, which, whereis, whatis find gzip bzip2 tar


Download ppt "Workbook 5 - Part 2 The Linux Filesystem RH030 Linux Computing Essentials."

Similar presentations


Ads by Google