π§ Day 2 - Basic Linux Navigation and File Manipulation for Beginners
Linux Basic Commands You Need to Know (Even If You're Just Starting Out!)

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 π»β¨
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,
mounikais the user,inspironis the computer name, and~means the home directory.To check these yourself, you can run:
Your username:
whoamiYour hostname:
hostnameYour 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.txtExample:
touch myfile.txtCreates an empty file called
myfile.txtif 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.txtExample:
echo "Hello Linux!" > greetings.txtCreates
greetings.txtwith 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.txtThen type text, and press
Ctrl + Dto save and exit.Example:
cat > notes.txtThen type:
This is my first note. This is the second line.Press
Ctrl + Dwhen done.
4. Using printf command
Purpose: Create a file with formatted content.
Syntax:
printf "Line1\nLine2\n" > filename.txtExample:
printf "Hello\nWorld\n" > hello.txtCreates
hello.txtwith 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.txtThis 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.txtExample:
cat myfile.txtDisplays the full content of
myfile.txton 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.txtBy default, shows the first 10 lines.
Example:
head myfile.txtShows the first 10 lines of
myfile.txt.View specific number of lines:
head -n 5 myfile.txtShows first 5 lines.
3. tail β View the last few lines of a file
Syntax:
tail filename.txtShows last 10 lines by default.
Example:
tail myfile.txtDisplays last 10 lines.
View specific number of lines:
tail -n 7 myfile.txtShows last 7 lines.
Follow file changes live:
tail -f /var/log/syslogKeeps showing new lines added to the file in real time (useful for logs).
4. less β View file page by page (scrollable)
Syntax:
less filename.txtExample:
less myfile.txtOpens the file for easy navigation up/down.
Navigation keys:
Press
Spaceto go to next pagePress
bto go back one pageUse arrow keys to scroll line by line
Press
qto quit
5. more β View file page by page (basic)
Syntax:
more filename.txtExample:
more myfile.txtSimilar to
lessbut 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_nameExample:
mkdir projectsCreates a new directory named
projects.Create multiple directories at once:
mkdir dir1 dir2 dir3Create parent directories as needed:
mkdir -p parent/child/grandchildCreates the full nested directory structure even if the parents donβt exist.
2. Change Directory: cd
Syntax:
cd directory_pathExample:
cd projectsMoves into the
projectsdirectory.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:
lsLists 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_nameRemove directory with files inside:
rm -r directory_nameUse
-r(recursive) to delete directory and its contents.Force remove without prompt:
rm -rf directory_nameBe very careful! This deletes directory and everything inside without confirmation.
5. Print Current Directory: pwd
Syntax:
pwdExample:
pwdShows 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_fileExample:
cp file1.txt file2.txtCopies
file1.txttofile2.txt.Copy directories recursively:
cp -r folder1 folder2Copies
folder1and its contents tofolder2.
Move or Rename Files (mv)
Syntax:
mv old_name new_nameExample (rename):
mv oldname.txt newname.txtExample (move to directory):
mv filename.txt /path/to/destination/
Delete Files (rm)
Syntax:
rm filenameExample:
rm file.txtDelete directories recursively:
rm -r myfolderForce 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!
