Introduction / Why This Is Needed
The Linux file system is a hierarchical structure where everything is represented as files and directories. The ability to manage it is a fundamental skill for any Linux user, from beginners to administrators. This guide will provide you with practical tools for navigation, data organization, and basic administration. You will be able to work confidently in the terminal, create/delete files, manage permissions, and understand the logic behind system file placement.
Requirements / Preparation
- Access to a terminal on any Linux distribution (Ubuntu, CentOS, Fedora, etc.).
- A user account with permissions to execute commands in your home directory (
/home/your_name). - For operations outside your home folder (e.g., in
/etcor/var), superuser (sudo) privileges may be required. Be cautious with such commands. - Basic understanding of what a path is (e.g.,
/home/user/Documents/file.txt).
Basic Navigation and Viewing Commands
Step 1: Determine Your Location — pwd
The pwd (print working directory) command displays the full path to your current directory. This is the first command you should use when opening a terminal to understand where you are.
pwd
# Example output: /home/username
Step 2: Move Between Directories — cd
The cd (change directory) command allows you to navigate the file system.
# Navigate to your home directory
cd ~
# or simply
cd
# Navigate to a specific absolute path
cd /etc/nginx
# Move up one level (to the parent directory)
cd ..
# Go back to the previous directory (like "back" in a browser)
cd -
Tip: Use Tab autocompletion. Start typing cd /ho and press Tab — the system will automatically complete it to cd /home/.
Step 3: View Directory Contents — ls
The ls (list) command outputs a list of files and subdirectories in the current or specified directory.
# Simple list
ls
# Detailed list (permissions, owner, size, date)
ls -l
# Show all files, including hidden ones (starting with .)
ls -la
# Sort by size (largest at the top)
ls -lS
# Recursive view (including nested directories)
ls -R
Working with Files and Directories
Step 4: Creating Files and Folders
- Create an empty file:
touch filename.txttouch notes.txt - Create a directory:
mkdir foldernamemkdir project_2026 - Create nested directories (if parents don't exist):
mkdir -p path/to/new/foldermkdir -p archive/2026/02
Step 5: Copying, Moving, and Renaming
- Copy a file:
cp source.txt destination/cp report.docx ~/Documents/ - Copy a directory (recursively):
cp -r source_folder/ destination/cp -r templates/ backup/ - Move or rename:
mv oldname.txt newname.txtormv file.txt /new/path/mv draft.txt final.txt mv image.jpg /var/www/images/⚠️ Important: The
mvcommand without flags overwrites the destination file without warning. Usemv -ifor interactive confirmation.
Step 6: Deleting Files and Directories
- Delete a file:
rm filenamerm temp.log - Delete an empty directory:
rmdir folderrmdir empty_cache - Delete a non-empty directory (with all contents):
rm -rf foldernamerm -rf old_backup/⚠️ Critically important: The
-rf(recursive, force) flag deletes everything permanently and without confirmation. Double-check the path before executing. A command error likerm -rf /can destroy the entire system.
Permissions and Security
Step 7: Viewing and Understanding Permissions
When using ls -l, you see a string like: -rw-r--r-- 1 user group 1234 Feb 17 10:00 file.txt.
Decoding:
- First character: type (
-for file,dfor directory). - Next 9 characters: permissions in three groups (owner, group, others). Each group:
r(read),w(write),x(execute). - Example:
rw-= read and write, but not execute.
Step 8: Changing Permissions — chmod
There are two main syntaxes:
- Symbolic (more intuitive):
# Add execute permission for the owner chmod u+x script.sh # Remove write permission for group and others chmod go-w important.conf # Set permissions: owner - rwx, group and others - r-x (5) chmod 755 script.sh - Octal (numeric): Each group (owner, group, others) is assigned a number from 0 to 7, where:
- 4 = read (r)
- 2 = write (w)
- 1 = execute (x)
- Sum: 7=4+2+1 (rwx), 6=4+2 (rw-), 5=4+1 (r-x), etc.
# 755 = rwxr-xr-x (owner: all, group and others: read and execute) chmod 755 script.sh
Step 9: Changing Owner and Group — chown
Requires sudo.
# Change a file's owner
sudo chown newuser filename.txt
# Change both owner and group simultaneously
sudo chown newuser:newgroup folder/
# Recursively change owner for an entire directory
sudo chown -R www-data:www-data /var/www/html
Verification
- Check your current path:
pwdshould show the expected directory. - Confirm creation:
lsshould display the new files/folders. - Verify permissions:
ls -l filenamewill show the set permissions (-rwxr--r--). - Test execution: If you created a script, run
./script.sh(if the owner hasxpermission).
Common Issues
| Problem | Cause | Solution |
|---|---|---|
Permission denied | No permissions for the operation (read/write/execute) in the target directory or for the file. | 1. Use sudo for system paths (carefully!).2. Change permissions via chmod or ownership via chown (if that is your task).3. Perform operations in your home directory ( /home/username). |
No such file or directory | An incorrect path or filename was specified. | 1. Check your current path with pwd.2. Use ls to view the contents of the current or specified directory.3. Ensure correct character case (Linux is case-sensitive: File.txt ≠ file.txt). |
| File accidentally deleted | Used rm or rm -rf with an error in the path. | 1. Immediately stop writing to the disk. 2. Try recovery with utilities ( extundelete, testdisk) if the file system hasn't been overwritten. Chances are low.3. Prevention: always use ls before rm -rf, set up alias rm='rm -i' in ~/.bashrc. |
Operation not permitted with chown/chmod | Attempting to change permissions/ownership of a file you don't own without sudo. | 1. Add sudo to the beginning of the command if you are an administrator.2. If the file is system-critical, reconsider if it needs to be changed. |
| Autocompletion (Tab) not working | The terminal is using a shell other than bash/zsh, or settings are misconfigured. | 1. Ensure you are in bash (echo $SHELL).2. Check if the bash-completion package is installed (sudo apt install bash-completion for Debian/Ubuntu). |
Final Tip: Start with simple operations in an isolated test folder (e.g., mkdir test && cd test). The more confident you become with basic commands, the more effectively you will work with Linux.