π§ Day 2 - Basic Linux Navigation and File Manipulation for Beginners

Table of contents
- 1. Username, Hostname, and Working Directory
- 2. What Does $ Mean?
- π 2. Navigate Through Directories
- π 3. Create and View Files
- π Viewing Files in Linux: Commands and Examples
- π Managing Directories in Linux: Commands and Examples
- What is a Directory?
- Common Directory Management Commands
- Summary Table
- βοΈ 5. Copy, Move, and Delete Files
- Copy Files (cp)
- Move or Rename Files (mv)
- Delete Files (rm)
- β Conclusion

Linux is a powerful and widely used operating system, especially in DevOps and server environments. Whether you're managing servers, writing shell scripts, or troubleshooting issues, mastering Linux commands is essential. Here's a guide to the most basic and commonly used Linux commands to get you started.
When you start using Linux, itβs important to first know who you are, where you are, and then learn how to move around and manage files.
Before you start creating or managing files, you need to identify yourself and understand your current location in the system
When you're using the Linux terminal, the command prompt often shows something like this:
1. Username, Hostname, and Working Directory
In the Linux terminal prompt, you often see something like:
username@hostname:working_directory$
username: the name of the user currently logged in.
hostname: the name of the computer or server.
working_directory: the current folder you are in.
$: the prompt symbol indicating a regular user (for root user, itβs
#
).Example:
mounika@inspiron:~$
Here,
mounika
is the user,inspiron
is the computer name, and~
means the home directory.To check these yourself, you can run:
Your username:
whoami
Your hostname:
hostname
Your current directory:
pwd
2. What Does $
Mean?
The
$
symbol at the end of the prompt means you are logged in as a regular user (non-root).If you see
#
, that means you are logged in as the root user (administrator).
Example:
mounika@inspiron:~$ (regular user)
root@inspiron:~# (root user)
π 2. Navigate Through Directories
Linux is like a big tree of folders. You need to learn how to move between these folders.
π This is Syntax: ls
π This is Structure: Lists files and folders in the current directory.
π This is Syntax: cd foldername
π This is Structure: Changes into the folder called foldername
.
π This is Syntax: cd ..
π This is Structure: Goes back one level to the parent directory.
π This is Syntax: cd ~
π This is Structure: Goes to your home directory.
π 3. Create and View Files
Now that you know where you are, letβs start making and reading files.
π How to Create Files in Linux: All Ways Explained with Examples
Method | Command Example | Description |
touch | touch file.txt | Create empty file |
echo | echo "text" > file.txt | Create file with single line text |
cat | cat > file.txt + Ctrl+D | Create file with multiple lines input |
printf | printf "line1\nline2\n" > file.txt | Create file with formatted content |
Text Editors | nano file.txt or vim file.txt | Create and edit file interactively |
1. Using touch
command
Purpose: Creates an empty file or updates the timestamp of an existing file.
Syntax:
touch filename.txt
Example:
touch myfile.txt
Creates an empty file called
myfile.txt
if it doesn't exist.
π This is Syntax: touch filename.txt
2. Using echo
command
Purpose: Create a file and add some text content to it.
Syntax:
echo "Your text here" > filename.txt
Example:
echo "Hello Linux!" > greetings.txt
Creates
greetings.txt
with the contentHello Linux!
.Note:
Using>
will overwrite the file if it exists. Use>>
to append text.
3. Using cat
command
Purpose: Create a file and enter multiple lines manually.
Syntax:
cat > filename.txt
Then type text, and press
Ctrl + D
to save and exit.Example:
cat > notes.txt
Then type:
This is my first note. This is the second line.
Press
Ctrl + D
when done.
4. Using printf
command
Purpose: Create a file with formatted content.
Syntax:
printf "Line1\nLine2\n" > filename.txt
Example:
printf "Hello\nWorld\n" > hello.txt
Creates
hello.txt
with two lines:Hello World
5. Using text editors
Purpose: Create and edit files interactively.
Common editors:
nano filename.txt
β Easy-to-use text editor.vim filename.txt
β Powerful but advanced editor.
Example with nano:
nano myfile.txt
This opens the nano editor where you can write content, then save (
Ctrl + O
) and exit (Ctrl + X
).
π Viewing Files in Linux: Commands and Examples
1.
cat
β View entire file contentSyntax:
cat filename.txt
Example:
cat myfile.txt
Displays the full content of
myfile.txt
on the terminal.Note: Good for small files because it prints all content at once.
2. head
β View the first few lines of a file
Syntax:
head filename.txt
By default, shows the first 10 lines.
Example:
head myfile.txt
Shows the first 10 lines of
myfile.txt
.View specific number of lines:
head -n 5 myfile.txt
Shows first 5 lines.
3. tail
β View the last few lines of a file
Syntax:
tail filename.txt
Shows last 10 lines by default.
Example:
tail myfile.txt
Displays last 10 lines.
View specific number of lines:
tail -n 7 myfile.txt
Shows last 7 lines.
Follow file changes live:
tail -f /var/log/syslog
Keeps showing new lines added to the file in real time (useful for logs).
4. less
β View file page by page (scrollable)
Syntax:
less filename.txt
Example:
less myfile.txt
Opens the file for easy navigation up/down.
Navigation keys:
Press
Space
to go to next pagePress
b
to go back one pageUse arrow keys to scroll line by line
Press
q
to quit
5. more
β View file page by page (basic)
Syntax:
more filename.txt
Example:
more myfile.txt
Similar to
less
but with fewer features.
Summary Table
Command | Purpose | Example |
cat | View full file content | cat file.txt |
head | View first 10 lines | head file.txt |
head -n N | View first N lines | head -n 5 file.txt |
tail | View last 10 lines | tail file.txt |
tail -n N | View last N lines | tail -n 7 file.txt |
tail -f | Follow live file updates | tail -f /var/log/syslog |
less | Scrollable view, page-wise | less file.txt |
more | Basic scrollable view | more file.txt |
π Managing Directories in Linux: Commands and Examples
What is a Directory?
A directory is like a folder that holds files and other directories.
Directories help organize your files on Linux systems.
Common Directory Management Commands
1. Create a Directory: mkdir
Syntax:
mkdir directory_name
Example:
mkdir projects
Creates a new directory named
projects
.Create multiple directories at once:
mkdir dir1 dir2 dir3
Create parent directories as needed:
mkdir -p parent/child/grandchild
Creates the full nested directory structure even if the parents donβt exist.
2. Change Directory: cd
Syntax:
cd directory_path
Example:
cd projects
Moves into the
projects
directory.Other useful shortcuts:
cd ..
β Move up one directory (to parent directory)cd ~
or simplycd
β Go to your home directorycd -
β Switch back to the previous directory
3. List Directory Contents: ls
Syntax:
ls [options] [directory]
Example:
ls
Lists files and folders in the current directory.
Common options:
ls -l
β Detailed list with permissions, size, and modification datels -a
β Show all files including hidden ones (those starting with.
)ls -lh
β Human-readable sizes (KB, MB)
4. Remove a Directory: rmdir
and rm
Remove empty directory:
rmdir directory_name
Remove directory with files inside:
rm -r directory_name
Use
-r
(recursive) to delete directory and its contents.Force remove without prompt:
rm -rf directory_name
Be very careful! This deletes directory and everything inside without confirmation.
5. Print Current Directory: pwd
Syntax:
pwd
Example:
pwd
Shows the full path of your current working directory.
Summary Table
Command | Description | Example |
mkdir directory | Create new directory | mkdir myfolder |
mkdir -p parent/child | Create nested directories | mkdir -p projects/app/src |
cd directory | Change directory | cd projects |
cd .. | Go to parent directory | cd .. |
ls | List files and folders | ls -la |
rmdir directory | Remove empty directory | rmdir oldfolder |
rm -r directory | Remove directory with contents | rm -r oldfolder |
pwd | Print current directory path | pwd |
βοΈ 5. Copy, Move, and Delete Files
Copy Files (
cp
)Syntax:
cp source_file destination_file
Example:
cp file1.txt file2.txt
Copies
file1.txt
tofile2.txt
.Copy directories recursively:
cp -r folder1 folder2
Copies
folder1
and its contents tofolder2
.
Move or Rename Files (mv
)
Syntax:
mv old_name new_name
Example (rename):
mv oldname.txt newname.txt
Example (move to directory):
mv filename.txt /path/to/destination/
Delete Files (rm
)
Syntax:
rm filename
Example:
rm file.txt
Delete directories recursively:
rm -r myfolder
Force delete without prompt:
rm -rf myfolder
β Conclusion
These basic commands are the building blocks of using Linux. Once youβre confident with them, youβll be able to:
Explore directories πΆββοΈ
Create files and folders π
Organize your data ποΈ
Understand your system better π»
Practice them regularly, and Linux will become your best friend!
Subscribe to my newsletter
Read articles from mounika pogakula directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

mounika pogakula
mounika pogakula
Hi, I'm Mounika Pogakula, a passionate DevOps enthusiast transitioning into tech with a strong foundation in Linux, Networking, and Cloud fundamentals. I hold a B.Sc. in Computers and a Networking Essentials certification. Iβm diving deep into tools like Git, Docker, Jenkins, Kubernetes, and AWS, while sharing my real-world learning journey, hands-on practice, and beginner-friendly insights here on Hashnode. π I'm especially focused on simplifying complex topics, documenting my progress, and building high-impact projects that help meβand othersβgrow in the DevOps space. Letβs learn, build, and grow together π»β¨