On this page

mkdir — make directories

mkdir creates a new directory.

$ mkdir projects
$ ls -d projects
projects

The -p flag creates parent directories on the way:

$ mkdir -p projects/2026/reports
$ ls -d projects/2026/reports
projects/2026/reports

touch — create empty files

touch creates an empty file, or updates the timestamp of an existing file.

$ touch todo.txt
$ ls -l todo.txt
-rw-r--r-- 1 user user 0 Aug  5 10:00 todo.txt

Running touch on an existing file just updates its modification time — it does not change the contents.

cp — copy

cp copies files and directories.

$ cp todo.txt todo-backup.txt
$ ls todo*.txt
todo-backup.txt  todo.txt

To copy a directory you need -r (recursive):

$ cp -r projects projects-backup

Other useful flags:

Flag Meaning
-r recursive (needed for directories)
-v verbose — show what is being copied
-i ask before overwriting an existing file
-p preserve permissions and timestamps
-a archive mode — recursive, preserves everything

Without -i, cp overwrites existing files silently:

$ cp new.txt old.txt   # old.txt is overwritten, no question asked

mv — move or rename

mv moves a file to another location, or renames it.

$ mv todo-backup.txt old-notes.txt   # rename
$ mv old-notes.txt archive/          # move into a directory

Like cp, mv overwrites existing files silently — use -i to be asked first.

rm — remove

rm deletes files permanently. There is no recycle bin and no undo.

$ rm todo.txt

Deleting a directory requires -r (recursive):

$ rm -r projects
Flag Meaning
-r recursive (needed for directories)
-f force — don’t ask, ignore missing files
-i ask before each deletion
-v verbose

rm -rf is powerful and dangerous — it deletes a directory tree without asking. Double-check the path before you run it:

$ rm -rf projects-backup

Graphical alternative: in most file managers, deleting sends files to a trash folder instead of deleting them permanently. rm does not.

ln creates links. A hard link is an additional name for the same file content — both names point to the same data:

$ echo hello > original.txt
$ ln original.txt hardlink.txt
$ cat hardlink.txt
hello

A symbolic link (symlink, soft link) is a shortcut that points to a path. It is created with -s:

$ ln -s original.txt shortcut.txt
$ ls -l shortcut.txt
lrwxrwxrwx 1 user user 12 Aug  5 10:00 shortcut.txt -> original.txt

Symbolic links are the more common type: they work across filesystems and clearly show what they point to (-> target). If the target is removed, a symlink dangles; a hard link keeps the data alive until all its names are removed.

file — what kind of file is this?

file examines a file and tells you what it actually is. This is handy when a file has an unfamiliar or missing extension:

$ file notes.txt
notes.txt: ASCII text
$ file script.sh
script.sh: Bash script, ASCII text executable
$ file archive.gz
archive.gz: gzip compressed data

file reads the file’s contents, not just its name — so a text file renamed to .pdf is still reported as text.