Linuxlab

mkdir, cp, mv, rm in Linux: working with files

Updated July 3, 2026

mkdir, cp, mv and rm create directories and copy, move and delete files.

Common cases

mkdir -p a/b/c        # create the whole directory tree
cp file file.bak      # copy it next to the original
cp -r src dst         # copy a directory with -r
mv old new            # move or rename
rm file               # delete a file
rm -r dir             # delete a directory and its contents

How it works: mv is a rename

Within one filesystem mv does not move the data: it only changes the name entry in the directory, which is why moving and renaming are the same operation. cp always makes a fresh copy of the data. rm removes a name, and when a file's last name is gone and no process holds it open, its inode is freed. rm has no trash can: what is deleted is gone, so before rm *.tmp it helps to check the pattern with ls *.tmp first.

Used in

You need this in the lesson Files and directories. The theory is the chapter Files and directories.

See also

Filename globbing, The ls command.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.