Presentation is loading. Please wait.

Presentation is loading. Please wait.

RH030 Linux Computing Essentials

Similar presentations


Presentation on theme: "RH030 Linux Computing Essentials"— Presentation transcript:

1 RH030 Linux Computing Essentials
Workbook 2 Part 1 - Filesystem Basic’s RH030 Linux Computing Essentials

2 Linux+ Guide to Linux Certification, 2e
Workbook 2 covers: Basic Understanding of the FSH The Linux Directory Structure Filesystem Navigation Commands Understanding the System Directories Managing Files & Directories Displaying the contents of files & directories Understanding the types of items in directories Understanding the different types of files Using Globbing, wildcards, metacharacters Editing Files will be covered next week. Linux+ Guide to Linux Certification, 2e

3 Linux+ Guide to Linux Certification, 2e
Recall these terms: FSH or Filesystem: Manages the storage and permissions of items in a hierarchical structure called the directory tree structure and allows the user access to items within this structure by using pathnames as their addresses. Root Directory/Sub-directories: st directory at the top level of the hierarchical filesystem structure always referred to using the / character. Pathname: The address which is used to identify where an item is logically located within the hierarchal filesystem structure. Absolute pathname: This type of pathname is determined from the root directory at the top of the hierarchal filesystem structure to a certain file or directory. Relative pathname: This type of pathname is determined from your current location in the hierarchical filesystem structure to a specific file or directory. Linux+ Guide to Linux Certification, 2e

4 Linux+ Guide to Linux Certification, 2e
System Directories Table 5-1: Linux directories defined by FHS Linux+ Guide to Linux Certification, 2e

