Java File Manager
A Java file manager is a command-line tool that lists folders, draws a folder tree, copies, moves and deletes files, searches by name or content, and reports disk usage. Building one is the best way to practise the java.nio.file API on real folders, because every operation must handle missing paths, existing targets and nested directories safely.
This project follows the Java Todo App and reuses its command-line style: each command runs, prints a result and exits with a status code. You build a FileInfo record, a FileManager class with listing, tree, copy, move, delete, search and usage methods, and finally fm.jar. All examples were run on JDK 21.
Describe Files With a FileInfo Record
Every listing needs the same three facts about an entry: its path, whether it is a folder, and its size. A record holds them, and a small helper turns raw byte counts into sizes people can read.
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/** A snapshot of one file or folder: its name, whether it is a folder, and its size in bytes. */
public record FileInfo(Path path, boolean directory, long size) {
public static FileInfo of(Path path) throws IOException {
boolean isDir = Files.isDirectory(path);
return new FileInfo(path, isDir, isDir ? 0 : Files.size(path));
}
public String name() {
return path.getFileName().toString();
}
/** 532 -> "532 B", 2048 -> "2.0 KB", 5_242_880 -> "5.0 MB". */
public static String humanSize(long bytes) {
if (bytes < 1024) return bytes + " B";
String[] units = {"KB", "MB", "GB", "TB"};
double value = bytes;
int unit = -1;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit++;
}
return String.format("%.1f %s", value, units[unit]);
}
}
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class SizeDemo {
public static void main(String[] args) throws IOException {
long[] samples = {0, 532, 1024, 2048, 1_536_000, 5_242_880, 3_221_225_472L};
for (long bytes : samples) {
System.out.printf("%,15d bytes = %s%n", bytes, FileInfo.humanSize(bytes));
}
Path notes = Files.writeString(Path.of("notes.txt"), "Buy milk\nCall plumber\n");
FileInfo info = FileInfo.of(notes);
System.out.println(info.name() + " is " + FileInfo.humanSize(info.size())
+ (info.directory() ? " (folder)" : " (file)"));
Files.delete(notes);
}
}
0 bytes = 0 B
532 bytes = 532 B
1,024 bytes = 1.0 KB
2,048 bytes = 2.0 KB
1,536,000 bytes = 1.5 MB
5,242,880 bytes = 5.0 MB
3,221,225,472 bytes = 3.0 GB
notes.txt is 22 B (file)
How it works:
Files.isDirectoryandFiles.sizeread the information from the file system. A folder gets size0here; its real total is calculated later by the disk usage report.humanSizedivides by 1024 until the value is below 1024, moving one unit up each time.3_221_225_472bytes is divided three times and becomes3.0 GB.%.1fprints one decimal place, so every size has the same short format.path.getFileName()returns only the last part of a path, such asnotes.txtfordocs/notes.txt.
List a Folder and Draw a Java Directory Tree
The FileManager class works inside one root folder. Every path the user types is resolved against that root, and any path that tries to leave it, such as ../.., is rejected. This is the most important safety rule in a file manager.
The listing and tree methods are shown first. The full class, with every method, is used in the later sections.
public class FileManager {
/** Folders first, then names A-Z ignoring case. */
static final Comparator<FileInfo> LISTING_ORDER = Comparator
.comparing((FileInfo f) -> !f.directory())
.thenComparing(f -> f.name().toLowerCase());
private final Path root;
public FileManager(Path root) {
this.root = root.toAbsolutePath().normalize();
}
/** Resolves a user path and refuses anything that escapes the root, such as "../../etc". */
public Path resolve(String userPath) {
Path target = root.resolve(userPath).normalize();
if (!target.startsWith(root)) {
throw new IllegalArgumentException("Path is outside the managed folder: " + userPath);
}
return target;
}
public String relative(Path path) {
String text = root.relativize(path).toString().replace('\\', '/');
return text.isEmpty() ? "." : text;
}
public List<FileInfo> list(String folder) throws IOException {
Path dir = resolve(folder);
if (!Files.isDirectory(dir)) throw new IllegalArgumentException("Not a folder: " + folder);
List<FileInfo> entries = new ArrayList<>();
try (Stream<Path> children = Files.list(dir)) {
for (Path child : (Iterable<Path>) children::iterator) {
entries.add(FileInfo.of(child));
}
}
entries.sort(LISTING_ORDER);
return entries;
}
public List<String> tree(String folder, int maxDepth) throws IOException {
List<String> lines = new ArrayList<>();
Path dir = resolve(folder);
lines.add((dir.equals(root) ? root.getFileName().toString() : relative(dir)) + "/");
addTreeLines(dir, "", 1, maxDepth, lines);
return lines;
}
private void addTreeLines(Path dir, String indent, int depth, int maxDepth, List<String> lines) throws IOException {
List<FileInfo> children = list(relative(dir));
for (int i = 0; i < children.size(); i++) {
FileInfo child = children.get(i);
boolean last = i == children.size() - 1;
lines.add(indent + (last ? "└── " : "├── ") + child.name()
+ (child.directory() ? "/" : " (" + FileInfo.humanSize(child.size()) + ")"));
if (child.directory() && depth < maxDepth) {
addTreeLines(child.path(), indent + (last ? " " : "│ "), depth + 1, maxDepth, lines);
}
}
}
// copy, move, delete, search and usage methods follow below
}
Every demo uses the same small sample folder, so the output is always the same:
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/** Builds the same small project folder for every demo, so the output is always identical. */
public class SampleFolder {
public static Path create(String name) throws IOException {
Path root = Path.of(name);
removeIfPresent(root);
Files.createDirectories(root.resolve("docs"));
Files.createDirectories(root.resolve("src/app"));
Files.createDirectories(root.resolve("photos"));
Files.writeString(root.resolve("README.md"), "# Shop\nA small shop app.\nTODO: add screenshots\n");
Files.writeString(root.resolve("docs/setup.txt"), "Install JDK 21\nRun the build\n");
Files.writeString(root.resolve("docs/notes.txt"), "Meeting notes\ntodo: invoice template\n");
Files.writeString(root.resolve("src/app/Main.java"), "class Main {\n // TODO: read config\n}\n");
Files.writeString(root.resolve("src/app/Cart.java"), "class Cart {\n int items;\n}\n");
Files.write(root.resolve("photos/beach.jpg"), new byte[245_760]);
Files.write(root.resolve("photos/team.png"), new byte[1_258_291]);
return root;
}
/** Deletes a leftover folder from an earlier run: deepest paths first. */
static void removeIfPresent(Path folder) throws IOException {
if (Files.notExists(folder)) return;
try (var paths = Files.walk(folder)) {
for (Path p : paths.sorted(java.util.Comparator.reverseOrder()).toList()) Files.delete(p);
}
}
}
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Path;
public class ListDemo {
public static void main(String[] args) throws IOException {
Path root = SampleFolder.create("shop");
FileManager fm = new FileManager(root);
System.out.println("Contents of shop/:");
for (FileInfo entry : fm.list(".")) {
System.out.printf(" %-6s %-12s %10s%n", entry.directory() ? "<DIR>" : "",
entry.name(), entry.directory() ? "" : FileInfo.humanSize(entry.size()));
}
System.out.println();
fm.tree(".", 3).forEach(System.out::println);
System.out.println();
System.out.println("Depth 1 only:");
fm.tree(".", 1).forEach(System.out::println);
try {
fm.list("../..");
} catch (IllegalArgumentException e) {
System.out.println("\nBlocked: " + e.getMessage());
}
}
}
Contents of shop/:
<DIR> docs
<DIR> photos
<DIR> src
README.md 47 B
shop/
├── docs/
│ ├── notes.txt (37 B)
│ └── setup.txt (29 B)
├── photos/
│ ├── beach.jpg (240.0 KB)
│ └── team.png (1.2 MB)
├── src/
│ └── app/
│ ├── Cart.java (30 B)
│ └── Main.java (40 B)
└── README.md (47 B)
Depth 1 only:
shop/
├── docs/
├── photos/
├── src/
└── README.md (47 B)
Blocked: Path is outside the managed folder: ../..
How it works:
root.resolve("../..").normalize()produces a path above the root.startsWith(root)is thenfalse, soresolvethrows before any file is touched.Files.listreturns a lazyStream<Path>that holds an open directory handle. Thetry-with-resources block closes it, as explained in Java Directory Handling.LISTING_ORDERsortsfalsebeforetrue, so!f.directory()puts folders first. Names are compared in lower case, soREADME.mdsorts with the otherrnames.addTreeLinescalls itself for each sub-folder. Theindentstring grows by"│ "under a middle entry and by four spaces under the last one, which draws the tree lines.maxDepthstops the recursion, sotree(".", 1)shows only the first level.
Copy, Move and Delete Files and Folders Safely
Files.copy and Files.delete work on one file or one empty folder. To copy or delete a whole folder, you walk it with Files.walkFileTree and a SimpleFileVisitor, which calls your methods for every folder and file it meets.
/** Copies a file or a whole folder. Refuses to overwrite an existing target. */
public int copy(String from, String to) throws IOException {
Path source = resolve(from);
Path target = resolve(to);
if (Files.notExists(source)) throw new IllegalArgumentException("Not found: " + from);
if (Files.exists(target)) throw new IllegalArgumentException("Already exists: " + to);
if (target.startsWith(source)) throw new IllegalArgumentException("Cannot copy a folder into itself");
int[] copied = {0};
Files.walkFileTree(source, new SimpleFileVisitor<>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Files.createDirectories(target.resolve(source.relativize(dir)));
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.copy(file, target.resolve(source.relativize(file)), StandardCopyOption.COPY_ATTRIBUTES);
copied[0]++;
return FileVisitResult.CONTINUE;
}
});
return copied[0];
}
/** Moves or renames a file or folder. Refuses to overwrite an existing target. */
public void move(String from, String to) throws IOException {
Path source = resolve(from);
Path target = resolve(to);
if (Files.notExists(source)) throw new IllegalArgumentException("Not found: " + from);
if (Files.exists(target)) throw new IllegalArgumentException("Already exists: " + to);
Files.createDirectories(target.getParent());
Files.move(source, target);
}
/** Deletes a file, or a folder with everything inside it. Returns how many entries were removed. */
public int delete(String userPath) throws IOException {
Path target = resolve(userPath);
if (target.equals(root)) throw new IllegalArgumentException("Refusing to delete the root folder");
if (Files.notExists(target)) throw new IllegalArgumentException("Not found: " + userPath);
int[] removed = {0};
Files.walkFileTree(target, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
removed[0]++;
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException error) throws IOException {
if (error != null) throw error;
Files.delete(dir); // the folder is empty now
removed[0]++;
return FileVisitResult.CONTINUE;
}
});
return removed[0];
}
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Path;
public class CopyMoveDeleteDemo {
public static void main(String[] args) throws IOException {
Path root = SampleFolder.create("shop");
FileManager fm = new FileManager(root);
System.out.println("Copied " + fm.copy("docs", "backup/docs") + " file(s) into backup/docs");
System.out.println("Copied " + fm.copy("README.md", "backup/README.md") + " file(s)");
fm.move("photos/team.png", "photos/2026/team-offsite.png");
System.out.println("Moved photos/team.png -> photos/2026/team-offsite.png");
String[][] badRequests = {
{"copy", "docs", "backup/docs"},
{"copy", "src", "src/app/src-copy"},
{"move", "missing.txt", "x.txt"},
{"delete", "."},
};
for (String[] request : badRequests) {
try {
switch (request[0]) {
case "copy" -> fm.copy(request[1], request[2]);
case "move" -> fm.move(request[1], request[2]);
case "delete" -> fm.delete(request[1]);
}
} catch (IllegalArgumentException e) {
System.out.println(String.join(" ", request) + " -> " + e.getMessage());
}
}
System.out.println("Deleted " + fm.delete("backup") + " entries from backup/");
System.out.println();
fm.tree(".", 3).forEach(System.out::println);
}
}
Copied 2 file(s) into backup/docs
Copied 1 file(s)
Moved photos/team.png -> photos/2026/team-offsite.png
copy docs backup/docs -> Already exists: backup/docs
copy src src/app/src-copy -> Cannot copy a folder into itself
move missing.txt x.txt -> Not found: missing.txt
delete . -> Refusing to delete the root folder
Deleted 5 entries from backup/
shop/
├── docs/
│ ├── notes.txt (37 B)
│ └── setup.txt (29 B)
├── photos/
│ ├── 2026/
│ │ └── team-offsite.png (1.2 MB)
│ └── beach.jpg (240.0 KB)
├── src/
│ └── app/
│ ├── Cart.java (30 B)
│ └── Main.java (40 B)
└── README.md (47 B)
| Visitor method | Called | Used here to |
|---|---|---|
preVisitDirectory | Before entering a folder | Create the same folder in the copy |
visitFile | For each file | Copy or delete the file |
postVisitDirectory | After leaving a folder | Delete the folder, which is now empty |
visitFileFailed | When a file cannot be read | Not overridden: the default rethrows the error |
How it works:
source.relativize(dir)gives the path inside the source, such asdocs/notes.txtbecomesnotes.txt. Resolving that againsttargetplaces the copy in the same relative position.COPY_ATTRIBUTESkeeps the original last-modified time on the copies.deletemust remove the files before their folder.postVisitDirectoryruns after all children are gone, soFiles.delete(dir)succeeds. Deletingbackup/removed 5 entries: 3 files and 2 folders (backup/docsandbackup).movecreates missing parent folders first, sophotos/2026/appeared automatically.Files.moveon the same disk is a fast rename, not a copy.- The guards run before any change, so a rejected command leaves the folder untouched. The counters are
int[]arrays because a local variable used inside an anonymous class must be effectively final, as covered in Java Anonymous Classes.
Search Files by Name, Content and Size in Java
A file manager also answers "where is it?" and "what is using the space?". Name search uses a glob pattern with PathMatcher, content search reads each matching file, and the usage report adds up file sizes with Files.walk.
/** Finds files whose name matches a glob such as "*.java" or "report-*.{csv,txt}". */
public List<Path> findByName(String glob) throws IOException {
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);
try (Stream<Path> found = Files.find(root, Integer.MAX_VALUE,
(path, attrs) -> attrs.isRegularFile() && matcher.matches(path.getFileName()))) {
return found.sorted().toList();
}
}
/** Finds lines that contain the text, ignoring case. Returns "path:line: text" entries. */
public List<String> grep(String text, String glob) throws IOException {
String needle = text.toLowerCase();
List<String> hits = new ArrayList<>();
for (Path file : findByName(glob)) {
List<String> lines;
try {
lines = Files.readAllLines(file);
} catch (MalformedInputException e) {
continue; // binary or non-UTF-8 file: skip it
}
for (int i = 0; i < lines.size(); i++) {
if (lines.get(i).toLowerCase().contains(needle)) {
hits.add(relative(file) + ":" + (i + 1) + ": " + lines.get(i).strip());
}
}
}
return hits;
}
/** Size and file count of one top-level entry. */
public record Usage(String name, long bytes, long files) { }
/** Total size under each top-level entry of the folder, largest first. */
public List<Usage> usage(String folder) throws IOException {
List<Usage> result = new ArrayList<>();
for (FileInfo entry : list(folder)) {
try (Stream<Path> walk = Files.walk(entry.path())) {
List<Path> files = walk.filter(Files::isRegularFile).toList();
long bytes = files.stream().mapToLong(FileManager::sizeOf).sum();
result.add(new Usage(entry.name() + (entry.directory() ? "/" : ""), bytes, files.size()));
}
}
result.sort(Comparator.comparingLong(Usage::bytes).reversed());
return result;
}
public List<FileInfo> largestFiles(int count) throws IOException {
try (Stream<Path> files = Files.walk(root)) {
return files.filter(Files::isRegularFile)
.map(p -> new FileInfo(p, false, sizeOf(p)))
.sorted(Comparator.comparingLong(FileInfo::size).reversed()
.thenComparing(f -> f.path().toString()))
.limit(count)
.toList();
}
}
private static long sizeOf(Path file) {
try {
return Files.size(file);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Path;
public class SearchDemo {
public static void main(String[] args) throws IOException {
Path root = SampleFolder.create("shop");
FileManager fm = new FileManager(root);
for (String glob : new String[] {"*.java", "*.{jpg,png}", "*.txt", "*.pdf"}) {
System.out.println(glob + " -> " + fm.findByName(glob).stream().map(fm::relative).toList());
}
System.out.println("\nLines containing \"todo\":");
fm.grep("todo", "*").forEach(hit -> System.out.println(" " + hit));
System.out.println("\nDisk usage of shop/:");
long totalBytes = 0;
for (FileManager.Usage u : fm.usage(".")) {
System.out.printf(" %-11s %10s %d file(s)%n", u.name(), FileInfo.humanSize(u.bytes()), u.files());
totalBytes += u.bytes();
}
System.out.printf(" %-11s %10s%n", "total", FileInfo.humanSize(totalBytes));
System.out.println("\nTwo largest files:");
fm.largestFiles(2).forEach(f ->
System.out.println(" " + FileInfo.humanSize(f.size()) + " " + fm.relative(f.path())));
}
}
*.java -> [src/app/Cart.java, src/app/Main.java]
*.{jpg,png} -> [photos/beach.jpg, photos/team.png]
*.txt -> [docs/notes.txt, docs/setup.txt]
*.pdf -> []
Lines containing "todo":
README.md:3: TODO: add screenshots
docs/notes.txt:2: todo: invoice template
src/app/Main.java:2: // TODO: read config
Disk usage of shop/:
photos/ 1.4 MB 2 file(s)
src/ 70 B 2 file(s)
docs/ 66 B 2 file(s)
README.md 47 B 1 file(s)
total 1.4 MB
Two largest files:
1.2 MB photos/team.png
240.0 KB photos/beach.jpg
| Glob | Matches |
|---|---|
*.java | Any name ending in .java |
*.{jpg,png} | Names ending in .jpg or .png |
report-??.csv | report- plus exactly two characters, then .csv |
* | Every file name |
How it works:
matcher.matches(path.getFileName())tests only the file name. Matching the full path with*.javawould fail, because*in a glob does not cross folder separators.Files.findwalks the whole tree and keeps paths for which the lambda returnstrue. Itsattrsparameter avoids a second disk call to checkisRegularFile.greplowers both the line and the search text, soTODO,todoandToDoall match.Files.readAllLinesthrowsMalformedInputExceptionfor files that are not valid UTF-8, and the loop simply skips those.Files.sizethrows a checkedIOException, which a stream lambda cannot throw.sizeOfwraps it inUncheckedIOException, a common pattern with the Java Files API.largestFilessorts by size withreversed(), then by path to break ties, andlimit(count)keeps the top results.
Build the Java File Manager Command-Line Tool
FileManagerApp maps commands such as ls, cp and grep to FileManager methods. Like the todo app, run returns an exit code instead of calling System.exit, so it can be tested.
package com.gocourse.files;
import java.io.IOException;
import java.nio.file.Path;
/** Command-line file manager: java -jar fm.jar <command> [arguments] */
public class FileManagerApp {
public static void main(String[] args) {
Path root = Path.of(System.getProperty("fm.root", "."));
try {
System.exit(run(args, new FileManager(root)));
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
System.exit(2);
}
}
/** Runs one command. Exit codes: 0 = success, 1 = user error, 2 = I/O error (thrown). */
static int run(String[] args, FileManager fm) throws IOException {
String command = args.length == 0 ? "help" : args[0];
try {
switch (command) {
case "ls" -> fm.list(arg(args, 1, ".")).forEach(f -> System.out.printf("%-6s %-22s %10s%n",
f.directory() ? "<DIR>" : "", f.name(), f.directory() ? "" : FileInfo.humanSize(f.size())));
case "tree" -> fm.tree(arg(args, 1, "."), Integer.parseInt(arg(args, 2, "10")))
.forEach(System.out::println);
case "cp" -> System.out.println("Copied " + fm.copy(need(args, 1), need(args, 2)) + " file(s)");
case "mv" -> {
fm.move(need(args, 1), need(args, 2));
System.out.println("Moved " + args[1] + " -> " + args[2]);
}
case "rm" -> System.out.println("Deleted " + fm.delete(need(args, 1)) + " entries");
case "find" -> fm.findByName(need(args, 1)).forEach(p -> System.out.println(fm.relative(p)));
case "grep" -> fm.grep(need(args, 1), arg(args, 2, "*")).forEach(System.out::println);
case "du" -> fm.usage(arg(args, 1, ".")).forEach(u -> System.out.printf("%10s %-22s %d file(s)%n",
FileInfo.humanSize(u.bytes()), u.name(), u.files()));
case "big" -> fm.largestFiles(Integer.parseInt(arg(args, 1, "5"))).forEach(f ->
System.out.printf("%10s %s%n", FileInfo.humanSize(f.size()), fm.relative(f.path())));
default -> {
System.out.println("""
Commands:
ls [folder] list a folder
tree [folder] [depth] show a folder tree
cp <from> <to> copy a file or folder
mv <from> <to> move or rename
rm <path> delete a file or folder
find <glob> find files by name, e.g. "*.java"
grep <text> [glob] find lines containing text
du [folder] size of each entry
big [count] largest files""");
return command.equals("help") ? 0 : 1;
}
}
return 0;
} catch (IllegalArgumentException e) { // also catches NumberFormatException
System.out.println("Error: " + e.getMessage());
return 1;
}
}
private static String arg(String[] args, int index, String fallback) {
return args.length > index ? args[index] : fallback;
}
private static String need(String[] args, int index) {
if (args.length <= index) throw new IllegalArgumentException("Missing argument. Run 'help' for usage");
return args[index];
}
}
How it works:
- The root folder comes from the system property
fm.rootand defaults to the current folder (.), so-Dfm.root=shoplimits every command toshop/. argreturns an optional argument or a default, andneedthrows a clear error when a required argument is missing.NumberFormatExceptionis a subclass ofIllegalArgumentException, sotree . abcis reported as a user error with exit code1.helpprints the command list with exit code0, while an unknown command prints the same list with exit code1.
Real-World Example: Organise a Project Folder With fm.jar
file-manager/
└── src/
└── com/
└── gocourse/
└── files/
├── FileInfo.java
├── FileManager.java
└── FileManagerApp.java
cd file-manager
javac -d out src/com/gocourse/files/*.java
jar --create --file fm.jar --main-class com.gocourse.files.FileManagerApp -C out .
# a short command for the terminal (Linux/macOS), limited to the shop/ folder
alias fm='java -Dfm.root=shop -jar fm.jar'
A session on the sample shop/ folder. Glob patterns are quoted so the shell passes them to Java unchanged.
$ fm tree
shop/
├── docs/
│ ├── notes.txt (37 B)
│ └── setup.txt (29 B)
├── photos/
│ ├── beach.jpg (240.0 KB)
│ └── team.png (1.2 MB)
├── src/
│ └── app/
│ ├── Cart.java (30 B)
│ └── Main.java (40 B)
└── README.md (47 B)
$ fm find '*.java'
src/app/Cart.java
src/app/Main.java
$ fm grep todo
README.md:3: TODO: add screenshots
docs/notes.txt:2: todo: invoice template
src/app/Main.java:2: // TODO: read config
$ fm cp docs archive/2026/docs
Copied 2 file(s)
$ fm mv photos/beach.jpg photos/holidays/goa-beach.jpg
Moved photos/beach.jpg -> photos/holidays/goa-beach.jpg
$ fm rm src/app/Cart.java
Deleted 1 entries
$ fm cp README.md archive/2026/docs
Error: Already exists: archive/2026/docs
$ echo $?
1
$ fm rm ../shop
Error: Refusing to delete the root folder
$ fm mv a
Error: Missing argument. Run 'help' for usage
$ fm du
1.4 MB photos/ 2 file(s)
66 B archive/ 2 file(s)
66 B docs/ 2 file(s)
47 B README.md 1 file(s)
40 B src/ 1 file(s)
$ fm big 3
1.2 MB photos/team.png
240.0 KB photos/holidays/goa-beach.jpg
47 B README.md
$ fm tree . 2
shop/
├── archive/
│ └── 2026/
├── docs/
│ ├── notes.txt (37 B)
│ └── setup.txt (29 B)
├── photos/
│ ├── holidays/
│ └── team.png (1.2 MB)
├── src/
│ └── app/
└── README.md (47 B)
How it works:
- Overview first.
treeshows the whole project, andfindandgreplocate the Java sources and every TODO note without opening an editor. - Organising.
cpbacked updocs/into a newarchive/2026/folder, andmvrenamed the beach photo while creatingphotos/holidays/on the way. - Safe by default. Copying onto an existing folder, deleting the root (
../shopnormalises to the root itself) and a missing argument all stop with exit code1and change nothing. - Space report.
dushows thatphotos/holds almost all the bytes, andbig 3names the exact files to compress or move. - Depth control.
tree . 2stops after two levels, which keeps the output short for large projects.
The next project, the Java Quiz App, loads questions from a file, shuffles them and scores the player's answers.