Skip to lesson

Common mistakes, a first look at Linux and practice

A review of this module. Skip it if you feel confident; the next module does not need it.

Fix the mistakes

The slips that cost marks in this module. Spot each one, then check the fix.

I'm on:

Showing steps for Windows. They are marked “On Windows” below.

Most terminal problems come from a few slips: the wrong folder, a typo, a space in a name, or a file replaced without warning. Knowing them by sight turns a confusing error into a ten-second fix.

Mistakes and fixes at a glance

Check this list first whenever a command surprises you. Each slip is taught in the lesson linked after it.

On Windows, also watch for commands copied from Mac or Linux guides: touch, ls -a and rm -rf fail in PowerShell. Use New-Item, ls -Force and rm -r instead.

The wrong folder: file not found

Priya opens a new terminal and compiles her program at once. Hello.java is in college-projects/java-basics, but a new window starts in her home folder.

Example 1 · javac in the wrong folder

Windows PowerShell
PS C:\Users\Priya> javac Hello.javaerror: file not found: Hello.java
Usage: javac <options> <source files>
use --help for a list of possible options

What this code does

  • The prompt PS C:\Users\Priya> already shows the problem: the terminal is in the home folder, and Hello.java is two levels down.
  • javac looks for the file only in the working directory, so it reports file not found and prints how to use it.

The fix is to move first, then compile: cd college-projects/java-basics, then javac Hello.java. When a file "is not found" but you can see it, the folder is almost always the problem, not the file.

A first look at Linux

Linux is a free operating system, like Windows or macOS, that runs most servers and cloud computers. Its terminal usually runs bash, which takes the same commands as the Mac Terminal.

When you put a project on a server, you meet Linux. Paths start at /, and ls, cd, mkdir -p, cp, mv and rm work as on a Mac. Two things are new: names are case-sensitive, and files carry permissions.

The permission text -rwxr-xr-- read in four parts. The first dash means a file (d would mean a folder). rwx: the owner may read, write and run it. r-x: the group may read and run it. r--: everyone else may only read it.

Example 2 · Permission denied, then chmod +x

Terminal
ls -l./build.shchmod +x build.sh./build.sh
Output (on a Linux server)
$ ls -l
total 8
-rw-r--r-- 1 priya priya 111 Oct 21 10:30 Hello.java
-rw-r--r-- 1 priya priya  62 Oct 21 10:30 build.sh
$ ./build.sh
bash: ./build.sh: Permission denied
$ chmod +x build.sh
$ ./build.sh
Building the marks project...
Done.

What this code does

  • ls -l lists files in long form. -rw-r--r-- means: a file, the owner may read and write, the group and everyone else may only read. Nobody may run it, so ./build.sh gives Permission denied.
  • chmod +x (change mode) adds the x (run) right, and the script runs. ./ means "the file in this folder": Linux never runs a program from the current folder unless you say so.

sudo runs one command as the administrator after asking for your password, for example sudo apt install git to install Git on Ubuntu. Use it only when a trusted guide says so, never to "fix" Permission denied in your own project folder.

Linux names are case-sensitive: Marks.txt and marks.txt are two different files. A program that works on your Windows laptop can fail on a server because of one capital letter.

Module quiz

Questions from the whole module. Your first answer is your score.

Problems

Graded easy to hard, using everything from this module.

Try each one yourself first. Use the hint if you get stuck. Mark it as done when it works.

Exercise 1· Easy

Open a new terminal, go into your college-projects folder, print where you are, and list what is in it.

Sample output (your names will differ)
Windows (PowerShell): Path C:\Users\Priya\college-projects, then a table with java-basics, marks-app and marks.txt
macOS (Terminal): /Users/priya/college-projects, then java-basics  marks-app  marks.txt

Exercise 2· Easy

Inside college-projects, create a folder practice/notes with one command and go into practice.

Sample output (your user name will differ)
Windows (PowerShell):
Path
----
C:\Users\Priya\college-projects\practice

macOS (Terminal):
/Users/priya/college-projects/practice

Exercise 3· Easy

In practice, build todo.txt with the two lines Revise loops and Push to GitHub using echo and redirection, then show it.

Expected output
Revise loops
Push to GitHub

Exercise 4· Medium

Copy todo.txt to todo-backup.txt, rename the backup to todo-old.txt, move it into notes, and list notes.

Sample output
Windows (PowerShell): a table with one file, todo-old.txt
macOS (Terminal): todo-old.txt

Exercise 5· Medium

Each line below has one mistake. Fix them so that the last command prints the three lines shown. (Create the folder My Notes in practice first, with File Explorer or Finder.)

Terminal
cd My Notesecho "Revise loops" > todo.txtecho "Revise OOP" > todo.txtecho "Push to GitHub" > todo.txtcat todo.txt
Expected output
Revise loops
Revise OOP
Push to GitHub

Exercise 6· Medium

Still in My Notes, print only the last line of todo.txt.

Expected output
Push to GitHub

Exercise 7· Hard

Find which java file runs on your computer, and print JAVA_HOME. Do they point to the same JDK?

Sample output (your folders will differ)
Windows (PowerShell):
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk-19\bin\java.exe
C:\Program Files\Java\jdk-19

macOS (Terminal):
/usr/bin/java
/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home

Exercise 8· Hard

Clean up safely: go back to college-projects, check where you are and what is there, delete the whole practice folder, and list again to show it is gone.

Sample output
Before: ls shows java-basics, marks-app, marks.txt, practice
After: ls shows java-basics, marks-app, marks.txt

What's next

You finished the preview of The Command Line

Java Programming has 26 sections, 252 modules and 1949 lessons. An account opens every lesson and saves your progress.

Finish up

Mark this lesson complete

This is the last lesson in this section.