0% found this document useful (0 votes)
32 views21 pages

1.1the File System-Class RIT

RIT Class 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views21 pages

1.1the File System-Class RIT

RIT Class 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

GCIS-123

Software Development & Problem Solving


Unit 1.1: File System
Basics
Windows 10 ● The goal of this week’s lectures is to
establish a common, minimum level of
Computer Literacy computer literacy among the students in the
class.
● We will explore:
○ The Command Line ⮜
○ The File System ⮜
○ Version Control (with Git)
○ Environment Variables
○ More Advanced Git
● You will learn to perform many tasks using
only the command line.
○ After a short time, you will find using the
command line to be much faster and more
efficient than trying to use a graphical user
If you’d like to use a non-Windows computer for interface like the File Explorer for many tasks.
your out of class work, you will need to do some ● Please note that throughout this series of
extra learning on your own. lectures (and the entire course) we will be
using the Windows 10 operating system.
Many of the commands you will use work much ○ If your personal computer has a different
the same in Linux or Mac OS. Others you may operating system, some of the examples will
easily Google. not work.
2
○ It is therefore recommended that you use one
1.1.0 Logging In
Even if you plan to use your own computer, take a minute to log into
the lab computer in front of you to make sure that you can access it if
needed.

● Depending on the lab in which your class meets, you may


be required to authenticate using an account specific to the
lab's domain.
○ If this is the case, you should have received an email with your
username and instructions for setting a password.
○ Using your phone or laptop, follow the instructions to reset your
password.
○ Once you have completed the process, you should be able to
use the username and password to log into the computer in
front of you.
● It is also possible that you don't need a special account to
log into the lab computers.
○ Ask your instructor!
3
● Every major operating system includes
support for a command prompt.
○ The command prompt is often called a The Command Prompt
“terminal” or “command line interface” (CLI).
○ Some operating systems only include a
command prompt!
● Many features of the operating system can
be quickly and efficiently executed via the
command prompt, including:
○ Running programs.
○ Opening files.
○ Creating or editing text files.
○ Copying, moving, or deleting files.
○ Creating or deleting directories.
○ etc.
● Starting the command prompt is easy:
○ Press the Windows key on your keyboard to
open the Start Menu.
○ Type “powershell” into the search field.
○ If necessary, use the up and down arrow keys
to select Windows PowerShell in the search
results.
4 ○ Press the enter key.
Customizing the Command Prompt
1.1.1
Start by customizing it to your preferred look and feel.

Right-click the window’s title bar and select You’ll be using the command prompt
the Properties menu option. Play around a lot, so go ahead and pin it to your
with customizing font color & size, layout, and taskbar (right click the icon and select
so on. Pin to taskbar).

Close and re-open the command


prompt using the button on the
If you haven’t already done so, use taskbar to make sure that your
the Windows key to open the start settings were saved.
menu and run the command prompt.

5
The File System
● The File System on your computer is
organized into a tree structure. Your PC is
at the root of the tree.
● Your PC contains one or more drives.
○ Most contemporary computers use some
combination of internal solid state drives
(SSDs) and removable drives (e.g. USB or
SATA).
● Each drive has a root directory.
○ Directories are often also called folders.
● While a directory may be empty, most
contain some combination of
● subdirectories
Each subdirectory and files.a directory, and
is itself
so may also contain its own files and
subdirectories.
● In fact, directories may be nested to an
arbitrary depth. 6
1.1.2 Listing Drives
Executing the gdr command from the command line on your
computer will list all of the available drives.

PS C:\Users\charlie> gdr And the root directory


Name Used (GB) Free (GB) Provider on each drive is shown on
the right.
Root
---- --------- --------- --------
The drive letters will be ----
listed on the left (along Alias Alias
with some other stuff)... C 312.36 640.88 FileSystem
C:\
D 2746.24 48.28 FileSystem
D:\
E 0.28 0.06 FileSystem
E:\
F 464.75 11.40 FileSystem
The used and available
F:\ storage on each drive is
Z 784.97
shown 168.90
(in gigabytes). FileSystem
Z:\ 7
File Paths ● Every drive in your PC is identified by a
Consider the file named “Fantastico.txt” depicted drive letter, e.g. C, D, or Z.
below. It is in a directory named “Kitty”, which is in a ○ A removable drive (e.g. a USB flash
directory named “Miss” in the root directory on drive “W”.
drive) will be automatically assigned an
unused letter.
● You may switch between drives on your
Kitty computer
Fantastico.txt
(a file) e.g. C:
○ Case does not matter.
Miss
● Every file or directory in your file
system is uniquely identified by its
\
absolute path.
○ The path begins with the letter of the
W: drive on which the file resides.
○ It includes the name of each directory
and subdirectory.
○ It ends with the name of the file.
absolute path to the file Fantastico.txt ○ The names of directories and files are
separated by a file separator, e.g. '\'.
W:\Miss\Kitty\Fantastico.txt 8
Navigating the File
● You may also move from one drive to
another by typing the drive letter followed System
by a colon, e.g. C:, W:, etc.
○ This will move your command prompt into Kitty
the last directory you used on the drive, or
the root directory if you have not used the
cd .. cd Kitty
drive yet.
● Once on a drive, you may change from cd W:\Miss\
Kitty
one directory to another using the cd cd \ Miss
command.
○ When used with the name of a
subdirectory, cd will move into that cd .. cd Miss
directory, e.g. cd Kitty
cd W:\
○ cd \ will move to the root directory on the Miss
current drive. W:\
○ cd .. will move up one directory (e.g. from
a subdirectory into its parent directory).
cd W:\

