Skip to content

Managing Files

All files on a Linux system are stored on a file system. The / directory is the root directory at the top of the file-system. Static content remains unchanged until edited or reconfigured. Dynamic or variable content may be modified or appended by active processes, typically kept under /var.

Persistent content remains after a reboot, like configuration settings, which might include the /etc directory used to keep configuration files.

Runtime content is either process or system-specific content that is deleted by a reboot, found under /run for example.

Regular commands and utilities are found in /usr/bin whereas installed programs and libraries are under /usr.

Command Description
mkdir Create a directory
cp Copy a file
cp -r Copy a directory and its contents
mv Move or rename a file or directory
rm Remove a file
rm -r Remove a directory containing files
dir Remove a directory containing files

It is possible to create multiple names that point to the same file. There are two ways to do this: by creating a hard link to the file, or by creating a soft link (sometimes called a symbolic link ) to the file. Each has its advantages and disadvantages.

Every file starts with a single hard link, from its initial name to the data on the file system. When you create a new hard link to a file, you create another name that points to that same data. The new hard link acts exactly like the original file name. Once created, you cannot tell the difference between the new hard link and the original name of the file.

ln existing_sraget_file hard_link_path_name
* hard links can only be used with regular files. * hard links can only be used if both files are on the same file system.

The ln -s command creates a soft link, which is also called a "symbolic link." A soft link is not a regular file, but a special type of file that points to an existing file or directory.

Soft links have some advantages over hard links:

  • They can link two files on different file systems.
  • They can point to a directory or special file, not just a regular file.

Summary

Files on a Linux system are a single inverted tree of directories, known as a file-system hierarchy. Absolute paths start with a / and specify the location of a file in the file-system hierarchy. Relative paths do not start with a / and specify the location of a file relative to the current working directory. Hard links and soft links are different ways to have multiple filenames point to the same data.

Command References:

mkdir, rmdir, cp, mv and rm.