Skip to content

01. File Management and Manipulation

Overview

This document covers essential Linux commands used for:

  • Navigating directories

  • Managing files and folders

  • Viewing and modifying content

These are foundational for system administration, scripting, and cybersecurity tasks.


Directory Navigation

pwd — Present Working Directory

pwd

Explanation
Displays the full path of your current working directory.


cd — Change Directory

cd /path/to/directory

Explanation
Moves from the current directory to another specified directory.


Move Up Directory Levels

cd ..
cd ../..
cd ../../..

Explanation

  • .. → move up one level

  • ../.. → move up two levels

  • Continue pattern as needed


Special Navigation Paths

cd ~
  • Takes you to the home directory
cd /
  • Takes you to the root directory

Listing Directory Contents

ls — List Files

ls

Explanation
Displays files and directories in the current location.


ls -l — Detailed List

ls -l

Shows

  • File type (file/directory)

  • Permissions

  • Number of links

  • Owner and group

  • File size

  • Last modified date

  • File name


ls -a — Show Hidden Files

ls -a

Explanation
Includes hidden files (those starting with .)


ls -la — Detailed + Hidden

ls -la

Explanation
Combines -l and -a for full visibility.


ls -lh — Human Readable Sizes

ls -lh

Explanation
Displays sizes in KB, MB, GB instead of bytes.


ls -lR — Recursive Listing

ls -lR /path

Explanation
Lists all files and subdirectories recursively.


File Handling

touch — Create File

touch filename.txt

Explanation
Creates an empty file if it does not exist.


file — Identify File Type

file filename

Examples Output

  • ASCII text

  • ELF binary

  • Shell script


Check Multiple Files

file ./*

Viewing and Writing Content

echo — Print Text

echo "Hello World"

Write to File (Overwrite)

echo "Hello" > file.txt

Explanation

  • > overwrites existing content

Append to File

echo "New Line" >> file.txt

Explanation

  • >> adds content without deleting existing data

cat — View File Content

cat file.txt

Create File Using cat

cat > file.txt

(Type content → Press CTRL + D to save)


Copy File Content

cat file1.txt > file2.txt

Append Using cat

cat >> file.txt

Directory Management

mkdir — Create Directory

mkdir dirname

File and Directory Operations

cp — Copy Files

cp file.txt /path/to/directory

Explanation
Copies a file to another location.


mv — Move or Rename

Move File

mv file.txt /path/to/directory

Rename File

mv old.txt new.txt

rm — Remove File

rm filename

rmdir — Remove Empty Directory

rmdir dirname

rm -r — Remove Directory Recursively

rm -r dirname

rm -rf — Force Remove

rm -rf dirname

Important Warning

  • Deletes files/directories without confirmation

  • Use carefully, especially in production or pentesting environments


System Information

whatis — Command Description

whatis ls

Explanation
Displays a short description of a command.


Important Notes

  • Linux is case-sensitive

  • Always verify paths before deletion

  • Use ls before running destructive commands

  • Prefer backups (cp) before modifying files


Summary Table

Command Purpose
pwd Show current directory
ls List files
cd Change directory
touch Create file
cat View file content
echo Print/write text
mkdir Create directory
cp Copy files
mv Move/Rename files
rm Delete file
rmdir Delete empty directory
file Identify file type
whatis Show command description

Conclusion

These commands are the core foundation of Linux usage. They are heavily used in:

  • Shell scripting

  • DevOps workflows

  • Cybersecurity and penetration testing

Mastering them improves speed, efficiency, and control over any Linux-based environment.