5.4 Special Directories and Files

Key Takeaways

  • /tmp and /var/tmp hold temporary files; both commonly use the sticky bit so users cannot delete each other’s files
  • The sticky bit on a directory (often shown as t in the others-execute position) restricts deletion/rename to file owners (and root)
  • ls -d lists directory entries themselves instead of descending into their contents
  • ln -s creates a symbolic link—a pointer to another path that can cross filesystems and target directories
  • Broken symlinks remain as link files even if the target is missing—verify targets when troubleshooting
Last updated: July 2026

5.4 Special Directories and Files

Not every directory behaves like a private home folder. Shared temporary areas need extra rules so users cannot erase each other’s work. Shortcuts across the tree use symbolic links. Topic 5.4 focuses on /tmp, /var/tmp, the sticky bit, ls -d, and ln -s.

Temporary directories: /tmp and /var/tmp

DirectoryTypical rolePersistence note
/tmp/General temporary files for programs and usersOften cleared on reboot (policy varies)
/var/tmp/Temporary files that should survive longerMore likely to persist across reboots

Both locations are usually world-writable so any user can create temp files. Without an extra control, directory write permission would let User A delete User B’s file. The sticky bit solves that classic problem.

The sticky bit on directories

When sticky is set, users may still create files if the directory is writable, but they generally may delete or rename only their own files (root still can manage everything). That is why sticky directories fit shared temp space.

In ls -l output, sticky directories often look like:

drwxrwxrwt ... /tmp

The final t in rwxrwxrwt replaces the usual others-execute x. A capital T can appear if sticky is set without others-execute.

Symbol in others execute slotMeaning (directory)
tSticky bit set and others have execute
TSticky bit set without others execute
xOthers execute, no sticky
sudo chmod +t /var/tmp
sudo chmod 1777 /shared/dropbox

Octal 1000 adds sticky; 1777 is a common shared-scratch mode (sticky + wide rwx). Essentials wants recognition of sticky-on-directory for /tmp, not a deep setuid lesson.

Worked example: Alice creates /tmp/alice.out; Bob creates /tmp/bob.out. With sticky set, Bob cannot delete alice.out even though he can write to /tmp. He can still delete bob.out.

Sticky-bit scenarios

SituationSticky?Result
Bob runs rm /tmp/alice.outYes (t)Denied (not owner)
Same rm after sticky clearedNoBob can delete Alice’s file
Carol renames Dave’s file in a 1777 dropboxYesDenied
Carol deletes her own file thereYesAllowed
ls -ld /tmp                 # look for ...rwxrwt
touch /tmp/$USER-test
# other user: rm /tmp/<yours>-test → fails when sticky set
rm /tmp/$USER-test          # owner cleanup OK

Applications pick /var/tmp when a temp file should survive reboot; both directories commonly show sticky in ls -ld. If a classmate can delete your /tmp file, the first troubleshooting glance is whether sticky is still present on the directory.

Listing directories with ls -d

By default, ls dirname shows contents. ls -d shows the directory entry itself.

ls -ld /tmp
ls -ld /home/*/project
CommandTypical result
ls /tmpNames inside /tmp
ls -d /tmpJust the /tmp path
ls -ld /tmpLong listing for /tmp—mode bits (including sticky t) visible

Use ls -ld when you care about directory permissions, not a flood of temporary filenames.

Symbolic links with ln -s

A symbolic link stores a path pointing to another file or directory:

ln -s /usr/share/doc/demo/README.md ~/readme-link
ln -s /var/log ~/logs
FeatureSymbolic link (ln -s)
Points toA path (absolute or relative)
Can cross filesystems?Yes
Can link to directories?Yes
If target is removedLink remains but is broken

Long listings show type l and often linkname -> target:

lrwxrwxrwx 1 alice alice 12 Jul 23 10:00 docs -> /srv/docs

Link mode bits are commonly rwxrwxrwx; the target’s permissions still govern access to the real data when you follow the link.

Worked example: ln -s /home/alice/projects/notes/todo.txt ~/Desktop/todo.txt puts a Desktop shortcut on the real notes file. Move the real file without updating the link and the Desktop entry becomes broken.

Relative targets (ln -s ../shared/assets assets) travel with a project tree; absolute targets are better when link and target may move separately. ln -s /tmp/missing ~/broken-link still creates type l—fix the target or rm the pointer only. Always confirm with ls -l that you see -> pointing where you intended before you rely on the shortcut.

Hard links vs symlinks (awareness only)

Essentials emphasizes ln -s. Plain ln creates a hard link (same inode, usually same filesystem, not for directories). Shortcuts to directories or cross-filesystem pointers → think symbolic.

Practical checklist for Topic 5.4

  1. Expect /tmp and often /var/tmp to be sticky shared temp spaces.
  2. Recognize t / T in directory modes as sticky indicators.
  3. Use ls -ld to inspect a directory’s own mode.
  4. Create shortcuts with ln -s and verify with ls -l.
  5. Deleting a symlink removes the pointer, not necessarily the target.

Together with accounts (5.1–5.2) and chmod/chown (5.3), special directories and symlinks complete Topic 5. Quick self-check: ls -ld /tmp (expect sticky t), create a disposable ln -s, then remove only the link name when cleaning up.

Test Your Knowledge

Why do /tmp and similar shared temporary directories typically use the sticky bit?

A
B
C
D
Test Your Knowledge

Which command creates a symbolic link named website pointing to /var/www/html?

A
B
C
D
Test Your Knowledge

You need to see the permissions on the /tmp directory itself, not a list of files inside it. Which command is most appropriate?

A
B
C
D
Test Your Knowledge

In a long listing, a directory mode ends with t as in drwxrwxrwt. What does that primarily indicate?

A
B
C
D
Congratulations!

You've completed this section

Continue exploring other exams