This outline shows our roadmap: Linux filesystem concepts, specifying files by name, file manipulation with command-line tools, creating links, pattern matching, quizzes, guided exercises, a graded lab, and the module summary.
After completing the work in this module you will be able to:
By module's completion, you should be able to describe the directory hierarchy, navigate using absolute and relative paths, create, copy, move, delete files and directories, set up hard and symbolic links, and use shell expansions for efficiency.
We begin with understanding the structure of the Linux filesystem—rooted in a single inverted tree, starting at a forward slash (/). This differs from Windows drive-letter systems.
Unlike Windows Linux organizes files into a single inverted tree-like structure even when files exist on a separate storage device. Drive letters such as C, D, and E are not used. The top of the file system is represented by a / (forward slash).
boot
DirectoryThe /boot
holds files essential for booting—like the Linux kernel (vmlinuz) and initial ramdisk images, needed before mounting the root filesystem.
dev
DirectoryThe /dev
is a virtual directory housing device files—interfaces to hardware devices. For example, /dev/sda
represents a physical disk.
etc
DirectoryThe etc
directory holds system-wide configuration files. It's where you configure services such as SSH (/etc/ssh/sshd_config
) and system settings.
home
DirectoryUnder the home
directory each unprivileged user has a personal directory. This is where personal files, configurations, and documents reside. For example, the personal files of user student are stored in /home/student
. If a user megan exists her files would be under /home/megan
.
lib
DirectoryLibraries shared by programs—such as those needed for spell-checking—live in /lib
or /usr/lib
. These libraries support executable binaries.
proc
DirectoryThe proc
directory is a virtual directory created when the system boots to provide information about system resources. For example, /proc/meminfo
contains detailed information about system memory.
root
DirectoryThe root
directory is the personal directory for the administrator or superuser - not to be confused with the filesystem root /. It's used when the root user logs in. However, following best practices the system administrator will work as as an unprivileged user and only gain root privileges when needed.
run
DirectoryThe run
directory is a temporary directory in memory for storing various information such as lock files and sockets.
tmp
DirectoryThe tmp
directory stores temporary files from both users and programs. It's cleared periodically or on reboot and is writable by all users.
usr
DirectoryInstalled software and shared libraries are found in the usr
directory. The /bin
and /sbin
directories are symbolically linked to /usr/bin
and /usr/sbin
.
var
DirectoryDynamic data—like logs, caches, mail spools—resides in /var
. For example, system logs are typically found in /var/log
.
Time for a quick graded quiz: identify and describe the purpose of these key directories based on what we've just covered.
Next, we'll learn how to access files using absolute and relative paths—crucial when navigating or executing commands.
[student@servera ~]$ ls /etc/ssh/sshd.config [student@servera ~]$ pwd /home/student/
The absolute path to a file always starts at the top of the file system represented by a forward slash (/) and can be used to navigate to a file from anywhere on the system. The pwd
or Print Working Directory command shows the absolute path to the directory you are currently in.
[student@servera /etc/ssh/]$ sudo vim sshd.config
Using a relative path to a file requires less typing then using the absolute path. In this example, student is already in the /etc/ssh/
directory as you can see by the prompt so only the file name is needed, but that will not work from anywhere else on the system.
[student@servera ~]$ cp /etc/passwd .
Linux provides a number of shortcuts to help you navigate the system. A single period (.) represents the current directory and two periods (..) represents the parent directory. These shortcuts can be used in commands.
In this example a file is copied to the current directory from the /etc
directory. Note the single period as the destination. A single period represents the current working directory in this case student's home directory.
[student@servera Documents]$ mv file.txt ../ [student@servera Documents]$ ls ../ Documents Music Desktop Pictures Videos file.txt
In this example, file.txt is moved to the parent directory of the Documents directory. ../ represents the parent directory in both commands.
After reading this section in the textbook complete the quiz in Canvas.
Creating, copying, moving, and removing files are common operations. In this section you will learn command line tools to perform these tasks.
Creating, copying, moving, and removing files are common operations. In this section you will learn command line tools to perform these tasks.
[student@servera ~]$ touch file file1 file2 file3 [student@servera ~]$ ls file* file file1 file2 file3
The touch
command is useful for creating one or more empty files when you need files to test a command. If used with files that already exist touch
will update the timestamp on the files. This can be useful if you want all the files to have the same modification date when distributing them in an archive.
[student@servera ~]$ mkdir -v 'My Stuff' mkdir: created directory 'My Stuff'
The mkdir
command creates one or more new directories. If the directory name contains a space the name must be enclosed in quotes. The -v
option confirms that the MyStuff
directory was created.
[student@servera ~]$ cp file1 file2
The cp
command copies a file to a new file. If the new file name already exists it is overwritten. The source file is always the first argument to the command followed by the destination file name. If the last argument is a directory the file or files are copied into that directory.
[student@servera ~]$ mv file1 file2 Documents/ [student@servera ~]$ ls Documents/ file1 file2
The mv
command serves two purposes. It can move a file to a new location or rename a file. Here file1
is moved from student's home directory to the Documents directory and renamed to file3
.
[student@servera ~]$ rm file2
[student@servera ~]$ rmdir MyStuff rmdir: failed to remove 'MyStuff': Directory not empty
[student@servera ~]$ rm -rf MyStuff
The rm
command will delete a file or if used with the recursive option it removes a directory and its contents. The deletion is permanent. There is no recycle bin or undo on the command line.
tree
command to confirm that you moved files correctly. See Resources.touch song{1..6}.mp3
.cp
command continues on the next two line and the period at the end of the command represents the destination, the current directory.You can refer to a file by creating multiple links. There are two types of links, hard links and symbolic or "soft" links.
[student@servera ~]$ ln file1 file2 [student@servera ~]$ ls -li file1 file2 1643415 -rw-r--r-- 2 user user 0 Jun 29 06:43 file1 1643415 -rw-r--r-- 2 user user 0 Jun 29 06:43 file2
A hard link points directly to the data on the file system not to a file name. A file name is just a reference to where the data is stored on the file system. You can create multiple hard links to the data. As long as one link still exists the data is accessible. Only when the last link is removed is the data no longer accessible.
In this example a hard link is created from file1
to file2
. The ls -li
command shows that each file has two links and the inode numbers for each file are the same. An inode tells the system where the data is on the storage device.
A hard link can not span multiple file systems and a hard link to a directory is not possible.
[student@servera ~]$ ln -s soft_link file1 [student@servera ~]$ ls -l soft_link lrwxrwxrwx 1 student student 8 Jun 29 soft_link -> file1
A symbolic or "soft" link points to a file name not to an inode. If the referenced file is deleted the link is broken and the data is lost.
In this example a soft link named soft_link
is created to file1
. The ls -l
command shows that soft_link
is a link. If file1
is deleted the link is broken and the data is lost.
Step 2.2: Using a relative path and tab completion this command can be entered by typing far fewer characters.
Often you can save time by using pathname expansion or pattern matching to perform operations on multiple files with a single command.
When you type a command at the Bash shell prompt, the shell processes that command line through multiple expansions before running it. You can use these shell expansions to perform complex tasks that would otherwise be difficult or impossible.
Pattern | Matches |
---|---|
* | Zero or more characters |
? | A single character |
[[abc]] | Any one character in the enclosed class |
[[!abc]] | Any one character not in the enclosed class |
[[:alpha:]] | Any alphabetic character |
[[:alnum:]] | Any alphabetic character or digit |
[[:digit:]] | Any single digit from 0 to 9 |
Pathname expansion expands a pattern of special characters that represent wild cards or classes of characters into a list of file names that match the pattern. See table in textbook.
[student@servera ~]$ touch file{1..5} [student@servera ~]$ ls file* file1 file2 file3 file4 file5
In this example brace expansion is used to create a sequence of files with a minimum of typing.
[student@servera Documents/MyStuff]$ ls ~/Videos video1.mp4 video2.mp4 video3.mp4
The tilde (~) represents the user's home directory and is a useful shortcut to that directory from anywhere on the system.
student@servera ~]$ echo "The system language is set to $LANG." The system language is set to en_US.UFT-8.
The $ in front of LANG tells the shell that this is a variable. The shell will use the value of the varible in the echo
command.
[student@servera ~]$ echo "The language is set with \$LANG." The language variable $LANG sets the system language.
A backslash (\) before a reserved character tells the shell to treat the character as an ordinary character.
[student@servera ~]$ tar -cf backup-$(date +%F).tar [student@worstation ~]$ ls backup* backup-2023-11-01.tar
Similar to variable expansion the value from the date
command is added to the file name making it easy to know when the backup was created.
Complete this quiz in Canvas.
mkdir
, rmdir
, cp
, mv
, and rm
are key commands to manage files in Linux.mkdir
command: 2-Minute Linux Tipsln
command: 2-Minute Linux Tipstree
command: 2-Minute Linux Tipsclear
command to get a fresh prompt.ln
command is the same as the cp
and mv
commands. The source file comes first followed by the destination file.Thanks for watching. This is the end of the presentation.
Created on 17 February 2025 by Dennis Kibbe. Last modified on 9 June 2025 09:21:00 by DNK.
Keyboard Shortcuts
Welcome everyone. In this module, we’ll explore how to manage files using the Linux command line. It’s essential for both server administration and everyday Linux use. This slide presentation was created by B6Plus. The audio accompanying this presentation is AI-generated.