Lab - Listing Files and Directories

By performing this lab, students will learn how to navigate and manage files and directories.

In this lab, you will perform the following tasks:

  1. List files and directories
  2. 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 /
时间: 2024-12-14 15:42:14

Lab - Listing Files and Directories的相关文章

Files and Directories

Files and Directories Introduction In the previous chapter we coveredthe basic functions that perform I/O. The discussion centered on I/O for regular files-opening a file, and reading or writing a file. We'll now look at additionalfeatures of the fil

How to remove all the empty files or directories?

*/--> How to remove all the empty files or directories? I am confused why I get many empty directories inside my Downloads directory, and I have to remove all of the empty ones. Here is what I did: find home/wujing/Downloads -empty -type d -delete Th

UNIX高级环境编程(4)Files And Directories - umask、chmod、文件系统组织结构和链接

本篇主要介绍文件和文件系统中常用的一些函数,文件系统的组织结构和硬链接.符号链接. 通过对这些知识的了解,可以对Linux文件系统有更为全面的了解. ? 1 umask函数 之前我们已经了解了每个文件与权限相关的9个位(bit),我们现在来了解一下当每个进程创建文件时默认会设置该文件的文件权限(the file mode creation mask). umask函数设置该进程默认创建文件的权限掩码(the file mode creation mask),并且返回之前的权限掩码值. #incl

UNIX高级环境编程(3)Files And Directories - stat函数,文件类型,和各种ID

在前面的两篇,我们了解了IO操作的一些基本操作函数,包括open.read和write. 在本篇我们来学习一下文件系统的其他特性和一个文件的属性,涉及的函数功能包括: 查看文件的所有属性: 改变文件所有者: 改变文件权限: 操作文件夹. 我们还会了解一些文件系统相关的数据结构和符号链接(symbolic link). 1 函数stat.fstat.fstatat.lsat函数 #include <sys/stat.h> int stat(const char *restrict pathnam

Notes for Apue &mdash;&mdash; chapter 4 Files and Directories(文件和目录)

4.1 Introduction 4.2 stat, fstat, fstatat, and lstat Functions The lstat function is similar to stat, but when the named file is a symbolic link, lstat returns information about the symbolic link, not the file referenced by the symbolic link. 4.3 文件类

UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作

?1 File Times 每个文件会维护三个时间字段,每个字段代表的时间都不同.如下表所示: 字段说明: st_mtim(the modification time)记录了文件内容最后一次被修改的时间. st_ctim(the changed-status time)记录了文件的i-node最后一次被修改的时间,如修改文件权限位,修改文件所有者ID,修改关联到该文件的link数目. i-node中的信息和文件的实际内容是分离的,所以当更新i-node时,需要更新的时st_ctim(the ch

java 实现下载htttp文件的简便办法 FileUtils IOUtils

其实很多时候,我们并不需要去重复造轮子,只需要借 就可以.但是前提就得你得知道谁家有轮子可借才行.这次就用到了 org.apache.common.io 家的轮子了. 具体实现: public String downloadHttpUrl(String url, String dir) { String fileName = "test.jpg"; try { URL httpurl = new URL(url); File f = new File(dir + fileName);

Jakarta Commons Cookbook

Cookbook就是工具书,应该是前年看的,在中关村看的影印版,全英文,本书主要讲解了一下模块: Core:BeanUtils,Lang,Collections,logging Db:DbUtils,DBCP,Pool IO: IO, XML vs Bean:betwixt,Digester,JXPath,Jelly 模版:EL, JEXL 通用:Codec,Id Web:FileUpload,httpClient 文件系统:VFS apache的工具包几乎是每个java工程都用到了的,或是co

Lua Doc生成工具

Luadoc http://keplerproject.github.io/luadoc/ Overview LuaDoc is a documentation generator tool for Lua source code. It parses the declarations and documentation comments in a set of Lua source files and produces a set of XHTML pages describing the c