By Manny Fernandez

March 24, 2026

Useful Linux Commands

In this post, I am going to go over basic Linux commands.  They may be a bit different depending on distro or platform.

📂 Navigation & File Management

These are the basics for moving around and organizing your digital space.

pwd – (Print Working Directory) Shows exactly where you are in the folder structure.

ls – Lists files in the current folder. Use ls -la to see hidden files and detailed info.

cd <folder> – Change directory. Use cd .. to move up one level.

mkdir <name> – Create a new folder.

touch <file> –  Create a new empty file.

cp <source> <dest> –  Copy files or folders. Use -r to copy a folder and everything inside it.

mv <source> <dest> – Move or rename a file/folder.

rm <file> – Delete a file. Use rm -rf for folders (be careful—there is no “Undo”!).

🔍 Searching & Viewing Files

When you need to find a needle in a haystack or just see what’s inside a document.

Command Action
cat –  Dumps the entire contents of a file to your screen.
less – Opens a file in a scrollable view (press q to exit).
head / tail – Shows the first or last 10 lines of a file.
greptext” – Searches for a specific string of text within a file.
find – Searches for files and directories based on name or size.

⚙️ System & Process Management

For when you need to know how your “engine” is running or stop a frozen program.

top or htop – Displays real-time system resources (CPU, RAM) and running tasks.

df -h – Shows how much disk space you have left in a human-readable format.

free -m –  Checks your available memory (RAM).

ps aux –  Lists every process currently running on the system.

kill <PID> – Stops a process using its Process ID number.

sudo – (Super User DO) Run a command with administrative privileges.

🌐 Networking

Useful for troubleshooting your internet or server connections.

ip addr – Shows your IP address and network interface details.

ping <host> – Checks if a server (like www.google.com) is reachable.

curl <URL> – Downloads content from the web or tests an API.

ssh <user>@<host> – Connects to a remote computer securely.

💡 Pro-Tips for Speed

Tab Completion: Start typing a filename and hit Tab – Linux will finish it for you.

The Up Arrow: Cycles through your previous commands so you don’t have to retype them.

history– Shows a list of everything you’ve typed recently.

man <command> – The “Manual.” Type this before any command to see the full instruction book for it.

🔗 The Power of Pipes (|)

The pipe takes the output of the command on the left and uses it as the input for the command on the right.

ls -la | less – If a folder has 500 files, ls will scroll past your eyes instantly. Piping it to less lets you scroll through that list manually.

ps aux | grep python – Shows every running process, but filters it to only show ones related to “python“.

cat access.log | grep "404" | wc -l

Read the .log file. Find all “404” errors.  Count the lines (wc -l) to tell you exactly how many errors occurred.

💾 Output Redirection (> and >>)

Sometimes you don’t want to see the result on the screen; you want to save it to a file.

ls > filenames.txtCreates (or overwrites) a file called filenames.txt with the list of files in your folder.

ip addr >> network_log.txtAppends your IP info to the end of a file without deleting what was already there. Useful for logging

Keyboard Shortcuts (The “Secret” Speed)

If you’re typing everything out, you’re working too hard. Try these:

Shortcut Action
Ctrl + C Kill the current running command (The “Emergency Stop“).
Ctrl + L Clears the terminal screen (same as typing clear).
Ctrl + A Jump the cursor to the start of the line.
Ctrl + E Jump the cursor to the end of the line.
Ctrl + R Search your command history (just start typing what you remember).

🚀 A Practical “Chain” Example

Imagine you want to find the 5 largest files in a directory and save that list to a file –
du -ah | sort -rh | head -n 5 > big_files.txt

du -ah – Calculate disk usage for all files.

sort -rh – Sort them in reverse (r) human-readable (h) order (biggest first).

head -n 5 – Grab only the top 5 results.

> big_files.txt –  Save that list to a file.

In Linux, everything is a file, and every file has a set of “locks” on it to determine who can do what. When you run ls -l, you’ll see a string of characters like -rwxr-xr--.

