Shell Navigation and File System

Level: Beginner Module: Linux Fundamentals 6 min read Lesson 2 of 10

Overview

  • What you’ll learn: How to navigate the Linux file system using the bash shell and manage files and directories with core commands.
  • Prerequisites: Lesson 1 – The Linux Operating System
  • Estimated reading time: 18 minutes

Introduction

The command-line shell is the primary interface for interacting with a Linux server. While graphical tools exist, the shell provides far greater power, flexibility, and the ability to automate tasks through scripting. Every Linux administrator must be proficient with shell navigation.

In this lesson, you will learn how to use the bash shell to move around the file system, understand the directory hierarchy, and perform essential file operations. These are foundational skills that you will use in every subsequent lesson.

We will cover the Filesystem Hierarchy Standard (FHS), which defines where different types of files are stored on a Linux system, and practice the commands you will use daily as a system administrator.

The Bash Shell

Bash (Bourne Again SHell) is the default shell on most Linux distributions, including Ubuntu. When you log in to a Linux server via SSH or open a terminal, you are presented with a shell prompt where you can type commands.

$ echo $SHELL
/bin/bash

$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

The shell prompt typically shows your username, hostname, and current directory. The $ symbol indicates a regular user, while # indicates the root user.

user@server:~$       # Regular user in home directory
root@server:/etc#    # Root user in /etc directory

Basic Navigation Commands

The three most fundamental navigation commands are pwd, cd, and ls:

$ pwd
/home/admin

$ cd /var/log
$ pwd
/var/log

$ ls
alternatives.log  auth.log  dpkg.log  kern.log  syslog

$ ls -la
total 2048
drwxrwxr-x  12 root   syslog  4096 Jan 15 00:00 .
drwxr-xr-x  14 root   root    4096 Jan  1 00:00 ..
-rw-r-----   1 syslog adm    52480 Jan 15 12:34 auth.log
-rw-r-----   1 syslog adm   198432 Jan 15 12:34 syslog
  • pwd (Print Working Directory): Shows your current location in the file system.
  • cd (Change Directory): Moves to a different directory.
  • ls (List): Displays the contents of a directory. The -l flag shows detailed information; -a shows hidden files.

Absolute vs. Relative Paths

There are two ways to specify a path in Linux:

  • Absolute path: Starts from the root directory /. Example: /var/log/syslog
  • Relative path: Starts from your current directory. Example: ../log/syslog (from /var/tmp)
$ cd /home/admin
$ cd Documents          # Relative: goes to /home/admin/Documents
$ cd /etc               # Absolute: goes to /etc
$ cd ..                 # Goes up one level to /
$ cd ~                  # Goes to home directory
$ cd -                  # Goes to previous directory

Filesystem Hierarchy Standard (FHS)

Linux follows the Filesystem Hierarchy Standard, which defines a consistent directory structure across distributions. Understanding where files are stored is critical for system administration.

  • / — Root directory, the top of the entire file system tree.
  • /bin — Essential user command binaries (e.g., ls, cp, mv).
  • /sbin — System binaries for administration (e.g., fdisk, iptables).
  • /etc — System-wide configuration files (e.g., /etc/passwd, /etc/fstab).
  • /home — User home directories (e.g., /home/admin).
  • /var — Variable data: logs (/var/log), mail, spool files.
  • /tmp — Temporary files, cleared on reboot.
  • /usr — User programs and data; /usr/bin, /usr/lib, /usr/share.
  • /opt — Optional third-party software.
  • /proc — Virtual filesystem providing process and kernel information.
  • /dev — Device files representing hardware (e.g., /dev/sda).
$ ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

File and Directory Operations

Creating and Removing Directories

$ mkdir projects
$ mkdir -p projects/web/frontend      # Create nested directories
$ rmdir projects/web/frontend         # Remove empty directory
$ rm -r projects                      # Remove directory and contents

Copying, Moving, and Deleting Files

$ cp file.txt backup.txt              # Copy a file
$ cp -r dir1/ dir2/                   # Copy directory recursively
$ mv old_name.txt new_name.txt        # Rename a file
$ mv file.txt /tmp/                   # Move file to /tmp
$ rm file.txt                         # Delete a file
$ rm -rf /tmp/old_data/               # Force delete directory

Viewing File Contents

$ file document.pdf
document.pdf: PDF document, version 1.4

$ cat /etc/hostname
ubuntu-server

