Chuyển đến nội dung chính
eLearner.app
Mô-đun 1 · Bài học 1 trong tổng số 21/11 trong khóa học~10 min
Bài học theo mô-đun (1/2)

Tôi đang ở đâu? (pwd và 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

tập thể dục#linux.m1.l1.e1
Nỗ lực: 0Đang tải…

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

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

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

Giải pháp khả dụng sau 3 lần thử

Exercise 2: List files

tập thể dục#linux.m1.l1.e2
Nỗ lực: 0Đang tải…

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

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

Use the fundamental command for listing contents.

Giải pháp khả dụng sau 3 lần thử

Exercise 3: Show hidden files

tập thể dục#linux.m1.l1.e3
Nỗ lực: 0Đang tải…

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

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

Use ls combined with the -a option.

Giải pháp khả dụng sau 3 lần thử