Skip to content

Theme color

Files

Command Effect
cat file Prints the whole file.
less file Pages through a file. / searches, q quits.
head -n 10 file Prints the first 10 lines.
tail -n 10 file Prints the last 10 lines.
tail -f file Keeps printing new lines as the file grows, e.g. for logs.
touch file Creates an empty file, or updates the timestamps of an existing one.
ln -s /path/to/target link Creates a symbolic link link pointing to the target.
stat file Size, permissions, owner and all timestamps.
file file Detects the file type from the content.
flowchart LR
  sym[symlink] -->|path| name1[file.txt]
  name1 --> inode[(inode<br/>data)]
  hard[hardlink] --> inode

A symbolic link (ln -s) stores a path. It can point to directories and across filesystems, but breaks when the target is moved or deleted. A hard link (ln) is a second name for the same inode: the data stays until the last name is deleted, but it only works within one filesystem and not for directories.