Linux Mastery

The Human Knowledge Project


04 — Creating & Managing Files


Why This Chapter Matters

Nearly everything you do in Linux involves files.

Programs are files.

Pictures are files.

Music is stored in files.

Configuration settings are stored in files.

Even many hardware devices appear as files.

Directories organize those files into a logical structure that allows Linux—and its users—to locate information quickly and efficiently.

The concepts introduced in this chapter will be used throughout the remainder of Linux Mastery.


1. Files and Directories

Linux systems organize information using:

Directories are often called folders in graphical environments.

Nearly everything in Linux involves:

files and directories.

Understanding file management is one of the most fundamental Linux skills.


2. Creating Files with touch

The:


touch

command creates empty files.

Example:


touch notes.txt

Verify:


ls

You should now see:


notes.txt

Multiple files may be created at once:


touch file1 file2 file3

The touch command is also used to update file timestamps.


3. Creating Directories with mkdir

The:


mkdir

command creates directories.

Example:


mkdir projects

Verify:


ls

You should now see:


projects

To create nested directories:


mkdir -p work/linux/chapter04

The:


-p

option creates parent directories automatically if needed.


4. Copying Files with cp

The:


cp

command copies files.

Example:


cp notes.txt backup_notes.txt

This creates:

To copy directories recursively:


cp -R projects backup_projects

The:


-R

option means recursive.

(See Appendix A — Recursion)


5. Moving and Renaming Files with mv

The:


mv

command moves or renames files.

Rename example:


mv notes.txt chapter_notes.txt

Move example:


mv chapter_notes.txt projects/

Linux uses the same command for:

because renaming is conceptually a filesystem move operation.


6. Removing Files with rm

The:


rm

command removes files.

Example:


rm unwanted.txt

Important

To remove directories recursively:


rm -R old_projects

Use recursive deletion carefully.

Incorrect paths may destroy important files.


7. Hidden Files

Linux hides files beginning with:


.

Example:


.bashrc
.profile

These are commonly:

To view hidden files:


ls -a

The:


-a

option means:

including hidden files.


8. File Naming

Linux filenames are:

These are different files:


File.txt
file.txt
FILE.txt

Good naming practices:

Recommended:


## chapter_04_notes.md

Avoid:


Stuff Final NEW reallyfinal2.txt

Good naming improves:


9. Wildcards

Wildcards allow commands to match multiple files.

The most common wildcard is:


*

Example:


ls *.txt

This matches all files ending in:


.txt

Another example:


rm *.tmp

This removes all files ending in:


.tmp

Wildcards are extremely powerful.

Always verify wildcard commands carefully before pressing ENTER.


10. Organizing Files

Good organization is an important Linux skill.

Common organizational methods include:

Example structure:


Linux_Mastery/
├── chapters/
├── appendices/
├── problem_sets/
├── solutions/
└── assets/

Well-organized filesystems improve:


11. Practice Exercises

1.

Create an empty file:


touch practice.txt

Verify using:


ls

2.

Create a directory:


mkdir testdir

3.

Create nested directories:


mkdir -p work/linux/ch04

4.

Copy a file:


cp practice.txt backup.txt

Verify both files exist.


5.

Rename a file:


mv backup.txt renamed_backup.txt

6.

Move a file into a directory:


mv renamed_backup.txt testdir/

7.

Create a hidden file:


touch .hiddenfile

Then display hidden files:


ls -a

8.

Create several text files:


touch one.txt two.txt three.txt

List them using:


ls *.txt

9.

Delete a practice file:


rm practice.txt

Verify removal.


12. Key Ideas

Linux systems are heavily file-oriented.

Users constantly:

files and directories.

Mastering file management builds:

These operations become the foundation for nearly all advanced Linux workflows.