Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français
Lire en français

Navigate and manage files on Linux

By updated

Improve this page

You are logged in to your server, facing the prompt, and the first thing to master is finding your way around the tree and handling files. Creating a directory, copying a configuration file, moving a backup, deleting a temporary file: these moves come back dozens of times a day in Linux administration. This guide shows you the essential commands to do them. If the terminal or the prompt mean nothing to you yet, start with Open a terminal and understand the prompt.

What you will learn

  • Locate yourself in the tree with pwd
  • Move between directories with cd
  • List files and directories with ls and its key options
  • Create files (touch) and directories (mkdir)
  • Copy (cp), move (mv) and delete (rm) files
  • Check the result of each operation

How do you find where you are and move around?

Unlike a graphical file manager, the terminal does not permanently show where you are. You are always positioned somewhere in the tree, the set of folders arranged as a tree from the root /. On Linux, "directory" is the usual word for "folder", and the one you are in is called the current directory: every command you type applies there by default. Two commands are enough for this: pwd tells you where you are, cd takes you elsewhere.

pwd: where am I?

At any moment, pwd (print working directory) tells you the directory you are in:

Terminal window
pwd
Output
/home/bob

It is the first reflex when you are lost: pwd puts you back in context.

cd: change directory

cd (change directory) is the fundamental navigation command. A path that starts with / starts from the root of the system: it is an absolute path. The double dot .. stands for the parent directory, and ~ for your home directory (the home). These are the forms to know:

Terminal window
cd /etc/ssh # go to a directory by absolute path
cd .. # go up one level (parent directory)
cd ~ # go back to your home (/home/bob)
cd - # go back to the previous directory
cd # same as cd ~ (back home)

After each cd, run pwd to confirm your position.

Terminal window
cd /var/log
pwd
Output
/var/log

One last shortcut is worth adopting straight away: cd - takes you back to the last directory visited and prints the destination path on the way. It is handy when you switch back and forth between two places, a configuration and the log of the service it drives, for example.

Terminal window
cd /etc/ssh
cd /var/log
cd -
Output
/etc/ssh

To understand the difference between absolute and relative paths, read the Absolute and relative paths guide.

How do you list files with ls?

ls (list) shows the contents of a directory. Without an option, it shows the names of files and folders:

Terminal window
ls
Output
Documents Images Projects script.sh

Essential options

Six options are enough for everyday use. The table says what each one does and in which situation to choose it.

OptionEffectWhen to use it
-lLong format (permissions, owner, size, date)Check permissions or size
-aShows hidden files (starting with .)See .bashrc, .ssh/, etc.
-hHuman-readable sizes (1K, 234M, 2G)With -l to read sizes quickly
-tSorts by modification date (newest first)Find the last modified file
-rReverses the sort orderWith -t to get the oldest first
-RRecursive listing (subdirectories included)Explore a tree

Common combinations

Options stack behind a single dash, in any order: ls -la and ls -al give the same result. Here are the four combinations you will type most often.

Terminal window
ls -la # see everything, long format (hidden files included)
ls -lh # long format with readable sizes
ls -lt # long format, sorted by date
ls -ltr # long format, sorted by date (oldest first)

Here is an example on /etc/ssh/, which holds the SSH configuration. It assumes the openssh-server package is installed: without it you will have neither sshd_config nor the host keys, and you can try ls -lah /etc/ instead.

Terminal window
ls -lah /etc/ssh/
Output
total 632K
drwxr-xr-x 4 root root 4,0K 15 nov. 19:03 .
drwxr-xr-x 1 root root 4,0K 15 nov. 19:03 ..
-rw-r--r-- 1 root root 1,7K 6 mai 2026 ssh_config
-rw-r--r-- 1 root root 3,4K 6 mai 2026 sshd_config
-rw------- 1 root root 411 15 nov. 19:03 ssh_host_ed25519_key
-rw-r--r-- 1 root root 99 15 nov. 19:03 ssh_host_ed25519_key.pub

This output is an extract, taken on Debian 13 (openssh-server 10.0p1, locale fr_FR.UTF-8), which is why the dates and decimals are in French. On your machine the list is longer, and the sizes, dates and permissions differ. The . and .. lines appear because of -a: they are the directory itself and its parent.

Look at the first column first, the permissions. The private key ssh_host_ed25519_key is -rw-------: only root can read it. The public key .pub and the sshd_config file are -rw-r--r--: everyone can read them.

