Tải bản đầy đủ

linux crash course chapter 04 2

Chapter 4:
The Linux Filesystem
Where stuff is

In this chapter …

What is a hierarchical filesystem
Directories and files
Pathnames: absolute vs. relative

What is a filesystem?

A data structure
Stores data
Organizes data
Allows for data retrieval and manipulation

What is a hierarchical filesystem?
• Essentially, a filesystem that allows nesting
of folders under a central point
• Like a pyramid or upside-down tree
• Tree analogy most common – ie the directory
• Programmers – definition of a tree applies

Hierarchical Filesystem
• Directories can contain other directories
and/or ordinary files
• Concept different from reality – in
implementation everything is a file
• Directories, devices, named pipes, ordinary
files – all really just files

• Root directory
• Subdirectories
• Parents, children

• Each file within a directory must have a
wholly unique filename
• Can be up to 255 characters – make them
longer to avoid confusion

• Special characters must either be escaped
out (using backslash) or in quotes
• Only illegal characters are / and carriage

Filenames con’t
• Spaces and other special characters a bad
• Instead of spaces use underscores or
– Ex: my_file or my.file

• Not always essential but helps simplify and
avoid confusion
• Some programs like gcc depend on proper
• This includes case!

Hidden Files
• To make a file hidden, start it with a period
– Ex .plan

• A normal ls will not show hidden files
• Use ls –a to reveal ALL files
• Startup files, containing configuration
settings for your account, hidden

mkdir – create directory
• Syntax: mkdir directory
• Directory can be a relative or absolute
pathname (we’ll get to that in a minute)
• You can use ls –F to show directories with a
forward slash at the end of the name
• If using a color terminal, directories will be a
different color than ordinary files

Working Directory
• The directory you are currently working in
• pwd will tell you what your working directory
• Helpful to know when using relative
pathnames (again, coming up)

Home Directory
• Not to be confused with working directory
• The directory you start in when you first
• Most users it is /home/username
• For root, it is /root
• Can be changed by system administrator

cd – change working directory
• Syntax: cd [directory]
• Again, directory can be absolute or relative
• If no argument given, changes working
directory back to your home directory

Absolute Pathnames (finally)
• Absolute pathname for a file gives the file’s
location relative to the root of the filesystem
• Sometimes long
• Ex: /home/jhowell/Assignment1/animals
• Shortcut: ~ represents your home directory
• So the above could also be

Relative Pathanmes
• A pathname relative to the current working
• Make sure you know what your working
directory is!
• Shorter
• Ex, in my home directory:

. and .. Directories
• . is an alias for the working directory
• .. is an alias for the parent of the current
working directory
• These pointers are placed in every directory
when created by mkdir
• Can be used in relative pathnames

Standard Filesystem Directories
• Most distributions try to adhere to the
Filesystem Hierarchy Standards, but it’s not
uncommon to find things in odd places
• Even less standardized going from Linux to
• In other words – no guarantees

Common Directories

/ (root) – root of the filesystem
/bin – essential system binaries (commands)
/boot – files for the bootloader
/dev – device files
/etc – system configuration files
/home – user home directories
/lib – standard libraries and modules

Common con’t
• /mnt – mount point for temporary filesystems
(floppies, CD-ROMs, non-native partitions)
• /opt – optional add-on software
• /proc – kernel and process information
• /root – root’s home directory
• /sbin – essential system binaries
• /tmp – temporary space (not swap)

Common con’t
• /usr – common area for data / program users
use frequently
• /var – frequently changing data like system
logs, caches, spools and mailboxes
• Lots more important subdirectories – see the

rmdir – remove directory
• Syntax rmdir directory
• Only deletes empty directories
• Not empty? Delete the files with rm and try
rmdir again
• Lazy? rm –r directory will recursively delete
a directory and its contents (files and
• Use with caution!

touch – create a file
• Syntax: touch filename
• Creates an empty file (size 0)
• Useful to create placeholders or while
learning the interface

mv revisited
• Already used mv to rename files
• If last argument is a directory, mv moves files
into a different directory
• If given a directory as the first argument, mv
moves the directory to the new name
supplied (which can either be a rename or

• Use a ls –l (for long view) and you might see
something like this:

2 jhowell jhowell 4096 Aug 18 15:46 Desktop
1 jhowell jhowell
0 Sep 4 18:08 myfile
2 jhowell jhowell 4096 Aug 22 15:32 public_html
# of

of file




Date and time
created / accessed

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay