Difference between revisions of "Tutorial2: Unix / Linux File Management"

From CDOT Wiki
Jump to: navigation, search
(Part 1: Creating / Removing Directories)
(Part 1: Creating / Removing Directories)
Line 131: Line 131:
 
# Issue the following Linux command to create the directories called '''notes''', '''tutorials''' and '''examples''': <span style="color:blue;font-weight:bold">mkdir notes tutorials examples</span><br><br>
 
# Issue the following Linux command to create the directories called '''notes''', '''tutorials''' and '''examples''': <span style="color:blue;font-weight:bold">mkdir notes tutorials examples</span><br><br>
 
# Issue a Linux command to confirm that those directories have been created. You should know how to do this...<br><br>
 
# Issue a Linux command to confirm that those directories have been created. You should know how to do this...<br><br>
#
+
#This technique is considered to be inefficient... There are options and ways to create the same directory structure without using the cd command and only issue a single Linux command.<br><br>Using this old inefficient method tends to show that you are a novice or "newbie", and you may lose marks if you issue multiple Linux commands to performed tasks that can be performed using only a single Linux command.<br><br>
 +
# x
  
 
===Part 2: Navigating / Listing Directories ===
 
===Part 2: Navigating / Listing Directories ===

Revision as of 10:28, 7 January 2020

UNIX / LINUX FILE MANAGEMENT


Main Objectives of this Practice Tutorial

  • Understand the Purpose of the Unix / Linux Directory Structure.
  • List Common Directories that are Contained in a Typical Unix / Linux Filesystem
  • Use Common Unix / Linux Commands to Perform Directory Management Tasks.
  • Use Common Unix / Linux Commands to Perform Text File Management Tasks.
  • Using Text Editors to Create and Manipulate Text Files

Tutorial Reference Material

Course Notes
Linux Command/Shortcut Reference
YouTube Videos
Course Notes:Tutorials:


Directory and File Management Commands Text File Management Commands Text Editors


Brauer Instructional Videos:

Unix / Linux Directory Concepts

In Unix / Linux (as opposed to MS Windows), there are no drive letters (such as C:, or D:).

All files and directories appear under a single ancestor directory called "the root directory".

A path points to a file system location by following the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/").

The Unix/Linux file system is hierarchical, similar to other operating systems such as
Windows, Mac OSX, etc. Files are organized in directories. Directories may contain sub-directories.

In Unix / Linux (as opposed to MS Windows), there are no drive letters (such as C:, or D:). All files and directories appear under a single ancestor directory called the "root directory".

Learning how to issue Linux commands for navigating the Linux filesystem and manipulating directory and files are essential skills for Linux users and administrators.

In the Linux (Unix) OS, the "root directory" / is the starting directory, and other "child directories", "grandchild directories", etc. are created The hierarchical structure resembles an "upside- down tree". There is actually a command called tree that can display a "tree diagram"!

Pathnames

A path, the general form of the name of a file or directory, specifies a unique location in a file system. A path points to a file system location by following the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/").

Reference: https://en.wikipedia.org/wiki/Path_(computing)


The following table displays and defines commonly used directories
(listed by directory pathname) for for ALL Unix / Linux Filesystems:

Please take a few moments to review these pathnames.

Commonly used directories (listed by directory pathname)
for for ALL Unix / Linux Filesystems.
Directory PathnamePurpose
/Root directory (ancestor to all directories)
/homeUsed to store users’ home directories
/home/usernameA Particular User's Home Directory
/binCommon system binaries (commands)
/usr/binCommon utilities (commands) for users.
/usr/sbinCommon utilities for system administration
/etcSystem administration files (eg. passwd)
/varDynamic files (log and mail files)
/tmp , /var/tmpTemporary files for programs
/devDevice driver files (terminals, printers, etc.)


Every user when receiving an account has a “home” directory created (/home/userid). This is where the user keep subdirectories and personal files.

We will now learn to create and manage subdirectories within your own home directory.

INVESTIGATION 1: MANAGING DIRECTORIES


In this investigation, you will learn to manage directories including their creation, navigation, listing contents and removal.

Part 1: Creating / Removing Directories