Then look at the date. The month names (nov., mai) and the decimal comma (4,0K) come from the language of the system: in English you will read Nov 15 and 4.0K, with the month before the day. For a file modified more than six months ago, ls shows the year (2026) instead of the time.

Reading the output of ls -l

This dense line is the one you will read most often in administration, so it is worth decoding once and for all. The first character gives the type of the entry, the next nine its permissions, then come the owners, the size and the date of the last modification. The detail of the nine permission characters is in Linux permissions.

-rw-r--r-- 1 root root 1,7K 6 mai 2026 ssh_config
│ │ │ │ │ │ │
│ │ │ │ │ │ └─ file name
│ │ │ │ │ └─ modification date
│ │ │ │ └─ size
│ │ │ └─ owning group
│ │ └─ owning user
│ └─ number of links (not important for now)
└─ type and permissions (d = directory, - = file, l = link)

How do you create files and directories?

On Linux, creating a file and creating a directory are two distinct operations, with two distinct commands. Neither opens an editor or asks for confirmation: they run silently, and it is up to you to check the result with ls. Above all, remember the -p option of mkdir, the one that saves you from creating directories one by one.

touch: create an empty file

touch creates an empty file if it does not exist. If it already exists, it only updates its modification date:

Terminal window
touch /tmp/my-file.txt
ls -l /tmp/my-file.txt
Output
-rw-rw-r-- 1 bob bob 0 Apr 6 14:30 /tmp/my-file.txt

The 0 is the size: the file is empty. The rw-rw-r-- permissions assume a umask of 002. The umask is the mask that removes rights from new files (type umask to read yours; the principle is explained in Linux permissions). With a umask of 022, you would read rw-r--r--. The same umask explains the drwxrwxr-x permissions of a directory, which you will see below.

mkdir: create a directory

mkdir (make directory) creates one or more directories:

Terminal window
mkdir /tmp/my-folder

The -p option creates the whole intermediate tree if it does not exist:

Terminal window
mkdir -p /tmp/project/src/config

Without -p, the command would fail if a parent directory did not exist (/tmp/project/ or /tmp/project/src/).

Check with ls -ld, where -d asks to show the directory itself rather than its contents:

Terminal window
ls -ld /tmp/project/src/config
Output
drwxrwxr-x 2 bob bob 4096 Apr 6 14:35 /tmp/project/src/config

How do you copy files and directories?

Copying a configuration file before editing it is the basic reflex of administration: it is your only way back if the service refuses to restart. Two details make all the difference with this command: without the -r option it refuses to handle a directory, and without -p (or -a) the copy keeps neither the dates nor the original owner.

cp: copy

cp (copy) copies a file or a directory. The first argument is the source, the second the destination:

Terminal window
cp /etc/ssh/ssh_config /tmp/ssh_config.bak

The options of cp to know:

OptionEffect
-rRecursive copy (required for directories)
-pPreserves permissions, dates and, if you have the right to, the owner
-aArchive: recursive copy that preserves all attributes (equivalent to -dR --preserve=all)
-iAsks for confirmation before overwriting an existing file
-vShows each copied file (verbose)

The -a option is the one for a faithful backup: it copies the whole tree and keeps the permissions, the dates, the hard links and the extended attributes.

With -r alone, it is the opposite: the copy receives the permissions of the original file, reduced by the umask, today's date and the name of the user who makes it.

For a configuration directory, as in the example below, cp -rp is enough; -a is worth it when links and attributes matter too. One limit applies to -p as to -a: only root can keep the owner of a file that belongs to another user. Copied by an ordinary user, the file belongs to that user.

To copy a whole directory, for example /etc/nginx/ if nginx is installed on your machine (otherwise, take another directory of /etc):

Terminal window
cp -rp /etc/nginx/ /tmp/nginx-backup/

Check the result:

Terminal window
ls -la /tmp/nginx-backup/

How do you move or rename a file?

Linux has no "rename" command: moving a file and renaming it are the same operation, carried out by mv. Changing the name simply means moving the file to a path whose last element differs. Like cp, this command overwrites the destination without warning if it already exists.

mv: move or rename

mv (move) is used both to move and to rename:

Terminal window
# Rename a file
mv /tmp/old-name.conf /tmp/new-name.conf
# Move a file into a directory
mv /tmp/file.txt /tmp/project/
# Move and rename at the same time
mv /tmp/draft.txt /home/bob/Documents/final-report.txt

The useful options of mv:

OptionEffect
-iAsks for confirmation before overwriting
-nNever overwrites an existing file
-vShows each operation (verbose)
Terminal window
mv -v /tmp/test /tmp/test-renamed
Output
renamed '/tmp/test' -> '/tmp/test-renamed'

