Absolute Paths and Relative Paths
The path of a file or directory specifies its unique file system location.
Following a file path traverses one or more named subdirectories, delimited by a
forward slash (
When a user logs in and opens a command window, the initial location is normally the user's home directory. System processes also have an initial directory. Users and processes navigate to other directories as needed; the terms working directory or current working directory refer to their current location.
For standard Linux file systems, the path name of a file, including all
Linux file systems—including, but not limited to, ext4, XFS, BTRFS, GFS2, and GlusterFS—are case-sensitive. Creating
The touch command normally updates a file's timestamp to the current date and time without otherwise modifying it. This is useful for creating empty files, which can be used for practice, since "touching" a file name that does not exist causes the file to be created. Using touch, practice files are created in the
To protect file contents from improper viewing requires the use of file permissions.
/
), until the destination is reached.
Standard file behavior definitions apply to directories (also called
folders) the same as other file types.
The common file browser view (left) is equivalent to the top-down view (right)
Important
Although a Space is an acceptable character in Linux file names, a space is the delimiter used by the command shell for command syntax interpretation. New administrators are advised to avoid using spaces in file names, since file names that include spaces frequently result in undesired command execution behavior.Absolute Paths
An absolute path is a fully qualified name, beginning at the root (/
) directory and specifying each subdirectory
traversed to reach and uniquely represent a single file. Every file in a
file system has a unique absolute path name, recognized with a simple rule:
A path name with a forward slash (/
) as the first character
is an absolute path name. For example, the absolute path name for the system message log file is
/var/log/messages
. Absolute path names can be long to type,
so files may also be located relatively.
When a user logs in and opens a command window, the initial location is normally the user's home directory. System processes also have an initial directory. Users and processes navigate to other directories as needed; the terms working directory or current working directory refer to their current location.
Relative Paths
Like an absolute path, a relative path identifies a unique file, specifying only the path necessary to reach the file from the working directory. Recognizing relative path names follows a simple rule: A path name with anything other than a forward slash (/
) as a first character is a relative path name.
A user in the /var
directory could refer to the
message log file relatively as log/messages
.
For standard Linux file systems, the path name of a file, including all
/
characters, may be no more than 4095 bytes long.
Each component of the path name separated by /
characters may be no more than 255 bytes long. File names can use any
UTF-8 encoded Unicode character except /
and the
NUL
character. (ASCII characters require one byte; other
Latin, Greek, Hebrew, or Cyrillic characters take two bytes; remaining
characters in the Unicode Basic Multilingual Plane take three; and no
character will take more than four bytes.)
Linux file systems—including, but not limited to, ext4, XFS, BTRFS, GFS2, and GlusterFS—are case-sensitive. Creating
FileCase.txt
and filecase.txt
in the same directory results in two unique files.
Although many non-Linux file systems are supported in Linux, each has unique file naming rules.
For example, the ubiquitous VFAT file system is not case-sensitive
and allows only one of the two example files to be created.
However, VFAT, along with Microsoft's NTFS and Apple's HFS+,
has case preserving behavior.
Although these file systems are not case-sensitive
(enforced primarily to support backward compatibility), they do
display file names with the original capitalization used when the file was created.Navigating Paths
The pwd command displays the full path name of the current location, which helps determine appropriate syntax for reaching files using relative path names. The ls command lists directory contents for the specified directory or, if no directory is given, for the current directory.Use the cd command to change directories. With a working directory of[student@desktopX ~]$
pwd
/home/student[student@desktopX ~]$
ls
Desktop Documents Downloads Music Pictures Public Templates Videos[student@desktopX ~]$
/home/student
, relative path syntax is shortest to reach
the Videos
subdirectory.
The Documents
subdirectory is then reached using absolute path syntax.
The shell program prompt displays, for brevity, only the last component of the current directory path. For[student@desktopX ~]$
cd Videos
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd /home/student/Documents
[student@desktopX Documents]$
pwd
/home/student/Documents[student@desktopX Documents]$
cd
[student@desktopX ~]$
pwd
/home/student[student@desktopX ~]$
/home/student/Videos
,
only Videos
displays.
At any time, return to the user's home directory using cd without
specifying a destination.
The prompt displays the tilde (~
) character
when the user's current directory is their home directory.
The touch command normally updates a file's timestamp to the current date and time without otherwise modifying it. This is useful for creating empty files, which can be used for practice, since "touching" a file name that does not exist causes the file to be created. Using touch, practice files are created in the
Documents
and Videos
subdirectories.
The ls command has multiple options for displaying attributes on files. The most common and useful are[student@desktopX ~]$
touch Videos/blockbuster1.ogg
[student@desktopX ~]$
touch Videos/blockbuster2.ogg
[student@desktopX ~]$
touch Documents/thesis_chapter1.odf
[student@desktopX ~]$
touch Documents/thesis_chapter2.odf
[student@desktopX ~]$
-l
(long listing format),
-a
(all files, includes hidden files),
and -R
(recursive, to include the contents of all subdirectories).
The two special directories at the top of the listing refer to the current directory ([student@desktopX ~]$
ls -l
total 15 drwxr-xr-x. 2 student student 4096 Feb 7 14:02 Desktop drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Documents drwxr-xr-x. 3 student student 4096 Jan 9 15:00 Downloads drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Music drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Pictures drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Public drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Templates drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Videos[student@desktopX ~]$
ls -la
total 15 drwx------. 16 student student 4096 Feb 8 16:15 . drwxr-xr-x. 6 root root 4096 Feb 8 16:13 .. -rw-------. 1 student student 22664 Feb 8 00:37 .bash_history -rw-r--r--. 1 student student 18 Jul 9 2013 .bash_logout -rw-r--r--. 1 student student 176 Jul 9 2013 .bash_profile -rw-r--r--. 1 student student 124 Jul 9 2013 .bashrc drwxr-xr-x. 4 student student 4096 Jan 20 14:02 .cache drwxr-xr-x. 8 student student 4096 Feb 5 11:45 .config drwxr-xr-x. 2 student student 4096 Feb 7 14:02 Desktop drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Documents drwxr-xr-x. 3 student student 4096 Jan 25 20:48 Downloads drwxr-xr-x. 11 student student 4096 Feb 6 13:07 .gnome2 drwx------. 2 student student 4096 Jan 20 14:02 .gnome2_private -rw-------. 1 student student 15190 Feb 8 09:49 .ICEauthority drwxr-xr-x. 3 student student 4096 Jan 9 15:00 .local drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Music drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Pictures drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Public drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Templates drwxr-xr-x. 2 student student 4096 Jan 9 15:00 Videos[student@desktopX ~]$
.
) and the
parent directory (..
).
These special directories exist in every directory on the system. Their
usefulness will become apparent when file management commands are practiced.
Important
File names beginning with a dot (.
) indicate files
hidden from normal view using ls
and other commands. This is not a security feature.
Hidden files keep necessary user configuration files from cluttering
home directories. Many commands process hidden files only with specific
command-line options, preventing one user's configuration
from being accidentally copied to other directories or users.
To protect file contents from improper viewing requires the use of file permissions.
The cd command has many options. A few are so useful as to be worth practicing early and using often. The command cd - changes directory to the directory where the user was previous to the current directory. Watch as this user takes advantage of this behavior to alternate between two directories, useful when processing a series of similar tasks.[student@desktopX ~]$
ls -R
.: Desktop Documents Downloads Music Pictures Public Templates Videos ./Desktop: ./Documents: thesis_chapter1.odf thesis_chapter2.odf ./Downloads: ./Music: ./Pictures: ./Public: ./Templates: ./Videos: blockbuster1.ogg blockbuster2.ogg[student@desktopX ~]$
The cd .. command uses the[student@desktopX ~]$
cd Videos
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd /home/student/Documents
[student@desktopX Documents]$
pwd
/home/student/Documents[student@desktopX Documents]$
cd -
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd -
[student@desktopX Documents]$
pwd
/home/student/Documents[student@desktopX Documents]$
cd -
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd
[student@desktopX ~]$
..
hidden
directory to move up one level to the parent directory,
without needing to know the exact parent name.
The other hidden directory (.
) specifies the
current directory on commands in which the current
location is either the source or destination argument, avoiding the need
to type out the directory's absolute path name.
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd .
[student@desktopX Videos]$
pwd
/home/student/Videos[student@desktopX Videos]$
cd ..
[student@desktopX ~]$
pwd
/home/student[student@desktopX ~]$
cd ..
[student@desktopX home]$
pwd
/home[student@desktopX home]$
cd ..
[student@desktopX /]$
pwd
/[student@desktopX /]$
cd
[student@desktopX ~]$
pwd
/home/student[student@desktopX ~]$
Comments
Post a Comment
thank you for visiting :)