Find and organize project files in Linux

Locate files using absolute and relative paths, and safely create, copy, move, and delete them.

🎯 Introduction

After uploading a project, you need to know where its files are and which copy a command will change. This article creates the linux-lab directory used throughout the course and uses common commands to organize project files and backups.


🧱 Where paths start

Linux organizes files and directories into a tree whose top level is the root directory, /. Directories contain files and other directories; files usually store content. A path beginning with / starts at the root directory and is called an absolute path. A relative path, such as notes/welcome.txt, starts at the current directory.

LocationCommon use
/homeRegular users' home directories, where you normally keep your work.
/etcSystem and service configuration.
/varData that changes during operation, such as /var/log.
/tmpTemporary files that may be removed automatically.
/optApplications or runtimes installed separately by an administrator.

In common forms such as ~/directory, the shell expands ~ to the current user's home directory. $HOME stores the same path. . means the current directory, and .. means its parent. /root is the administrator account's home directory.


🛠 Create a structured practice directory

Run these commands in the Ubuntu terminal. Spaces separate commands and arguments. The mkdir option -p also creates missing parent directories.

mkdir -p "$HOME/linux-lab/notes" "$HOME/linux-lab/logs"
cd "$HOME/linux-lab"
pwd
ls -la

cd changes directories, pwd shows your location, and ls lists directory contents. -l shows details, and -a includes hidden entries whose names begin with a dot. Double quotes keep the whole path as one argument, even if it contains spaces.

cd notes
pwd
cd ..
pwd

The first output should end in /linux-lab/notes; the second returns to /linux-lab. If you see No such file or directory, check your current location, capitalization, and spelling.


🧰 Copy, rename, and delete

touch creates an empty file if the target does not exist. Copying leaves the original in place; moving removes the original path. Moving to a new name within the same directory renames the file.

cd "$HOME/linux-lab"
touch notes/welcome.txt
cp notes/welcome.txt notes/welcome-copy.txt
mv notes/welcome-copy.txt notes/welcome-backup.txt
ls -l notes

To copy an entire directory, use cp -R notes notes-copy. First confirm that the destination does not exist: if it is an existing directory, a copy or move may place the source inside it.

Before deleting anything, check the path with ls. The following commands delete only the backup you just created. -i asks for confirmation; type y and press ↩ Return. Use rmdir to remove an empty directory.

ls -l notes/welcome-backup.txt
rm -i notes/welcome-backup.txt
ls -l notes
rm usually deletes files directly. rm -r recursively removes directories and their contents as well. List the target before acting during these exercises. Confirmation messages may vary by system language and version.

❓ Knowledge check

Q1: Why did ls omit .config?

Names beginning with . are hidden by default. Use ls -a to see them. Hiding is only a display convention; permission rules still apply normally.

Q2: How do I choose between an absolute and a relative path?

Relative paths are short and clear when your terminal is already in the project directory. Absolute paths make the target easier to identify in service configuration or commands that must work from any location.


🧪 Exercise

Create incoming inside linux-lab, copy notes/welcome.txt into it, and rename the copy to first-note.txt. Check with ls -l notes incoming: there should be one original and one renamed copy. The SSH article also uses incoming later.


🎉 You can now check your location before working with project files!