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.
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.
- Wrong folder:
file not foundfor a file you can see → checkpwdandls, thencdto the right folder. Review: Moving around folders (opens in a new tab) - Typo or old window: "not recognized" / "command not found" → check the spelling; after a PATH change, open a new window. Review: Environment variables, PATH and redirection (opens in a new tab)
- Space in a name:
cd My Notesfails → writecd "My Notes"or press Tab. Review: Moving around folders (opens in a new tab) - Silent overwrite and delete:
cp,mvand>replace files without asking, andrmhas no undo. Review: Creating, copying and deleting files (opens in a new tab)
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
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, andHello.javais two levels down. javaclooks for the file only in the working directory, so it reportsfile not foundand 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.
Example 2 · Permission denied, then chmod +x
ls -l./build.shchmod +x build.sh./build.sh$ 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 -llists 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.shgivesPermission 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.
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.
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.
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.
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.
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.)
cd My Notesecho "Revise loops" > todo.txtecho "Revise OOP" > todo.txtecho "Push to GitHub" > todo.txtcat todo.txtRevise loops Revise OOP Push to GitHub
Exercise 6· Medium
Still in My Notes, print only the last line of todo.txt.
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?
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.
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.