$ less /var/log/syslog                # Scrollable viewer (q to quit)

$ head -5 /etc/passwd                 # First 5 lines
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync

$ tail -3 /etc/passwd                 # Last 3 lines
$ tail -f /var/log/syslog             # Follow new lines in real time

Wildcards and Globbing

The shell supports wildcards (also called globbing) to match multiple files:

$ ls *.txt                # All .txt files
$ ls file?.log            # file1.log, file2.log, etc.
$ ls [abc]*               # Files starting with a, b, or c
$ ls /var/log/*.log       # All .log files in /var/log
  • * — Matches zero or more characters.
  • ? — Matches exactly one character.
  • [abc] — Matches any single character in the set.
  • [a-z] — Matches any character in the range.

Key Takeaways

  • Bash is the default shell on Ubuntu; the prompt shows user, host, and current directory.
  • Use pwd, cd, and ls to navigate; understand absolute vs. relative paths.
  • The FHS defines a standard directory layout: /etc for config, /var for data, /home for users, /tmp for temporary files.
  • Essential file commands: mkdir, cp, mv, rm, cat, less, head, tail.
  • Wildcards (*, ?, []) allow you to match multiple files in a single command.

What’s Next

In Lesson 3, you will learn about Users, Groups, and Permissions — how Linux controls access to files and commands through its multi-user security model.

繁體中文

概述

  • 學習目標:學習如何使用 bash shell 導航 Linux 檔案系統,並使用核心命令管理檔案和目錄。
  • 先決條件:第 1 課 – Linux 作業系統
  • 預計閱讀時間:18 分鐘

簡介

命令列 shell 是與 Linux 伺服器互動的主要介面。雖然存在圖形工具,但 shell 提供了更強大的功能、靈活性以及透過腳本自動化任務的能力。每位 Linux 管理員都必須精通 shell 導航。

在本課程中,您將學習如何使用 bash shell 在檔案系統中移動、了解目錄層次結構,以及執行基本的檔案操作。這些是您在每個後續課程中都會使用的基礎技能。

Bash Shell

Bash(Bourne Again SHell)是大多數 Linux 發行版(包括 Ubuntu)的預設 shell。當您透過 SSH 登入 Linux 伺服器或開啟終端機時,您會看到一個可以輸入命令的 shell 提示符號

$ echo $SHELL
/bin/bash

基本導航命令

三個最基本的導航命令是 pwdcdls

  • pwd(列印工作目錄):顯示您在檔案系統中的當前位置。
  • cd(切換目錄):移動到不同的目錄。
  • ls(列出):顯示目錄的內容。-l 選項顯示詳細資訊;-a 顯示隱藏檔案。

絕對路徑與相對路徑

  • 絕對路徑:從根目錄 / 開始。例如:/var/log/syslog
  • 相對路徑:從您的當前目錄開始。例如:../log/syslog

檔案系統層次結構標準 (FHS)

Linux 遵循檔案系統層次結構標準,它定義了跨發行版一致的目錄結構。了解檔案的儲存位置對系統管理至關重要。

  • / — 根目錄,整個檔案系統樹的頂端。
  • /bin — 基本使用者命令二進位檔案。
  • /etc — 系統級設定檔。
  • /home — 使用者主目錄。
  • /var — 可變資料:日誌、郵件、排隊檔案。
  • /tmp — 臨時檔案,重新開機時清除。

檔案和目錄操作

建立和刪除目錄

$ mkdir projects
$ mkdir -p projects/web/frontend      # 建立巢狀目錄
$ rmdir projects/web/frontend         # 刪除空目錄
$ rm -r projects                      # 刪除目錄及其內容

複製、移動和刪除檔案

$ cp file.txt backup.txt              # 複製檔案
$ mv old_name.txt new_name.txt        # 重新命名檔案
$ rm file.txt                         # 刪除檔案

檢視檔案內容

$ cat /etc/hostname                   # 顯示檔案全部內容
$ less /var/log/syslog                # 可捲動的檢視器
$ head -5 /etc/passwd                 # 前 5 行
$ tail -f /var/log/syslog             # 即時跟蹤新行

萬用字元和 Globbing

  • * — 匹配零個或多個字元。
  • ? — 匹配恰好一個字元。
  • [abc] — 匹配集合中的任意單個字元。

重點摘要

  • Bash 是 Ubuntu 的預設 shell;提示符號顯示使用者、主機和當前目錄。
  • 使用 pwdcdls 進行導航;理解絕對路徑與相對路徑。
  • FHS 定義了標準目錄佈局:/etc 用於設定、/var 用於資料、/home 用於使用者。
  • 基本檔案命令:mkdircpmvrmcatlessheadtail
  • 萬用字元(*?[])允許您在單個命令中匹配多個檔案。

下一步

在第 3 課中,您將學習使用者、群組和權限——Linux 如何透過其多使用者安全模型控制對檔案和命令的存取。

日本語

概要

  • 学習内容:bash シェルを使用した Linux ファイルシステムのナビゲーション方法と、コアコマンドを使用したファイルとディレクトリの管理。
  • 前提条件:レッスン1 – Linux オペレーティングシステム
  • 推定読了時間:18分

はじめに

コマンドラインシェルは、Linux サーバーと対話するための主要なインターフェースです。グラフィカルツールも存在しますが、シェルはより強力な機能、柔軟性、スクリプトによるタスクの自動化機能を提供します。すべての Linux 管理者はシェルナビゲーションに精通している必要があります。

このレッスンでは、bash シェルを使用してファイルシステム内を移動し、ディレクトリ階層を理解し、基本的なファイル操作を実行する方法を学びます。

Bash シェル

Bash(Bourne Again SHell)は、Ubuntu を含むほとんどの Linux ディストリビューションのデフォルトシェルです。SSH 経由で Linux サーバーにログインするか、ターミナルを開くと、コマンドを入力できるシェルプロンプトが表示されます。

$ echo $SHELL
/bin/bash

基本的なナビゲーションコマンド

  • pwd(作業ディレクトリの表示):ファイルシステム内の現在位置を表示します。
  • cd(ディレクトリの変更):別のディレクトリに移動します。
  • ls(リスト):ディレクトリの内容を表示します。

絶対パスと相対パス

  • 絶対パス:ルートディレクトリ / から始まります。例:/var/log/syslog
  • 相対パス:現在のディレクトリから始まります。例:../log/syslog

ファイルシステム階層標準 (FHS)

Linux はファイルシステム階層標準に従い、ディストリビューション間で一貫したディレクトリ構造を定義しています。

  • / — ルートディレクトリ、ファイルシステムツリーの最上位。
  • /bin — 基本的なユーザーコマンドバイナリ。
  • /etc — システム全体の設定ファイル。
  • /home — ユーザーホームディレクトリ。
  • /var — 可変データ:ログ、メール、スプールファイル。
  • /tmp — 一時ファイル、再起動時にクリアされます。

ファイルとディレクトリの操作

ディレクトリの作成と削除

$ mkdir projects
$ mkdir -p projects/web/frontend      # ネストされたディレクトリを作成
$ rmdir projects/web/frontend         # 空のディレクトリを削除
$ rm -r projects                      # ディレクトリとその内容を削除

ファイルのコピー、移動、削除

$ cp file.txt backup.txt              # ファイルをコピー
$ mv old_name.txt new_name.txt        # ファイル名を変更
$ rm file.txt                         # ファイルを削除

ファイル内容の表示

$ cat /etc/hostname                   # ファイルの全内容を表示
$ less /var/log/syslog                # スクロール可能なビューア
$ head -5 /etc/passwd                 # 最初の5行
$ tail -f /var/log/syslog             # リアルタイムで新しい行を追跡

ワイルドカードとグロビング

  • * — 0文字以上にマッチ。
  • ? — 正確に1文字にマッチ。
  • [abc] — セット内の任意の1文字にマッチ。

重要ポイント

  • Bash は Ubuntu のデフォルトシェルで、プロンプトにはユーザー、ホスト、現在のディレクトリが表示されます。
  • pwdcdls でナビゲーション。絶対パスと相対パスを理解しましょう。
  • FHS は標準的なディレクトリレイアウトを定義:/etc は設定、/var はデータ、/home はユーザー用。
  • 基本的なファイルコマンド:mkdircpmvrmcatlessheadtail
  • ワイルドカード(*?[])を使って1つのコマンドで複数のファイルをマッチできます。

次のステップ

レッスン3では、ユーザー、グループ、パーミッションについて学びます。Linux がマルチユーザーセキュリティモデルを通じてファイルやコマンドへのアクセスをどのように制御するかを学びます。

You Missed