---
title: "Linux Essentials"
description: "The Linux fundamentals you use every day: flags and manuals, creating and moving files, reading permissions, switching users, and what /etc, /var, /root, and /tmp mean for security."
url: "https://davidezambiasi.dev/notes/linux-essentials"
---

Article

# Linux Essentials

The Linux fundamentals you use every day: flags and manuals, creating and moving files, reading permissions, switching users, and what /etc, /var, /root, and /tmp mean for security.

Published October 11, 2025 · 5 min read

Originally published on [Hashnode](https://blog.davideai.dev/linux-essentials).

Working with Linux is mostly about using commands — and knowing what they do, how to tweak them with flags, and where things live on disk. This article collects the fundamentals you’ll use every day: how flags and manuals work, how to create/copy/move/delete files and folders, how to read permissions and switch users, and what the important root directories (/etc, /var, /root, /tmp) contain and mean for security.

## TL;DR

-   Flags change a command’s behaviour (`-a` vs `--all`). Use `--help` and `man` to learn options.
-   Create files with `touch`, directories with `mkdir`. Copy with `cp`, move/rename with `mv`, delete with `rm`.
-   Read permissions with `ls -l` (r, w, x for owner/group/others). Use `su` or `su -l` to switch users.
-   /etc holds config (sensitive), /var holds logs/data, /root is root’s home, /tmp is world-writable (sticky bit).

## 1) Flags, switches, and manuals — how commands accept options

Short-form flags start with a single hyphen followed by a letter: `-a`.

Long form switches start with two hyphens and full words: `--all`.

Quick ways to learn a command:

```bash
# short help summary
ls --help

# full manual (press q to quit)
man ls
```

Example: `ls` lists directory contents by default. `ls -a` or `ls --all` shows hidden files (those that begin with a dot).

## 2) Filesystem basics — create, copy, move, delete, inspect

### Create files and directories

```bash
# create an empty file
touch note

# create a directory
mkdir mydirectory
```

`touch` makes a blank file; use `echo`, `cat >`, or a text editor (nano, vim) to add content.

### Copy and move

```bash
# copy file
cp source_file dest_file

# copy directory recursively
cp -r source_dir dest_dir

# move or rename file/directory
mv oldname newname
mv file.txt /path/to/folder/
```

### Remove (be careful)

```bash
# delete a file
rm file.txt

# delete a directory and its contents (destructive)
rm -R directory_name

# safer: prompt before deleting
rm -i file.txt
```

### Determine a file’s type

```bash
file filename
# example output: "note: ASCII text"
```

## 3) Permissions 101 — reading `ls -l`

Run:

```bash
ls -lh
```

Sample line:

```plaintext
-rw-r--r-- 1 alice developers 1024 Feb 19 10:37 note
```

Breakdown:

-   First character: file type (`-` file, `d` directory, `l` symlink).
-   Next nine characters: permissions in three groups of three:
    -   Owner (user): `rw-` → read, write, no execute
    -   Group: `r--` → read only
    -   Others: `r--` → read only

Permission symbols: r (read), w (write), x (execute), `-` (no permission).

Useful commands:

```bash
stat file.txt            # show detailed mode/owner/timestamps
chmod 644 file.txt       # owner rw, group r, others r
chmod 755 script.sh      # owner rwx, group rx, others rx
sudo chown user:group file.txt  # change owner and group
```

## 4) Switching users

`su` allows you to become another user (requires that user’s password unless you are root).

```bash
# switch to user2 (keeps current environment)
su user2

# full login shell (use home directory and environment of the target user)
su -l user2
# or
su --login user2
```

`su -l` drops you into the target user’s home and loads their login environment (PATH, shell init files, etc.).

## 5) Common root directories — purpose, importance, and quick checks

### /etc — system configuration

-   Stores service and system config: network, auth, service configs.
-   Files of interest: /etc/passwd (accounts metadata), /etc/shadow (password hashes, root-only), /etc/sudoers and /etc/sudoers.d (sudo rules).

```bash
ls -l /etc | head
cat /etc/passwd
sudo cat /etc/shadow   # requires root
```

**Security note:** /etc/shadow is sensitive — access implies root-level compromise.

### /var — variable data and logs

-   Contains logs (/var/log), caches, databases, spool files.
-   Logs show system and app activity — useful for debugging and auditing.

```bash
ls -lh /var/log | head
sudo tail -n 200 /var/log/syslog
# or on systemd systems:
sudo journalctl -n 200
```

**Security note:** misconfigured apps may leak secrets into logs.

### /root — root user’s home

-   The admin’s home directory. Not /home/root.

```bash
ls -la /root    # normally permission denied unless root
```

**Security note:** if you can read /root, you likely have root access.

### /tmp — temporary files (world-writable)

-   Meant for short-lived files; usually cleared on reboot.
-   Typically has sticky bit: `drwxrwxrwt` — anyone can create files, only owner/root can delete them.

```bash
ls -ld /tmp
[ -w /tmp ] && echo "/tmp writable" || echo "/tmp not writable"
mktemp /tmp/mytmp.XXXXXX  # create a secure temporary file
```

**Security note:** never trust scripts or files placed in /tmp; prefer mktemp for temporary files.

## 6) Compact cheatsheet (copy/paste)

```bash
# Learn command options
<cmd> --help
man <cmd>

# File & directory ops
touch file.txt
mkdir folder
cp source dest
cp -r sourcedir destdir
mv oldname newname
rm file.txt
rm -R directory_name
rm -i file.txt

# File info
file file.txt
ls -lh
ls -la

# Permissions & ownership
stat file.txt
chmod 644 file.txt
chmod 755 script.sh
sudo chown user:group file.txt

# Switch users
su otheruser
su -l otheruser

# Important directories quick checks
ls -l /etc /var /root /tmp
ls -lh /var/log | head
sudo tail -n 200 /var/log/syslog
ls -ld /tmp

# Security-focused discovery (use with sudo)
sudo find / -perm -4000 -type f 2>/dev/null | head
sudo find / -xdev -type d -perm -0002 -ls 2>/dev/null | head
```

## 7) Security reminders & best practices

-   Treat /etc/shadow, SSH keys, and config files as high-value targets. Protect them.
-   `rm -R` (or `rm -rf`) is destructive — double-check paths before running.
-   Use `mktemp` to create unpredictable temporary filenames (avoid race conditions).
-   Logs in /var/log may contain secrets; don’t expose them in public repos.
-   Prefer `sudo` for temporary elevation; avoid running a long-lived root shell unless necessary.

## 8) Example workflow (quick practical scenario)

1.  Inspect the current directory and hidden files:
    
    ```bash
    ls -la
    ```
    
2.  Create a workspace, move a file into it, and verify:
    
    ```bash
    mkdir workspace
    mv note workspace/
    ls -lh workspace
    ```
    
3.  Check if the file is text and read it:
    
    ```bash
    file workspace/note
    cat workspace/note
    ```
    
4.  If you need elevated config access, view /etc/sudoers safely:
    
    ```bash
    sudo visudo   # edits /etc/sudoers with syntax checking
    ```
    

## Final notes

This guide gives you a concise, practical foundation: flags and manuals, the basic file operations you’ll use daily, how to read and change permissions safely, and the root directories you should know about.

DZ

Davide Zambiasi

Senior Developer Relations Engineer

I ship the docs, guides, and example apps that get developers building, and I hire for the roles that do the same.

[GitHub](https://github.com/soos3d)[LinkedIn](https://www.linkedin.com/in/davide-zambiasi)[Blog](https://blog.davideai.dev)

[

SpectraCoreX

Previous Page

](/notes/spectracorex)[

Run LLMs locally with Ollama

Next Page

](/notes/run-llms-locally-with-ollama)