Understanding those 10 characters is the key to mastering Linux security.

🧩 Anatomy of a Permission String

The string is broken down into four distinct parts:

The Type (1st character) – means a regular file, d means a directory.

The User/Owner (next 3) – What the person who owns the file can do.

The Group (next 3) – What members of the file’s assigned group can do.

Others (last 3)  What everyone else on the system can do.

The Three Basic Permissions

r (Read): Permission to view the file contents or list a directory.

w (Write): Permission to modify the file or add/delete files in a directory.

x (Execute): Permission to run the file as a program or “enter” a directory.

🔢 The “Number System” (Octal Notation)
While letters are easy to read, Linux often uses numbers to set permissions. Each letter has a value:

4 = Read (r)

2 = Write (w)

1 = Execute (x)

0 = No permission (-)

You add them up to get a single digit for each category (User, Group, Others).

Permission Math Number
rwx 4 + 2 + 1 7 (Full access)
rw- 4 +2 + 0 6 (Read/Write)
r-x 4 + 0 + 1 5 (Read/Execute)
r-- 4 + 0 + 0 4 (Read only)

Example: chmod 755 script.sh

7 (User) – Read, Write, Execute.

5 (Group) – Read, Execute.

5 (Others) – Read, Execute.

🛠️ Commands to Change Permissions

chmod – (Change Mode) Changes the permissions.

Symbolic way – chmod u+x file (Adds execute permission for the user).

Numeric way – chmod 644 file (Standard for most files).

chown – (Change Owner) Changes who owns the file.

Example: sudo chown bob:devs file.txt (Makes “bob” the owner and “devs” the group).

Here is a quick-reference “Permission Calculator” for the most common scenarios you’ll encounter in Linux. These are the industry standards that balance accessibility with security.

🛡️ Common Permission Sets

Numeric Symbolic Description Common Use Case
777 rwxrwxrwx Everyone can do everything. ⚠️ Danger! Avoid this. Used only for temporary testing.
755 rwxr-xr-x Owner can edit; others can only read/run. Public Scripts & Programs (e.g., /usr/bin).
700 rwx------ Only the owner has any access. Private Scripts or sensitive tools.
644 rw-r--r-- Owner can edit; others can only read. Standard Files (HTML files, text documents).
600 rw------- Only the owner can read/write. SSH Private Keys (id_rsa) and secret configs.
444 r--r--r-- Everyone can read; no one can edit. Read-only logs or protected records.
400 r-------- Only the owner can read. Ultra-sensitive keys (e.g., .pem files for AWS).

🧮 How to “Build” Your Own Number

If you want a specific permission, just add the values for each of the three slots (User, Group, Others):

Step 1: Choose what the User can do (e.g., Read + Write = 6).

Step 2: Choose what the Group can do (e.g., Read only = 4).

Step 3: Choose what Others can do (e.g., Nothing = 0).

Result – chmod 640 filename

💡 The “Directory” Exception

Permissions work slightly differently for folders (directories) than for files:

Read (r): Allows you to ls (see what’s inside).

Write (w): Allows you to create or delete files inside.

Execute (x): This is the “Pass-through” bit. Without this, you cannot cd into the folder or access anything inside it, even if you have read permissions on the files.

Pro-Tip – Most web servers (like Nginx or Apache) require folders to be 755 and files to be 644 to function correctly without being “too open” to hackers.

Using the Recursive flag (-R) is a superpower in Linux. It allows you to apply a command to a folder, every file inside it, and every sub-folder within those, all at once.

However, it’s also a “double-edged sword”, if you run it on the wrong folder or with the wrong numbers, you can break your system’s access in a single keystroke.

🛠️ The Basic Recursive Command

The syntax is simple: add -R right after the command.

To change permissions: chmod -R 755 /path/to/folder

To change ownership: sudo chown -R user:group /var/www/html

⚠️ The “Recursive Trap”

There is a catch. Usually, you want folders to have different permissions than files (folders need +x to be searchable, but files often don’t). If you just run chmod -R 777, you make everything executable and insecure.

