DEV Community

Rising Felix
Rising Felix

Posted on

Linux Basics for DevOps: Files, Directories and Permissions (Hands-On on Kali WSL)

I'm learning DevOps, and my first assignment was all about the Linux command line: moving around the file system, managing files, and understanding permissions. I worked through it on Kali Linux running in WSL (Windows Subsystem for Linux), and every screenshot below is real output from my terminal.

If you're just starting out, this is a compact tour of the commands you'll use every single day.

Tip for WSL users: work inside your Linux home folder (~), not on a Windows drive under /mnt/c. Windows drives don't support Linux permissions properly, so chmod won't behave as expected there.

Part 1: The Concepts

What is Linux?
An open-source, Unix-like operating system. It runs most of the world's servers, cloud infrastructure, containers and embedded devices, which is why it's the foundation of DevOps.

cp vs mv
cp copies a file, so the original stays put. mv moves or renames it, so the original is gone from its old location.

What does chmod do?
It changes a file's permissions: who can read, write or execute it.

Absolute vs relative paths

  • Absolute paths start from the root /, for example /home/p0cx/notes.txt.
  • Relative paths start from where you are now, for example docs/notes.txt.

ls -la
Lists all files, including hidden ones that start with ., in long format: permissions, owner, size and date.

r, w, x

Letter On a file On a directory
r (read) view contents list contents
w (write) modify add or delete files inside
x (execute) run it as a program enter it with cd

mkdir creates a directory.

rm vs rmdir
rm deletes files (and whole directories with -r). rmdir only removes empty directories.

File extensions are the suffix that hints at a file's type: .txt, .sh, .log, .py, .pdf.

sudo runs a command with administrator (root) privileges.

Part 2: Command Cheat Sheet

# Task Command
1 Show current directory pwd
2 List files and directories ls
3 Create a directory mkdir linux_lab
4 Create an empty file touch notes.txt
5 Show a file's contents cat notes.txt
6 Copy a file cp notes.txt backup.txt
7 Rename a file mv backup.txt report.txt
8 Delete a file rm old.txt
9 Add execute for the owner chmod u+x script.sh
10 Show logged-in user whoami
11 Show OS information uname -a
12 Show disk space df -h
13 Show memory usage free -h
14 Find a file in the directory tree find . -name error.log
15 Show the first 10 lines of a file head app.log

Who am I, and where am I?

pwd, ls, whoami and uname -a. Note the kernel string microsoft-standard-WSL2: that's how you can tell you're inside WSL.

Screenshot 1: pwd, ls, whoami and uname -a in Kali WSL

Creating, copying, renaming and deleting files

I created linux_lab, added two files, wrote a line into notes.txt, then copied, renamed and deleted. The final ls -l confirms old.txt is gone and report.txt exists.

Screenshot 2: mkdir, touch, cat, cp, mv and rm

Permissions, searching and reading logs

Watch the permission string on script.sh change from -rw-r--r-- to -rwxr--r-- after chmod u+x. Only the owner gained execute. find locates error.log in a subfolder, and head stops at line 10 of a 20-line log.

Screenshot 3: chmod u+x, find and head

Disk and memory

df -h and free -h print sizes in human-readable units (G, M, K) instead of raw bytes. In WSL, df also shows your Windows drives mounted under /mnt/c and /mnt/d.

Screenshot 4: df -h and free -h

Part 3: Hands-On Exercises

Task 1: Build a project structure

cd ~
mkdir DevOps
mkdir DevOps/Scripts DevOps/Logs DevOps/Backup
touch DevOps/Scripts/deployment.sh
touch DevOps/Logs/application.log
ls -R DevOps
Enter fullscreen mode Exit fullscreen mode

ls -R lists the whole tree recursively. It's a quick way to verify the structure.

Screenshot 5: DevOps folder structure with ls -R

Task 2: Write, copy and rename

cd ~/DevOps
echo "This is my first Linux assignment" > Scripts/deployment.sh
cp Scripts/deployment.sh Backup/
mv Backup/deployment.sh Backup/deployment_backup.sh
cat Backup/deployment_backup.sh
Enter fullscreen mode Exit fullscreen mode

> redirects output into a file and overwrites it. Use >> if you want to append instead.

Screenshot 6: copying and renaming deployment.sh

Task 3: 755 vs 644

ls -l Scripts/deployment.sh
chmod 755 Scripts/deployment.sh
chmod 644 Scripts/deployment.sh
Enter fullscreen mode Exit fullscreen mode

Screenshot 7: chmod 755 then chmod 644

Each digit is the sum of r = 4, w = 2, x = 1, for owner, group and others in that order:

Mode String Owner Group Others Typical use
755 rwxr-xr-x read, write, execute read, execute read, execute scripts and programs
644 rw-r--r-- read, write read read config and text files

The difference: 755 makes the file executable, while 644 leaves it as a plain, non-executable file that only the owner can edit.

Part 4: Permissions Challenge

  • chmod 777 file.txt: everyone can read, write and execute. Almost never a good idea.
  • chmod 600 secret.txt: only the owner can read and write; nobody else has access. This is ideal for private keys and credentials.
  • chmod u+x deploy.sh: adds execute permission for the owner only.
  • chmod -R 755 project/: applies rwxr-xr-x to project/ and everything inside it.
  • -rw-r--r-- β†’ -rwxr-xr-x: chmod 755 file (or chmod +x file).

Why not give everyone write access to sensitive files?
Because anyone, or any compromised process, could change, corrupt or delete them, or inject malicious code. Follow the principle of least privilege: grant only the access each user actually needs.

Wrapping Up

These commands are the foundation for everything that comes next in DevOps, from shell scripting to CI/CD pipelines and container work. The best way to make them stick is to type them yourself, break things, and run ls -l to see what happened.

What was the first Linux command that tripped you up? Let me know in the comments. πŸ‘‡

Top comments (0)