1.1the File System-Class RIT
1.1the File System-Class RIT
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).
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.
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
Copying Files
Practice using the cp command to make two copies of
the same file.
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\
.\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
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