File naming rules and globbing

2.4 Creating, Moving, and Deleting Files (Weight: 2)

📘Linux Essentials (LPI 010-160)


In Linux systems, files and directories are identified by their names. Understanding how file names work and how Linux can match multiple files using globbing patterns is very important when working in the command line. These concepts are commonly used with commands such as ls, cp, mv, and rm.

This section explains file naming rules and globbing in a simple way so students can understand how Linux handles file names and how patterns can be used to work with many files at once.


1. File Naming Rules in Linux

Linux allows flexible file naming, but there are still some important rules and best practices.

1.1 Case Sensitivity

Linux file names are case-sensitive.

This means that uppercase and lowercase letters are treated as different characters.

Example:

report.txt
Report.txt
REPORT.txt

These are three different files in Linux.

This is important in IT environments where configuration files, scripts, or logs may depend on the exact file name.

Example:

config.sh
Config.sh

These would be treated as separate files by the system.


1.2 Allowed Characters

Linux allows many characters in file names, including:

  • Letters (a–z, A–Z)
  • Numbers (0–9)
  • Periods .
  • Underscores _
  • Hyphens -

Example:

server_config.conf
backup-2025.tar
logfile1.txt

These characters are commonly used in system files and scripts.


1.3 Special Characters

Although Linux allows many special characters, some characters have special meanings in the shell.

Examples include:

*  ?  $  &  |  ;  ( )  < >  !  space

Using these characters in file names may cause command-line issues because the shell interprets them.

Example:

backup*.txt

The * is normally interpreted as a wildcard, not part of a filename.

Because of this, it is usually better to avoid special characters in file names when working in IT environments.


1.4 Spaces in File Names

Linux allows spaces in file names, but they can cause problems in the command line.

Example:

system log.txt

The shell treats spaces as argument separators, so the system may interpret this as two items:

system
log.txt

To work with such files, you must use:

Quotation marks

"system log.txt"

or

Escape characters

system\ log.txt

However, in most IT environments, it is better to avoid spaces and use underscores instead.

Example:

system_log.txt

1.5 Hidden Files

Files beginning with a dot (.) are hidden files.

Example:

.bashrc
.profile
.gitconfig

Hidden files are commonly used for:

  • user configuration
  • application settings
  • environment customization

They are not displayed by default when using:

ls

To see hidden files, use:

ls -a

1.6 File Extensions

Linux does not require file extensions, but they are commonly used.

Example:

script.sh
backup.tar
config.conf
notes.txt

Unlike some operating systems, Linux does not rely on extensions to determine file type. Instead, it often checks the file content.

However, extensions are still useful in IT environments to quickly identify file types.


1.7 Maximum File Name Length

Typical Linux file systems allow:

  • 255 characters per file name

Also:

  • The full path length has limits depending on the filesystem.

Example:

/home/user/projects/linux/scripts/install_script.sh

2. Best Practices for File Naming

In professional IT environments, administrators often follow these guidelines:

Use:

  • lowercase letters
  • numbers
  • hyphens -
  • underscores _

Example:

webserver-config.conf
backup_script.sh
database_log_2025.txt

Avoid:

  • spaces
  • complex special characters
  • very long names

This ensures scripts and automation tools work reliably.


3. What is Globbing?

Globbing is the process used by the Linux shell to match file names using patterns.

It allows a command to work with multiple files at once.

Globbing is mainly used with commands such as:

ls
cp
mv
rm

Example:

ls *.txt

This command lists all files ending with .txt.

The shell expands the pattern before running the command.


4. Common Globbing Wildcards

Linux globbing uses special pattern characters called wildcards.

The most important ones for the exam are:

*
?
[ ]

4.1 Asterisk *

The * wildcard matches zero or more characters.

Example:

*.log

Matches:

system.log
error.log
server_backup.log

Example command:

ls *.log

Lists all .log files in the current directory.


Another Example

backup*

Matches:

backup
backup1
backup_script.sh
backup.tar

4.2 Question Mark ?

The ? wildcard matches exactly one character.

Example:

file?.txt

Matches:

file1.txt
file2.txt
fileA.txt

But it does not match:

file10.txt

because that has more than one character after file.

Example command:

ls file?.txt

4.3 Brackets [ ]

Brackets match one character from a set of characters.

Example:

file[123].txt

Matches:

file1.txt
file2.txt
file3.txt

But not:

file4.txt

Range Matching

You can also define ranges.

Example:

file[1-5].txt

Matches:

file1.txt
file2.txt
file3.txt
file4.txt
file5.txt

Letter Ranges

Example:

log[a-c].txt

Matches:

loga.txt
logb.txt
logc.txt

4.4 Negation with Brackets

A pattern can match all characters except certain ones.

Example:

file[!1].txt

Matches:

file2.txt
file3.txt

But not:

file1.txt

5. Globbing with Common Linux Commands

Globbing is frequently used with file management commands.


Using Globbing with ls

ls *.conf

Lists all configuration files.


Using Globbing with cp

cp *.log /backup/

Copies all log files into a backup directory.


Using Globbing with mv

mv *.txt archive/

Moves all text files to an archive directory.


Using Globbing with rm

rm *.tmp

Deletes all temporary files ending with .tmp.

This command should always be used carefully.


6. Important Globbing Behavior

Hidden Files Are Not Matched by *

The * wildcard does not match hidden files.

Example:

ls *

This will not show:

.hiddenfile

To match hidden files:

ls .*

Shell Expansion

Globbing is processed by the shell, not the command.

Example:

ls *.txt

The shell converts it into:

ls file1.txt file2.txt file3.txt

before executing the command.


7. Difference Between Globbing and Regular Expressions

Students often confuse these two concepts.

FeatureGlobbingRegular Expressions
Used inShell commandsText processing tools
Examples*, ?, [abc].*, ^, $
Toolsls, cp, mv, rmgrep, sed, awk

For the Linux Essentials exam, you mainly need to understand basic globbing patterns.


8. Exam Tips (Important for LPI Linux Essentials)

Students preparing for the exam should remember:

  • Linux file names are case-sensitive
  • Hidden files start with a dot (.)
  • Avoid spaces and special characters in file names
  • * matches any number of characters
  • ? matches exactly one character
  • [ ] matches one character from a set or range
  • Globbing is expanded by the shell
  • * does not match hidden files

✅ Understanding file naming rules and globbing is important because system administrators often manage large numbers of files, logs, configuration files, and scripts from the command line.

Correct use of patterns and naming conventions makes file management faster, safer, and easier to automate in Linux environments.

Buy Me a Coffee