The Professional Way (Using find)

Instead of a “blind” recursive chmod, pros use the find command to target files and folders separately.

Fix all Folders to 755

This finds all directories (-type d) and sets them so they can be entered and listed.

find /path/to/folder -type d -exec chmod 755 {} +
2. Fix all Files to 644

This finds all files (-type f) and sets them so they can be read but not executed.

find /path/to/folder -type f -exec chmod 644 {} +

🛑 Important Safety Tips

Never run chmod -R on system directories like /etc, /bin, or /root. This will break your OS and likely prevent it from booting.

Double-check your path. Before running a recursive command, type pwd to make sure you are where you think you are.

The “Dry Run” Trick: If you’re using find, you can replace -exec … with -print to see a list of what would be changed before you actually do it.

 

 

 

 

Recent posts

  • If you've spent any time configuring user authentication on... Full Story

  • DNS is one of those technologies that quietly underpins... Full Story

  • BGP issues on FortiGate firewalls usually trace back to... Full Story

  • Every time your laptop talks to your router, a... Full Story

  • If you've spent any time configuring NAT on a... Full Story

  • If you have spent any time configuring firewall policies... Full Story

  • High availability on FortiGate is one of those features... Full Story

  • If you've configured SD-WAN on a FortiGate, you've almost... Full Story

  • FortiLink is the management protocol that turns a FortiSwitch... Full Story

  • FortiSwitches are pretty rock solid from Mean Time Between... Full Story

  • This is a quicky tip.  Have you ever gone... Full Story

  • DNS is one of those quiet pieces of internet... Full Story

  • This article is an updated version of the previous... Full Story

  • You will add ns2 as a secondary (slave) BIND9... Full Story

  • In the process of deploying my lab, I needed... Full Story

  • RFC 8805, used to be known as Self-Correcting IP... Full Story

  • Years back, I wrote an article about certificate pinning. ... Full Story

  • FortiGates have the ability to send alerts to Microsoft... Full Story

  • In this post, I am going to walk through... Full Story

  • Troubleshooting VoIP on a FortiGate can feel like trying... Full Story

  • Prior to FortiOS 7.0, there were three commands to... Full Story

  • In this post, I am going to go over... Full Story

  • What we are going to do:  We are going... Full Story

  • Choosing between FGCP (FortiGate Clustering Protocol) and FGSP (FortiGate... Full Story

  • Creating a VLAN on macOS (The "Pro" Move) A... Full Story

  • This blog post explores the logic behind how macOS... Full Story

  • Pretty Fly for a Wi-Fi Tell My Wi-Fi Love... Full Story

  • Part of my daily gig is creating BoMs (Bill-of-Materials)... Full Story

  • ICMP introduces several security risks, but careful filtering, rate... Full Story

  • The command diag debug application dhcps -1 enables full... Full Story

  • In the world of FortiOS, execute tac report is... Full Story

  • LLDP; What is it The Link Layer Discovery Protocol... Full Story

  • What it actually does When you run diagnose fdsm... Full Story

  • Monkey Bites are bite-sized, high-impact security insights designed for... Full Story

  • I have run macOS in macOS with Parallels but... Full Story

  • Don't be confused with my other FortiNAC posts where... Full Story

  • This is the third session in a multi-part article... Full Story

  • Today I was configuring key-based authentication on a FortiGate... Full Story

  • Netcat, often called the "Swiss Army knife" of networking,... Full Story

  • At its core, IEEE 802.1X is a network layer... Full Story

  • In case you did not see the previous FortiNAC... Full Story

  • This is our 5th session where we are going... Full Story

  • Now that we have Wireshark installed and somewhat configured,... Full Story

  • The Philosophy of Packet Analysis Troubleshooting isn't about looking... Full Story

  • 1. High-Level Overview The FortiGate Wireless Intrusion Detection System... Full Story

  • What MIMO Actually Does Multiple Input, Multiple Output (MIMO)... Full Story

  • A practitioner's tour of the diagnose, test, and fnsysctl... Full Story