How do you delete files and directories?

This is the section where attention matters most: on the command line there is no trash can and no undo. A successful deletion does not even print a message, which makes a mistake all the more discreet. Two commands exist: rm, which deletes files (and directories with -r), and rmdir, which refuses to touch a non-empty directory.

rm: delete

rm (remove) deletes files. It is irreversible.

Terminal window
rm /tmp/temporary-file.txt

The options of rm:

OptionEffect
-rRecursive deletion (needed for directories)
-iAsks for confirmation for each file
-fForces deletion without confirmation
-vShows each deletion
Terminal window
# Delete a directory and its contents
rm -r /tmp/test-project/
# Delete with confirmation
rm -ri /tmp/important-folder/

rmdir: delete an empty directory

rmdir only deletes empty directories. It is safer than rm -r when you know the folder should be empty:

Terminal window
rmdir /tmp/empty-folder

If the directory contains files, rmdir refuses and prints an error, which protects you from an accidental deletion.

Practical exercise

This sequence replays every command in the guide on a disposable tree created in /tmp, the directory for temporary files: nothing you do there affects the system. Type the commands rather than pasting them, and always run the check shown before moving on to the next step. The last step cleans everything up.

  1. Create a working tree:

    Terminal window
    mkdir -p /tmp/lab-files/{config,backup,logs}

    The braces {config,backup,logs} are expanded by the shell: mkdir receives three paths, /tmp/lab-files/config, /tmp/lab-files/backup and /tmp/lab-files/logs.

    Check with ls -R /tmp/lab-files/ (-R goes down into the subdirectories).

  2. Create test files:

    Terminal window
    touch /tmp/lab-files/config/app.conf
    touch /tmp/lab-files/config/db.conf
    touch /tmp/lab-files/logs/app.log
  3. Copy the configuration into the backup:

    Terminal window
    cp -rp /tmp/lab-files/config/ /tmp/lab-files/backup/config-2026/

    Check with ls -la /tmp/lab-files/backup/config-2026/.

  4. Rename a file:

    Terminal window
    mv /tmp/lab-files/config/app.conf /tmp/lab-files/config/application.conf

    Check with ls /tmp/lab-files/config/.

  5. Delete the logs:

    Terminal window
    rm /tmp/lab-files/logs/app.log
    rmdir /tmp/lab-files/logs

    Check with ls /tmp/lab-files/: the logs folder is gone.

  6. Clean everything up:

    Terminal window
    rm -r /tmp/lab-files

Troubleshooting

The error messages of these commands are short but precise: they almost always name the file at fault and the reason for the refusal. Get into the habit of reading them in full before running the command again: the message already tells you which option is missing or which right you lack. Depending on the system language, they may appear in French. Here are the seven you will meet first, with the matching fix.

SymptomLikely causeFix
No such file or directoryWrong path or typoCheck with ls and pwd, use the Tab key for completion
Permission deniedInsufficient permissions on the file or directoryCheck with ls -la, use sudo if needed
cp: -r not specified; omitting directory '/tmp/project'Missing -r option to copy a directoryUse cp -r source/ destination/
rm: cannot remove '/tmp/project': Is a directoryrm without -r on a directoryUse rm -r directory/
rmdir: failed to remove '/tmp/project': Directory not emptyThe directory contains files (maybe hidden ones)Check with ls -a, then use rm -r if you are sure
mkdir: cannot create directory '/tmp/project': File existsThe directory already existsNothing to fix if you wanted that directory: it is already there. With -p, mkdir no longer reports an error
File overwritten by cp or mvNo confirmation askedAlways use -i on important files

Put it into practice

Handling files without a safety net is exactly what a disposable environment allows: nothing to break, everything to learn. The lab gives you a target tree and has you build it from scratch in your working directory, with cd, ls, mkdir, cp, mv and rm. The validation checks every path: a file with the right name in the wrong place does not count, and neither does an extra file. In the course on AI-generated applications, this lab is optional.

Key points

  • pwd tells you where you are, cd moves you, ls shows the contents.
  • ls -lah is a very common combination: long format, hidden files, readable sizes.
  • mkdir -p creates a whole tree in one command.
  • cp -rp copies a directory while preserving permissions and dates, the reflex for backups; cp -a also keeps links and attributes. Only root also keeps the original owner.
  • mv both moves and renames.
  • rm is irreversible: check with ls before deleting, prefer rm -i when in doubt.
  • After each operation, check the result with ls -la.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer