Skip to content

Filenames and metadata

Module
Working with Files and Directories
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21, file 5.45, GNU Coreutils 9.4
On this page

Your notes are in a file called meeting notes.txt. You type cat meeting notes.txt, and cat complains about two missing files. The file is there; the command did not receive its name as you intended.

By the end, you can address names containing spaces or a leading hyphen, inspect what a file contains without trusting its extension, and read its size, ownership, and recorded times.

Finish Removing files deliberately (B06.2). Keep your existing ~/lab from B04.1’s setup, including the original notes and report.

Work only in ~/lab/b06/inspection. Leave the earlier project, archive, handoff, and removal exercises intact. Run this setup once; use Reset this lesson before repeating it.

Single quotes in the setup keep a filename’s spaces together. The next section shows what happens without them. ./ means “in this directory”, as in B05.2; its use before -draft.txt is explained below.

Terminal window
cd ~/lab/b06
mkdir -p inspection
cd inspection
cp ../../Documents/notes.txt 'meeting notes.txt'
cp ../../Documents/notes.txt photo.jpg
cp ../../Documents/report.txt ./-draft.txt
cp ./-draft.txt release-notes.txt
head -c 2048 /dev/zero > padding.bin
pwd
ls -1
Captured output
/home/learner/lab/b06/inspection
Captured output
-draft.txt
'meeting notes.txt'
padding.bin
photo.jpg
release-notes.txt

The copies preserve the source files. From inspection, ../../Documents goes up through b06 to lab, then into Documents.

The head line prepares a file with a known size. -c 2048 reads 2,048 bytes, units of stored data, instead of a number of lines. /dev/zero supplies zero-valued bytes; > saves them in padding.bin, as > saved text in B04.1. This creates data, not readable notes.

ls -1 prints one name per line. Its displayed quotes around the spaced name are not part of the filename. Your prompt ends in ~/lab/b06/inspection$; every relative path below starts here.

Before running the broken command, predict which paths cat will try to open:

Terminal window
cat meeting notes.txt
Run it, then compare with your guess
Captured output
cat: meeting: No such file or directory
cat: notes.txt: No such file or directory

The messages name meeting and notes.txt separately. Without quotes, the space separates two arguments. Neither path exists in this directory.

Put single quotes around the whole name:

Terminal window
cat 'meeting notes.txt'
Captured output
Buy printer paper
Renew lab VM snapshot

Bash uses the quotes to pass meeting notes.txt as one argument. The quotes themselves are not passed to cat. This is quoting: keeping characters together and literal. Single quotes are enough for these names, which contain no single quote themselves. The broader rules belong to B08.

Tab completion (B04.2) handles the space for you by inserting a backslash, so cat meet followed by Tab becomes cat meeting\ notes.txt. A backslash keeps the single character after it literal, so the space does not split the name. It is another form of quoting; B08 covers the full rules.

Terminal window
cat meeting\ notes.txt
Captured output
Buy printer paper
Renew lab VM snapshot

A hyphen inside a name needs no special treatment:

Terminal window
cat release-notes.txt
Captured output
Quarterly lab report

The first character is r, so this argument does not look like an option. A leading hyphen is different. Even quoting the name is not enough:

Terminal window
ls '-draft.txt'
Captured output
ls: invalid option -- '.'
Try 'ls --help' for more information.

Bash passed one argument, but that argument still starts with -. ls tries to read its characters as options and rejects .. Quotes solve Bash’s separation of words; they do not tell a utility to stop reading options.

For GNU ls, put -- before the filename:

Terminal window
ls -- '-draft.txt'
Captured output
-draft.txt

-- marks the end of options: the arguments after it are treated as names. Many utilities, including the ls, file, and stat used here, support it. It is a utility convention, not a universal Bash feature; check the command’s documentation.

Another way is to start the path with ./:

Terminal window
cat ./-draft.txt
Captured output
Quarterly lab report

The path still names -draft.txt in the current directory, but the argument starts with . instead of -. Both corrections inspect the existing file without renaming it.

You need to decide what kind of file you are inspecting before choosing a program to open it:

Terminal window
file 'meeting notes.txt'
Captured output
meeting notes.txt: ASCII text

file examines the file and reports an identification. ASCII text means text using a character set that includes these English letters, spaces, and newlines.

Now predict what file reports for photo.jpg. Does its extension make it a JPEG image?

Terminal window
file photo.jpg
Run it, then compare with your guess
Captured output
photo.jpg: ASCII text

It is text too. The setup copied the notes and gave the copy a name ending in .jpg. That extension, the suffix after the final dot, did not turn the contents into an image.

For a download, a mismatch is a reason to stop and investigate before opening it in the program its extension suggests. A matching identification is not a guarantee of safety: file classifies data; it does not certify that the file is harmless.

You know what the note contains. Now ask about the file itself:

Terminal window
stat 'meeting notes.txt'
Captured output
File: meeting notes.txt
Size: 40 Blocks: 8 IO Block: 4096 regular file
Device: 0,93 Inode: 38079 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ learner) Gid: ( 1001/ learner)
Access: 2026-11-11 08:28:17.043006176 +0000
Modify: 2026-11-11 08:28:13.000824361 +0000
Change: 2026-11-11 08:28:13.000824361 +0000
Birth: 2026-11-11 08:28:12.998533269 +0000

stat displays metadata, information about the file rather than its text. These are captured values, not values to reproduce. Your dates, time zone, inode and device numbers, numeric user/group IDs, and allocation details can differ. The replay is another recorded run; its metadata need not match a run on your computer. On the course VM, the numeric user and group IDs are usually 1000, and the time zone follows the VM’s settings.

Start with the fields that answer everyday questions:

  • Size: 40 is the content length in bytes. It includes spaces and newline characters, not only visible letters.
  • Uid identifies the owning user; Gid identifies the owning group. Both show the name learner here, alongside numeric IDs. Groups let permission rules apply to several accounts, as in B03.3.
  • The first Access: line contains permission settings. Leave its numbers and letters for B11; this lesson does not change them.

The date rows answer different questions:

Row Common name What the time records
Access atime Last recorded access to the contents, such as reading
Modify mtime Last content modification, or a time explicitly set by a tool such as touch
Change ctime Last inode status change, including content or metadata changes
Birth birth time Creation time, when the filesystem and tools provide it

ctime is not creation time. Changing ownership, for example, changes status without rewriting the contents. Birth time is available in this capture; another filesystem or interface may not supply it, and stat can show a dash instead. Do not substitute ctime for a missing birth time.

Access times are not an exact log of every read: filesystem settings can delay or suppress updates. Do not infer a reliable sequence of events merely because two rows differ, or assume that reading always changes the displayed time.

Inode is the number identifying the file’s metadata record within its filesystem. Keep that field in mind for B06.4’s links. Device identifies the filesystem’s device; Links counts hard-link names. Those relationships are the next lesson’s subject.

Read a spaced name, its type, and its metadata
learner@rootvolt:~/lab/b06/inspection$ cat 'meeting notes.txt'Buy printer paper
Renew lab VM snapshotlearner@rootvolt:~/lab/b06/inspection$ file 'meeting notes.txt'meeting notes.txt: ASCII textlearner@rootvolt:~/lab/b06/inspection$ stat 'meeting notes.txt'  File: meeting notes.txt
  Size: 40        	Blocks: 8          IO Block: 4096   regular file
Device: 0,93	Inode: 38079       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/ learner)   Gid: ( 1001/ learner)
Access: 2026-11-11 08:28:17.043006176 +0000
Modify: 2026-11-11 08:28:13.000824361 +0000
Change: 2026-11-11 08:28:13.000824361 +0000
 Birth: 2026-11-11 08:28:12.998533269 +0000learner@rootvolt:~/lab/b06/inspection$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Quoted cat addresses one spaced filename; file identifies its contents; stat reports its recorded metadata.
Steps (9)
  1. Type cat 'meeting notes.txt'
  2. Press Enter
  3. Output: Buy printer paper Renew lab VM snapshot
  4. Type file 'meeting notes.txt'
  5. Press Enter
  6. Output: meeting notes.txt: ASCII text
  7. Type stat 'meeting notes.txt'
  8. Press Enter
  9. Output: File: meeting notes.txt Size: 40 Blocks: 8 IO Block: 4096 regular file Device: 0,93 Inode: 38079 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1001/ learner) Gid: ( 1001/ learner) Access: 2026-11-11 08:28:17.043006176 +0000 Modify: 2026-11-11 08:28:13.000824361 +0000 Change: 2026-11-11 08:28:13.000824361 +0000 Birth: 2026-11-11 08:28:12.998533269 +0000

In words: cat prints the two note lines, file reports ASCII text, and stat reports a 40-byte file owned by learner, with its recorded times. The static transcript preserves the same information without playback.

Inspect the padding file from setup:

Terminal window
stat padding.bin
Captured output
File: padding.bin
Size: 2048 Blocks: 8 IO Block: 4096 regular file
Device: 0,93 Inode: 38076 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ learner) Gid: ( 1001/ learner)
Access: 2026-11-11 08:28:15.018769488 +0000
Modify: 2026-11-11 08:28:15.022844135 +0000
Change: 2026-11-11 08:28:15.022844135 +0000
Birth: 2026-11-11 08:28:15.018769488 +0000

Its Size is 2,048 bytes. Blocks describes allocated storage, and IO Block a transfer-size hint; neither replaces Size as the content length.

Compare the long listing with -h added:

Terminal window
ls -lh 'meeting notes.txt' padding.bin
Captured output
-rw-r--r-- 1 learner learner 40 Nov 11 08:28 'meeting notes.txt'
-rw-r--r-- 1 learner learner 2.0K Nov 11 08:28 padding.bin

-l is the long format from B04. -h makes sizes human-readable, using powers of 1,024: 2.0K represents 2,048 bytes. The 40-byte note stays 40. The two learner columns are owner and group; the date is modification time, shown with less detail than stat. Your dates will differ.

Goal: Inspect a handoff file whose name starts with a hyphen and contains a space.

Prepare a disposable copy:

Terminal window
cp -- release-notes.txt '-arrival notes.dat'

Without renaming it, identify its content type, read its metadata, and print its contents. Explain why the name needs both space handling and option handling. State its byte size, owner/group, and which timestamp is status-change time. Say whether .dat proves anything about its contents.

Expected: Three successful inspections of the same file, with no missing-path or invalid-option error.

Hint

Quotes preserve the space. They do not remove the leading hyphen. Use an end-of-options marker supported by the inspection utility, or prefix the quoted path with ./.

Solution
Terminal window
file -- '-arrival notes.dat'
stat -- '-arrival notes.dat'
cat './-arrival notes.dat'
Captured output
-arrival notes.dat: ASCII text
Captured output
File: -arrival notes.dat
Size: 21 Blocks: 8 IO Block: 4096 regular file
Device: 0,93 Inode: 38075 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ learner) Gid: ( 1001/ learner)
Access: 2026-11-11 08:28:23.351748437 +0000
Modify: 2026-11-11 08:28:22.827489128 +0000
Change: 2026-11-11 08:28:22.827489128 +0000
Birth: 2026-11-11 08:28:22.823685898 +0000
Captured output
Quarterly lab report

This is a 21-byte text file owned by user learner and group learner in the capture. Change is ctime, not creation time. The extension does not prove a type. Quotes make one argument; -- or ./ prevents its leading hyphen from being read as an option. The displayed metadata values vary as described above.

The inspections preserve the file contents. To restore the initial five-file layout, including removing the challenge copy, return to the parent and inspect the target:

Terminal window
cd ~/lab/b06
ls -AR inspection

-A includes hidden entries and -R includes subdirectories. After the solution:

Captured output
inspection:
'-arrival notes.dat' 'meeting notes.txt' photo.jpg
-draft.txt padding.bin release-notes.txt
Terminal window
rm -r ~/lab/b06/inspection

It succeeds silently. Run the setup under Before you start again. If the directory is already absent, skip removal and run setup. This restores the names and contents; it creates fresh files, so timestamps and inode numbers need not match the previous run.

  • Single quotes keep a spaced pathname together as one argument; the quotes are not part of the name.
  • A leading hyphen can look like an option. Use -- where the utility supports it, or a path beginning with ./.
  • Extensions do not prove content type. file reports an identification, not a safety guarantee.
  • stat shows metadata; Size counts bytes, and ls -lh uses readable units. Owner and group identify who the file belongs to.
  • Access, modification, and status-change times describe different events. ctime is not creation time; birth time may be unavailable.

Next, Hard links and symbolic links (B06.4) follows names to inodes or target paths and checks what survives removal.

  • On your system: man file, man stat, and man ls. Ubuntu 24.04 manuals: file(1), stat(1), and ls(1).
  • Ubuntu 24.04 inode(7), especially timestamps and inode numbers.
  • On your system: man bash, section QUOTING, or Ubuntu 24.04 bash(1), for single quotes.