Results for “File positioning & lifecycle”
Small, practical examples. Search by task or narrow things down below.
Copy a file with explicit permissions
Linux Commands: Use install to create parent directories and set the destination mode in one operation.
Linux Commands✓ Tested
Copy a file without overwriting
C#: File.Copy defaults to refusing a destination that already exists.
C#✓ Tested
Copy a file without replacing an existing destination
Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.
Java✓ Tested
Copy a file without replacing an existing destination
C++: The default copy_file policy refuses to overwrite an existing destination.
C++✓ Tested
Count bytes in a file
Linux Commands: Use wc -c for byte length rather than Unicode character count.
Linux Commands✓ Tested
Count lines in a file
Count newline characters in a text file, printing only the count without the filename.
lines✓ Tested
Create a file only when it does not exist
C#: FileMode.CreateNew prevents accidental replacement of existing content.
C#✓ Tested
Create a file without overwriting an existing one
Python: Use exclusive creation mode and handle FileExistsError explicitly.
Python✓ Tested
Create a file without replacing existing data
Create a file without replacing existing data in a complete Rust program using the standard library.
Rust✓ Tested
Create a runtime file during the build
Docker / Compose: RUN executes during the build while CMD executes when a container starts.
Docker / Compose✓ Tested
Create a second name for the same file
Linux Commands: Use ln for a hard link and inspect the shared link count.
Linux Commands✓ Tested
Create a small file at build time
Docker / Compose: Create a small file at build time with a complete introductory Dockerfile.
Docker / Compose✓ Tested