3.navigating Filesystem
3.navigating Filesystem
3.navigating Filesystem
NAVIGATING FILE
SYSTEMS
GOAL
• Copy, move, create, delete, and organize files while working from the Bash shell.
OBJECTIVES
• Describe how Linux organizes files, and the purposes of various directories in the
filesystem hierarchy.
• Specify the location of files relative to the
• current working directory and by absolute
• location, determine and change your working
• directory, and list the contents of directories.
• Create, copy, move, and remove files and directories.
• Make multiple file names reference the same file using hard links and symbolic (or
"soft") links.
• Efficiently run commands affecting many files by using pattern matching features of
the Bash shell.
LAB Managing Files from the Command Line
THE FILE-SYSTEM HIERARCHY
• All files on a Linux system are stored on file systems, which are
organized into a single inverted tree of directories, known as a file-
system hierarchy.
• The / directory is the root directory at the top of the file-system
hierarchy. The / character is also used as a directory separator in file
names. For example, if etc is a subdirectory of the / directory,
you could refer to that directory as /etc. Likewise, if the /etc directory
contained a file named issue, you could refer to that file as /etc/issue.
File types
• The following terms help to describe file-system directory
contents:
• static content remains unchanged until explicitly edited or
reconfigured.
• dynamic or variable content may be modified or appended by
active processes.
• persistent content remains after a reboot, like configuration
settings.
• runtime content is process- or system-specific content that is
deleted by a reboot.
LOCATION PURPOSE
Installed software, shared libraries, include files, and read-only program data.
Important subdirectories include:
/usr • /usr/bin: User commands.
of
/etc Configuration files specific to this system.
Variable data specific to this system that should persist between boots. Files
/var that dynamically change, such as databases, cache directories, log files,
each printer-spooled documents, and website content may be found under /var.
Location
Runtime data for processes started since the last boot. This includes process
ID files and lock files, among other things. The contents of this directory are
/run
recreated on reboot. This directory consolidates /var/run and /var/lock
from earlier versions of Red Hat Enterprise Linux.
Home directories are where regular users store their personal data and
/home
configuration files.
/root Home directory for the administrative superuser, root.
A world-writable space for temporary files. Files which have not been
accessed, changed, or modified for 10 days are deleted from this directory
/tmp automatically. Another temporary directory exists, /var/tmp, in which files
that have not been accessed, changed, or modified in more than 30 days are
deleted automatically.
WARNING
If the destination file already exists, the cp command overwrites the
file.
• If you want to copy a file to the current working directory, you can use
the special . directory:
• Use the copy command with the -r (recursive) option, to copy the
Thesis directory and its contents to the ProjectX directory.
Moving Files
• The mv command moves files from one location to another. Also for
renaming file.
• Use the mv command to rename a file.
• Use the mv command to move a file to a different directory.
Removing Files and Directories
• The rm command removes files. By default, rm will not remove
directories that contain files, unless you add the -r or --recursive
option.
• It is a good idea to verify your current working directory before
removing a file or directory
• If you want to find out whether two files are hard links of each other,
one way is to use the –i option with the ls command to list the files'
inode number. If the files are on the same file system (discussed in a
moment) and their inode numbers are the same, the files are hard
links pointing to the same data.
• Even if the original file gets deleted, the contents of the file are still available as
long as at least one hard link exists. Data is only deleted from storage when the
last hard link is deleted.