Tree Diagram of Directory Structure to Create in your Home Directory (displayed in blue text).

Creating subdirectories within your home directory makes it more efficient to save and access files on your Linux server.

A comparison would be rooms in a house. If there were no rooms, just one large room in a 3,000 square foot house, it would be "messy" and difficult to locate items. Each room in a house is used to for a specific purpose to be more productive to perform a task such as a kitchen, bedroom, bathroom, etc.


You would like to create a directory structure within your home directory as displayed in the diagram on the right aide.


You should note from the previous section that the root directory is the
"starting point" in the Matrix file system, that the home directory is used to store all Matrix user accounts by their userid, and that your userid contained within the home directory represents YOUR home directory where you can create files (both directory files, text files, etc).


Perform the Following Steps:

  1. Login your matrix account.

  2. Issue a command to confirm you are located in your home directory. You should know how to do this from the previous tutorial.

  3. Issue the following Linux command: mkdir uli101

    NOTE: You should always confirm that you have created a directory. This can be done by issuing the ls command.

    Creating and Confirming the Creation of a Directory.
  4. Issue the following Linux command: ls uli101

    There are no contents that are contained in this newly-created directory; therefore, no contents appear. A useful option -d can be used to confirm that the actual directory has been created as opposed to viewing the contents of the directory.

  5. Issue the following Linux command: ls -d uli101

    You should now see just the directory listed. You can also combine the -d and -l options to provide more detail regarding the newly-created directory.

  6. Issue the following Linux command:ls -d -l uli101

    How can you confirm from the output of this command that the file uli101 is a directory?

  7. Issue the following Linux command:ls -ld uli101

    Is the output from this command the same was the output from the previous command? If so, what does this say about how to use multiple options for Linux commands?

  8. Issue the following Linux command to create the apc100 and xyz100 directories:mkdir apc100 xyz100

    NOTE: You should now notice that you can create multiple directories by issuing the mkdir with multiple arguments.

  9. Issue the following Linux command to confirm that those directories have been created: ls -ld apc100 xyz100

  10. We will now create the subdirectories that are contained in the uli101 directory. Issue the following Linux command to move to the uli101 directory: cd uli101

  11. Issue a command to confirm that your current location is in the uli101 directory. You should know how to issue this command from a previous tutorial.

  12. Issue the following Linux command to create the directories called notes, tutorials and examples: mkdir notes tutorials examples

  13. Issue a Linux command to confirm that those directories have been created. You should know how to do this...

  14. This technique is considered to be inefficient... There are options and ways to create the same directory structure without using the cd command and only issue a single Linux command.

    Using this old inefficient method tends to show that you are a novice or "newbie", and you may lose marks if you issue multiple Linux commands to performed tasks that can be performed using only a single Linux command.

  15. x

Part 2: Navigating / Listing Directories

x


Perform the Following Steps:

  1. x

Part 3: Copying / Moving Directories

x


Perform the Following Steps:

  1. x

Part 4: Removing Directories

x


Perform the Following Steps:

  1. x

INVESTIGATION 2: MANAGING TEXT FILES


x

Part 1: Creating Text Files

x


Perform the Following Steps:

  1. x

Part 2: Viewing / Manipulating Text Files

x

Perform the Following Steps:

  1. x


Part 3: Copying / Moving Text Files

x

Perform the Following Steps:

  1. x

Part 4: Removing Text Files

x


Perform the Following Steps:

  1. x




INVESTIGATION 3: USING TEXT EDITORS TO CREATE / MODIFY TEXT FILES


In this section, x

Part 1: Using the Nano Text Editor

x

Perform the Following Steps:

  1. x


Part 2: Using the VI / VIM Text Editor

x


Perform the following steps:

  1. x





LINUX PRACTICE QUESTIONS

The purpose of this section is to obtain extra practice to help with quizzes, your midterm, and your final exam.

Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to simulate a quiz:

https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week2_practice.docx

Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).


Review Questions:

  1. x
  2. x
  3. x
  4. x
  5. x
  6. x
  7. x
  8. x
  9. Create a table listing each Linux command, useful options that were mentioned in the online assignment #1 and command purpose for the following Linux commands: '