Learning Linux Commands: Navigating the File System

Learning Linux Commands: Navigating the File System

As I explore Linux, one thing has become clear: the terminal is where the real power lies. You can move through directories, manage files, and interact with your system all from the command line.

There are many commands available, but here are the essential ones for navigating the Linux file system:

1. pwd – Print Working Directory

What it does: Displays your current location in the file system.

Why it's useful: When you’re deep in folders and subfolders, it’s easy to lose track of where you are. Running pwd helps you know exactly which directory you're in at any time.

$ pwd
/home/user        

In this example, we are currently located in the /home/user directory.

2. cd – Change Directory

What it does: Moves you from your current folder into another directory.

Use case: Let’s say we’re in /home/user and want to move into the /etc directory. Here's how we do it:

$ cd /etc        

That’s it! You’re now in the /etc folder. You can always double-check with pwd.

3. ls – List Files and Directories

What it does: Shows you the contents of the current directory (files, folders, etc.).

Example: After moving to the /usr directory using cd, you can run:

$ ls        

This will list everything inside /usr. For instance, if you see 10 items, those could include folders like bin, lib, and share.

Getting Help

If you're ever unsure about what a command does, the manual (man) pages can help. It is usually very detailed and explanatory

$ man ls        

This will open a detailed explanation of how ls works and what options you can use with it.

Manipulating Files and Directories in Linux

Linux isn’t just about navigating the file system — it also gives you powerful tools to create, move, copy, and delete files and folders directly from the terminal. Here are a few basic file manipulation commands that I’ve found especially useful:

1. touch – Create a New File

Purpose: Creates an empty file.

Syntax:

touch <file_name>        

Example:

touch my_file.txt        

No message is displayed after running this command, but you can verify the file was created using ls.

2. mkdir – Create a Directory

Purpose: Creates a new folder (directory).

Syntax:

mkdir  <directory_name>        

Example:

mkdir test_folder        

Again, there’s no confirmation message, so you can use ls to check if the directory now exists.

3. rm – Delete Files and Directories

Purpose: Removes files or folders. Be very careful while using this command — there’s no undo!

Syntax (for files):

rm <file_name>        

Syntax (for directories):

rm -r <directory_name>        

Example:

rm my_file.txt
rm -r test_folder        

Use ls to confirm that the files or folders are gone.

4. cp – Copy Files and Directories

Purpose: Copies files or directories to a new location without removing the original.

Syntax:

cp <source_path> <destination_path>        

Example:

touch test_file.txt
mkdir test_dir
cp test_file.txt test_dir/        

This creates an empty file called test_file.txt and also a directory named test_dir. We use cp command to copy the test_file.txt into the directory. Then you can cd into test_dir and use ls to see the copied file.

5. mv – Move or Rename Files and Directories

Purpose: Moves a file or directory to another location, or renames it. Unlike cp, the original file is removed from the original location.

Syntax (for moving):

mv <source_path> <destination_path>
        

Syntax (for renaming):

mv old_name new_name
        

Example:

touch test_runner.py
mv test_runner.py test_dir/
        

Use ls inside test_dir to confirm the file has been moved.

Commands for Viewing Files in Linux

In Linux, the terminal isn’t just for navigating and manipulating files — it also lets you view the content of files directly from the command line. They are especially useful when working with logs, config files, or scripts. Here are some powerful commands you can use to read file content without opening a text editor:

1. cat – View the entire file

Syntax:

cat filename.txt        

Example:

cat notes.txt        

This displays the full content of notes.txt right in the terminal. Best used for small files.

2. head – View the first few lines of a file

Syntax:

head filename.txt        

Example (default first 10 lines):

head report.txt        

Example (first 5 lines):

head -n 5 report.txt        

This is helpful when you just want a quick preview of how the file starts.

3. tail – View the last few lines of a file

Syntax:

tail filename.txt        

Example (default last 10 lines):

tail log.txt        

Example (last 20 lines):

tail -n 20 log.txt        

tail is perfect for checking recent entries in log files or updates.

4. more – Page through a long file

Syntax:

more filename.txt        

Example:

more long_file.txt        

  • Press spacebar to scroll to the next page.
  • Press q to quit.

Useful when the file is too large to fit on one screen.

5. less – Advanced pager for large files

Syntax:

less filename.txt        

Example:

less system_config.txt        

  • Use arrow keys or Page Up/Page Down to scroll.
  • Press q to exit.

Difference Between more and less in Linux


Article content
more vs less


These commands are simple, but they’ve helped me feel much more confident using the Linux terminal. Mastering them makes file management fast and efficient — no need to rely on a GUI!

This is just the beginning, but these basic commands have already made using Linux way less intimidating for me. If you're learning too, feel free to connect or share what helped you most!


To view or add a comment, sign in

More articles by Daniel Edun

Insights from the community

Others also viewed

Explore topics