Consider the directory structure from the previous


example: W:\Miss\Kitty\ Anywhere on
your PC
9
Listing Files

● Once you are in a directory, you can use PS C:\users\charlie\Downloads> ls


the ls command to list the files in the Directory: C:\users\charlie\Downloads
directory. Mode LastWriteTime Length Name
---- ------------- ------ ----
● The
○ listing
“ls” isprovides a lot of detailed
short for “list.”
d----- 4/2/2020 8:33 PM nightmare_hero
information about the contents of the d----- 5/12/2020 8:36 AM hello-world
directory. --r--- 5/22/2020 10:57 AM 352609 The File
○ The mode indicates details about the System.pdf
attributes of each file. -a---- 5/22/2020 9:20 AM 241580 More Git.pdf
■ d indicates that it is a directory. -ar--- 5/16/2020 9:26 AM 1353127 batman-logo.png
-a---- 5/12/2020 1:57 PM 198109216 AtomSetup-x64.exe
■ a indicates that the file has been
-a---- 5/22/2020 1:08 PM 46891904 Git-2.26.2-64-
archived (backed up) since the last
bit.exe
update. -a---- 5/12/2020 1:54 PM 24 hello.py
■ r indicates that the file is read only. -a---- 5/12/2020 2:34 PM 204 hw02.py
○ The last write time is the last time that the -a---- 5/20/2020 12:25 PM 2138 set.txt
file was updated.
○ The length is the number of bytes of data in
the file. PS C:\users\charlie\Downloads> _ 10
○ The name is, well, the name.
1.1.3

Changing Directories
Practice using the cd command to change drives or
directories, and the ls command to list files in a directory.

● Navigate each of the directories below and list the files inside of each.
Hint: you can type the first few letters in the name of the directory and press
the TAB key to autocomplete, e.g. cd Doc → cd .\Documents\
○ Your user directory, e.g. C:\Users\George
○ Documents (in your user directory)
○ Downloads (in your user directory)
○ Pictures (in your user directory)
○ C:\Program Files
○ C:\Program Files (x86)
11
● Files are used to store data such as text,
File Types images, video, or executable
applications.
● The file type is usually indicated using a
file extension - the last part of the
filename after a dot (.).
○ For legacy purposes, most file extensions
are three letters.
● Some examples of file extensions
Extension File Type
include:
txt A text file, containing only characters

pdf Portable Document Format

png, gif, jpg Image files


Notepad is the default text editor for the Windows
operating system and it can be used to create and zip A ZIP compressed archive
edit text files.
py A Python program (or script)
You can run Notepad from the command prompt
html, htm A Hypertext Markup Language file
followed by the name of the file that you want to
create or edit.
C:\users\charlie> notepad ● Files highlighted in yellow use
atotc.txt different/special file extensions, but are 12
1.1.4

Creating Text Files


Lets practice by using Notepad to create, save, and then
reopen a text file.

● Launch a new command prompt.


● Navigate to the Documents directory.
● Use notepad to create a file named “hello.txt”.
○ When prompted, choose to create the file.
● Add a few lines of text to your file, save it (shortcut: CTRL-S), and
exit (shortcut ALT-F to open the File menu and X to exit) Notepad.
● Use ls to verify that your file has been created.
● Use notepad again to open your file and see the text.
● Close the command prompt.
13
● The cp command can be used to create a
Copying Files
copy of a file. It requires at least one
argument: source.
○ For example, cp C:\story.txt will copy the
file with the specified path into the current
directory; the copy will be named PS C:\Users\charlie> cp atotc.txt dickens.txt
PS C:\Users\charlie> ls
story.txt.
● An optional second argument can be used Directory: C:\users\charlie
to specify the name (or path) of the copy.
Mode LastWriteTime Length Name
○ For example cp story.txt tale.txt will
---- ------------- ------ ----
create a copy of the file story.txt in the -a---- 5/23/2020 10:54 AM 52 atotc.txt
current directory; the copy will be named -a---- 5/23/2020 10:54 AM 52 dickens.txt
tale.txt.
C:\Users\charlie> cp atotc.txt
● A directory cannot contain two files with
cp : Cannot overwrite the item C:\users\charlie\
exactly the same name; trying to copy a atotc.txt with itself.
file into a directory that already has a file
PS C:\Users\charlie> cp C:\afile.txt here.txt
with that name will cause an error. PS C:\Users\charlie> cp here.txt Documents\
there.txt
If everything goes well, the cp command is silent (it will
14 not produce any output). Use ls to see your copy.
1.1.5

