跳转到主要内容
eLearner.app
模块 1 · 第 1 课(共 2)课程中的1/11~10 min
模块课程(1/2)

我在哪里? (pwd 和 ls)

The Linux command line (or terminal) is an extremely powerful tool that lets you interact with the operating system by typing text commands instead of using a graphical user interface.

All files and folders in Linux are organized in an inverted tree structure starting from a common root directory, represented by a single forward slash / (referred to as root). Every user has their own personal folder inside /home, for example, /home/user. This is known as the home directory.


Knowing Where You Are: pwd

In the terminal, you are always positioned inside a specific folder, called the current working directory.

To find out which folder you are currently in, you can use the command:

Bash
pwd

This command stands for Print Working Directory. If you run it right after opening the terminal, you will typically see the path to your home folder, for example:

Bash
/home/user

Listing Contents: ls

To see what files and folders are present inside your current directory, use the command:

Bash
ls

This command stands for List. It will show the names of all visible files and folders in your current location.

Useful Options for ls

Linux commands can be customized using options (also called flags or arguments), prefixed with a hyphen -:

  • ls -a: Lists all files, including hidden files that start with a dot (like .bashrc or .git).
  • ls -l: Displays the listing in long format, including details such as file permissions, owner, file size, and the date/time of last modification.
  • You can combine these flags by writing ls -la or ls -al to see all files in a detailed list.

For example, running ls -la in a sample folder might display a structured output like this:

Bash
drwxr-xr-x 2 user user 4096 May 22 12:00 .
drwxr-xr-x 3 user user 4096 May 22 12:00 ..
-rw-r--r-- 1 user user  220 May 22 12:00 .bashrc
-rw-r--r-- 1 user user   18 May 22 12:00 info.txt
drwxr-xr-x 2 user user 4096 May 22 12:00 documents

In this output:

  • Lines starting with d (e.g. drwxr-xr-x) represent directories (folders).
  • Lines starting with - (e.g. -rw-r--r--) represent regular files.
  • . and .. are special shortcuts linking to the current and parent directories.
  • .bashrc is a hidden file, recognized by its leading dot.

Try it yourself

Exercise 1: Find your position

锻炼#linux.m1.l1.e1
尝试:0加载中...

Write the command to find the current working directory you are in.

正在加载编辑器...
显示提示

Use the command that prints the absolute path of the current directory.

3 次尝试后可用的解决方案

Exercise 2: List files

锻炼#linux.m1.l1.e2
尝试:0加载中...

List the files in the current folder to see what resources are available.

正在加载编辑器...
显示提示

Use the fundamental command for listing contents.

3 次尝试后可用的解决方案

Exercise 3: Show hidden files

锻炼#linux.m1.l1.e3
尝试:0加载中...

Use the ls command with the appropriate flag to display all files in the current directory, including hidden files starting with a dot.

正在加载编辑器...
显示提示

Use ls combined with the -a option.

3 次尝试后可用的解决方案