Updated: 22 October 2026 · Applies to: Linux and Unix, bash
These are the fundamental file and directory management commands every Linux or Unix user needs.
1. List files: ls
ls
Lists files and directories in your current directory. Add -R to list recursively through subdirectories, or -al for a detailed, columnar listing:
ls -R ls -al
In ls -al output, the columns are:
- File type and access permissions
- Number of hard links to the file
- Owner
- Owner's group
- File size in bytes
- Date and time of last modification
- File or directory name
2. List hidden files
ls -a
On Linux and Unix, a hidden file or directory is simply one whose name starts with a dot (.).
3. Create, view and combine files: cat
Create a new file and type content into it directly, then press Ctrl+D to stop and save:
cat > filename
View a file's contents:
cat filename
Combine two files into a new one:
cat file1 file2 > newfilename
The shell does not print a confirmation after this; if nothing went wrong, nothing is shown. Check the result by viewing the new file:
cat newfilename
cat only works reliably this way on plain text files.
4. Delete a file: rm
rm filename
rm deletes without asking for confirmation by default.
5. Move and rename a file: mv
mv filename new_file_location
The same command renames a file when the destination is just a new name in the same directory:
mv filename newfilename
If you get a permission error moving or renaming a file you do not own, run it with sudo:
sudo mv filename newfilename
sudo runs a single command with root privileges after you authenticate with your own password, not the root password.
6. Directory basics
Create a directory in your current location:
mkdir directoryname
Create a directory at a specific path, and more than one at a time:
mkdir /path/to/directoryname mkdir dir1 dir2 dir3
7. Remove a directory: rmdir
rmdir directoryname
rmdir only removes an empty directory; delete its files and subdirectories first, or use rm -r directoryname to remove a directory and everything in it at once.
8. Rename a directory
mv renames directories the same way it renames files:
mv directoryname newdirectoryname
Other useful commands
man COMMAND: shows the manual page for a command, similar to a built-in help file.history: lists the commands you have run in the current terminal session.clear: clears the terminal screen.- Copy and paste in most terminal emulators: Ctrl+C to copy (where that does not send an interrupt), Ctrl+Shift+V or Shift+Insert to paste, or the terminal's own Edit menu.
Formatting a file for printing: pr
Useful options:
-x: split the output intoxcolumns.-h "header": use "header" as the report header.-t: suppress the header and top/bottom margins.-d: double-space the output.-n: number every line.-l page_length: set lines per page (default 56).-o margin: set the page margin.
pr -x filename pr -h "Header" filename pr -n filename
Printing a file
lp filename
or:
lpr filename
Installing software
Linux distributes software as packages; dependencies are usually separate packages that need installing too. On a Debian or Ubuntu system:
sudo apt-get update sudo apt-get install packagename
Sending mail from the terminal
Install mailutils first:
sudo apt-get install mailutils
Then send a message:
mail -s 'subject' -c 'cc-address' -b 'bcc-address' 'to-address'
Type the message body, then press Ctrl+D to finish composing and send it.