5 /etc holds the system configuration files
There are many many configuration files. Such as the file to list what shells are available. This file is used to list the available shells in the system Absolute pathname is /etc/shells Which lists the absolute pathname to the available executable files which are used to run each shell . These are all stored in /bin It is common for the name of a shell to end in *sh. So their absolute pathname’s would be: /bin/*sh Bash = /bin/bash Bourne = /bin/sh Cshell = /bin/csh Pathnames To describe a specific file or directory in the filesystem hierarchy, you must specify a "path." The path to a location can be defined as an absolute path or relative path: An absolute path of a file or directory is the complete path to it, starting at the root, which means you must include directory names. For example, the path name for the file "ch1.tex" in the directory "thesis" that is within the home directory of user zoman "/home/zoman" would be: /home/zoman/thesis/ch1.tex, (remember, the first "/" is the directory root). A relative path of a file or directory is the path to it starting from the current location. For example, if the current working directory is /home/zoman, the relative path to the file “ch1.tex” in the directory “thesis” would be thesis/ch1.tex When specifying a path, you simply trace a route through the filesystem tree, listing the sequence of directories you pass through as you go from one point to another. Each directory listed in the sequence is separated by a slash “/”. UNIX provides the shorthand notation of "." to refer to the current location, and ".." to refer to the parent directory. Because UNIX filesystem trees have no loops, the ".." notation refers unambiguously to the directory's parent.

6 Some really fundamental system configuration files – you should know.
/etc/passwd This file is used to list the attributes of the accounts in the system /etc/group This file is used to list created groups within the system /etc/shadow This file is used to store the encrypted passwords within the system /etc/shells This file is used to tell the system what shells are available to it. Pathnames To describe a specific file or directory in the filesystem hierarchy, you must specify a "path." The path to a location can be defined as an absolute path or relative path: An absolute path of a file or directory is the complete path to it, starting at the root, which means you must include directory names. For example, the path name for the file "ch1.tex" in the directory "thesis" that is within the home directory of user zoman "/home/zoman" would be: /home/zoman/thesis/ch1.tex, (remember, the first "/" is the directory root). A relative path of a file or directory is the path to it starting from the current location. For example, if the current working directory is /home/zoman, the relative path to the file “ch1.tex” in the directory “thesis” would be thesis/ch1.tex When specifying a path, you simply trace a route through the filesystem tree, listing the sequence of directories you pass through as you go from one point to another. Each directory listed in the sequence is separated by a slash “/”. UNIX provides the shorthand notation of "." to refer to the current location, and ".." to refer to the parent directory. Because UNIX filesystem trees have no loops, the ".." notation refers unambiguously to the directory's parent.

7 Sometimes System Files are hidden.
Configuration files are often hidden. Filenames that start with a . are hidden files. You can hide any file by renaming it with a . at the start. Or unhide it by removing the . Such as your local user bash startup initialization files …. ~/.bash_profile, ~/.bashrc Linux+ Guide to Linux Certification, 2e

8 Linux+ Guide to Linux Certification, 2e
Filename Extensions Files on Linux do not have to use an extension But they are often used to denote their file type When used they are similar to windows & are used as identifiers. The extension is placed after the filename following a dot (.) Text configuration files often end in .conf Such as httpd.conf Data files commonly use extensions to identify their application. Executables do not commonly use an extension. But sometimes a command can put an extension onto their output. Such as winzip does with compression. Or they are sometimes used to identify how the system uses it. Linux+ Guide to Linux Certification, 2e

9 Linux+ Guide to Linux Certification, 2e
Common Extensions Table 4-1: Common filename extensions Linux+ Guide to Linux Certification, 2e

10 In a Linux system there are many different types of files
Text files: Stores information in a readable ASCII text format Data files: Associated with a specific application program it’s specific format. Executable files: These are the Binary files which are used to run the commands and programs. Linked files: Like shortcuts a link just associates an item with another item. Well discuss these more later. Special device files: These represent the system devices within the /dev directory. Such as …. hd=ide hardrive tty=terminal Linux+ Guide to Linux Certification, 2e

11 Linux+ Guide to Linux Certification, 2e
File Command Sometimes you need to discover the origins of a file. Because Linux does not follow the same pattern as Windows with the use a extensions you sometimes have to be able to identify for yourself what type of file you are working with. This is done with the file command. file /etc/passwd file /etc/passwd /bin/ls ~/dir1/coffees/beans file ~/class-files/* file ./* Linux+ Guide to Linux Certification, 2e

12 Linux+ Guide to Linux Certification, 2e
Locating Commands whatis command: used to display what this command does display 1st line from the man pages. whereis command: Used to locate the binary, source and man pages for a command. which command: Used only for executable files Searches through the System Variable $PATH Lists directories on system where executable files are located Allows executable files to be run without specifying absolute or relative path Linux+ Guide to Linux Certification, 2e

13 Linux+ Guide to Linux Certification, 2e
Viewing Directories ls command: Most commonly used options: ls – l : detailed display or long listing of items. ll command: Is the default Alias for ls -l ls – a : displays hidden files ls – F : used to identify types of items in the directory. ls – r : list in reverse ls – R : list contents of everything – even irectories ls – ld : detailed display of actual cwd not it’s contents. Linux+ Guide to Linux Certification, 2e

14 ls –F = Display types items in a directory
Modifies the displayed listing so each item is displayed with a symbol to tell what the type of item it is: / = directory – A forward slash (/) after the name = ASCII Text File – no symbol * = Executable – asterisk (*) after the name @ = Symbolic Link – An at sign (similar to a shortcut in Windows) Linux+ Guide to Linux Certification, 2e

15 ls –l = Long Detailed Listing
Linux+ Guide to Linux Certification, 2e

16 ls –R = Recursive Listing
ls -R (recursive) command - displays the contents of all directories, subdirectories and their contents for a particular part of the directory tree If done at a high level in the directory structure, the output can be substantial! Linux+ Guide to Linux Certification, 2e

17 Globbing Wildcard Metacharacters
A metacharacter is any keyboard character that has a “special” meaning to a shell when used in a command-line. Used to simplify commands specifying multiple filenames Can be used with most Linux filesystem commands Linux+ Guide to Linux Certification, 2e

18 Linux+ Guide to Linux Certification, 2e
Using Metacharacters Asterik ‘*’ ‘*’ matches zero or more characters. Except the leading dot ‘.’ on a hidden file. Commonly referred to as a wildcard character. Using with the ls command will list all the files that match the pattern made by using ‘*’, as well as the directories and their contents that match. Question Mark ‘?’ Matches a single character. Linux+ Guide to Linux Certification, 2e

19 Linux+ Guide to Linux Certification, 2e
Using Metacharacters Square Brackets ‘[ ]’ These are called ranges If looking for a range, then the characters must be in order. [az] looks for the 2 lower case characters ‘a’ or ‘z’ inclusive [a-z] looks for any lower case character between ‘a’ and ‘z’ Case sensitive. [a-z] and [A-Z] are not the same Semicolon ‘;’ Enables typing in multiple commands on the command line without having to press “enter” in between them. Put the ‘;’ in between each command. Called the “command separator.” Linux+ Guide to Linux Certification, 2e

20 Linux+ Guide to Linux Certification, 2e
Example of use. Linux+ Guide to Linux Certification, 2e

21 Metacharacters Exercise
What does this command do? $ ls *[1-5]*p Linux+ Guide to Linux Certification, 2e

22 Displaying the contents of Text Files
There are many commands commonly used: cat head tail more less Linux+ Guide to Linux Certification, 2e

23 Linux+ Guide to Linux Certification, 2e
Cat command Really there are multiple uses for this command. Mainly used to display contents of a text file on the screen -n switch: Displays line number and contents cat /etc/passwd Concatenation: Joining text files together cat file1 file2 file3 > new-big-file Create new quick files – similar to ‘DOS copy con’ cat > new-file tac command: Displays content of files in reverse order Linux+ Guide to Linux Certification, 2e

24 Displaying the Contents of Text Files
head command: Views first 10 lines of a file by default You can also specify how many lines to show head - 6 <filename> tail command: Views last 10 lines of a file by default tail <filename> You can also specify what line number to start the display from. tail + 50 <filename> more command: Displays output page-by-page Use the Space key to go to the next page Use the Enter key to go to the next line less command: Same as more command. But can also use cursor to scroll backwards. Linux+ Guide to Linux Certification, 2e

25 Using more/less with a pipe
more and less is often used with the output from other commands If output is too large to fit on terminal screen, you would use the “|” pipe metacharacter with the more or less command. ls -l | more cat dante | more more dante Linux+ Guide to Linux Certification, 2e

26 What does this command do?
$ ls -al | head > myfiles Linux+ Guide to Linux Certification, 2e

27 Piping & Redirection Solution
$ ls -al | head > myfiles take the top ten files listed and put this part of the listing in a file called myfiles Linux+ Guide to Linux Certification, 2e

28 Working with Directories
There are many commands commonly used: mkdir rmdir rm cp mv Linux+ Guide to Linux Certification, 2e

29 Managing Files and Directories
mkdir command: Creates new directories mkdir Will make a new directory mkdir –p Will make a hierarchical pathname structure using a only a single command. mkdir –p ~/newdir1/newdir2/newdir3 rm command: Removes files only rm -r command: Removes directories +files + sub-directories etc -r recursive copy entire contents of a directory -i interactive prompts user before overwriting files -f force action overrides interactive mode rmdir command: Removes directories only if they are empty Linux+ Guide to Linux Certification, 2e

30 Managing Files and Directories
cp command: Copies files 2 arguments minimum: Source file/directory (may specify multiple sources) Target file/directory - mandatory . = cwd -r recursive copy entire contents of a directory -i interactive prompts user before overwriting files -f force action overrides interactive mode mv command: Move/Rename files or directories Used to move items Also used to rename items Same use of arguments as the cp command Linux+ Guide to Linux Certification, 2e

31 What does this command do?
$ mv ??[abc] ../.. Linux+ Guide to Linux Certification, 2e

32 Linux+ Guide to Linux Certification, 2e
solution $ mv ??[abc] ../.. move any file(s) with only three characters in the name, anything in the first two character positions, a or b or c in the third position, up two directory levels Linux+ Guide to Linux Certification, 2e

33 Workbook 2 - Command Summary
/etc /home /root /boot /var /usr /bin /sbin ls cd pwd / ~ touch whoami which exit > >> cp mv rm echo mkdir rmdir rm - r cp -r ls – F r a l s R *, ?, [a-z], [az] ranges file cat less head more Directory Navigation To gain access to particular files, you have to be able to move through directories to find them. Here are a few useful commands which will allow you to do this :- cd path Changes working directory to path. Allows you to change directory but only if you can see it in your directory listing. Example : current directory is : /home/zoman ; type $ cd thesis new location is : /home/zoman/thesis cd /path Changes working directory to /path. Allows you to change directory based on the given absolute path. Example : $ cd /etc new location is : /etc cd / This will put you into the UNIX root directory. Example: $ cd / new location is : / cd .. This will put you into the previous (parent) directory in the hierarchy. Example : current directory is : /home/zoman/thesis ; type $ cd .. new location is : /home/zoman cd This will put you into your personal home directory. Example: current directory is : / ; type $ cd


Download ppt "RH030 Linux Computing Essentials"

Similar presentations


Ads by Google