Copying Files
Practice using the cp command to make two copies of
the same file.

● Launch a new command prompt.


● Navigate to the Documents directory.
● Use cp to create two copies of your “hello.txt” file.
○ Name them whatever you’d like.
● Use Notepad to edit and change the contents of the files.
○ Don’t forget to save (CTRL-S)!
● When you are finished, close the command prompt.

15
Making Directories
The mkdir command allows you to create new
directories anywhere in the file system. ● The mkdir command can be used to make a
C:\> mkdir W:\Miss\Kitty\Witty\ new directory with a specified name in the
Lovebuns current directory.
○ For example, assuming that you are in the
...new directories are Lovebuns
created here... directory with the path C:\Users\charlie,
then the command mkdir Weasley will make
Witt a subdirectory named “Weasley”.
y ○ The full path to the new directory would be
Kitt C:\Users\charlie\Weasley
y ● You may also create the same directory from
The command anywhere in the file system using an
Miss prompt is here...
absolute path.
\ \ ○ mkdir C:\Users\charlie\Weasley

W: C:

16
Moving Files
● The mv command will let you do exactly
that.
● Like cp, mv can be used with at least one
argument: the path to the file to move.
○ For example, mv C:\story.txt will move
the file named story.txt from C:\ to the
current directory.
● An optional second argument can be used
A file that is moved is not necessarily physically moved
to specify the name (or path) of the
from one location to another on the storage media.
destination.
○ For example mv C:\story.txt W:\
tale.txt will move the file story.txt from It is more often the case that the alias used to refer to the
C:\ to W:\ and rename it to tale.txt at the file’s location is changed from one name to another.
same time.
○ The mv command can also be used to
rename files in place, e.g. mv old.txt Conversely, your operating system may physically move a
new.txt will change the name of the file file from one place to another without changing its name.
“old.txt” to “new.txt” in the current
directory.
17
Relative Paths
● So far we have referred to files either by Consider the file depicted below with the absolute path
name or by using the absolute path to the W:\Miss\Kitty\Witty\Lovebuns\Esquire.txt
What is the relative path from each directory?
file.
● Files may also be referenced using a Esquire.txt
(a file)
relative path, that is a path relative to
the current directory; it specifies how to get
Lovebuns .\Esquire.txt
there from here.
● For example, consider the file named Witt .\Lovebuns\
y Esquire.txt
Esquire.txt that is depicted to the right. ..\..\..
○ The relative path to the file from the Kitty Kitt .\Witty\Lovebuns\

directory is: .\Witty\Lovebuns\ y Esquire.txt

.\Kitty\Witty\Lovebuns\
Esquire.txt. Miss Esquire.txt
○ Note that the dot (.) is a shortcut to refer to
.\Miss\Kitty\Witty\Lovebuns\
the current directory. \ Esquire.txt

● A relative path may include both . and ..


(to refer to a parent directory), e.g. the W:

path to Miss from Witty would be ..\.. Remember: .. can be used to create paths that move
18 (the parent of its parent). in the opposite direction.
1.1.6
Making Directories and
Moving Files
Practice using mkdir to make directories and mv to
Document SoftDev move files between directories.
s I
Harry
● Launch a new command prompt.
Users ● Create a new directory structure under your user directory with
the relative path SoftDev1\Unit01\Day01
\ ○ e.g. C:\Users\Harry\SoftDevI\Unit01\Day01
● Move all 3 of the text files that you created previously into the
C: new directory.
○ e.g. mv .\Documents\hello.txt .\SoftDevI\Unit01\Day01

19
Wildcards & Deleting Files
● A wildcard (*) can be used to find multiple
files with names that match a certain pattern,
e.g.:
○ *.txt matches all files with a .txt extension.
○ hel* matches all files with names that begin with
“hel” such as “hello.txt” or “help.png”.
○ *if* matches all files with “if” anywhere in the
name such as “if_only.txt”, “riff.jpg”, or
“tears.gif”.
○ And so on.
● Wildcards can be used in combination with
commands such as ls. You may be used to being able to recover deleted files, but
○ e.g. ls *.txt will list all of the text files in the files deleted from the command line line are not moved to
current directory. the Recycle Bin!

● The rm command can be used to delete a file That means that you should use caution when using the
by name, e.g. rm hello.txt rm command to delete anything, especially when using a
● Wildcards can be used with rm, and so rm wildcard (*)!
*.txt will delete all of the files with a .txt 20
extension in the current directory.
1.1.7

Deleting Files

● Launch a new command prompt.


○ If necessary, navigate to your user directory.
● Delete two of the text files in your Day01 folder.
○ Challenge: can you use a relative path and a wildcard (*) to delete
both files from your user directory without deleting the third?
● List the files in the directory to verify that your files have been
deleted.
Remember! Deleting files from
the command prompt deletes
them permanently! Be careful!
21

You might also like