By performing this lab, students will learn how to navigate and manage files and directories.
In this lab, you will perform the following tasks:
- List files and directories
- Copy, move and delete files and directories
Part 1: Files and Directories
In this task you will explore the concepts of files and directories.
On a Linux OS, data is stored in files and files are stored in directories. You may be used to the term folders to describe directories.
Directories are actually files, too; the data that they hold are the names of the files that have been entered into the them, along with the inode number (a unique identifier number assigned to each file) for where the data for that file exists on the disk.
As a Linux user, you will want to know how to manipulate these files and directories, including how to list files in a directory, copy, delete and move files.
Step 1
Type the following command to print the working directory:
[[email protected] ~]$ pwd /home/zhangqiwei
The working directory is the directory that your terminal window is currently "in". This is also called the current directory. This will be important for when you are running future commands as they will behave differently based on the directory you are currently in.
When you first open a terminal window, you will be placed in your home directory. This is a directory where you have full access and other users normally have no access by default. To see the path to your home directory, you can execute the following command to view the value of the HOME variable:
[[email protected] ~]$ echo $HOME /home/zhangqiwei
Step 2
You can use the cd
command with a path to a directory to change your current directory. Type the following command to make the root directory your current working directory and verify with the pwd
command:
[[email protected] ~]$ cd / [[email protected] /]$ pwd /
To change back to your home directory, the cd command can be executed without a path. Change back to your home directory and verify by typing the following commands:
[[email protected] /]$ cd [[email protected] ~]$ pwd /home/zhangqiwei
Step 3
Use the echo
command below to display some other examples of using the tilde as part of path:
[[email protected] ~]$ echo ~ zhangqiwei ~root ~mail ~nobody /home/zhangqiwei zhangqiwei /root /var/spool/mail /