Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

The Linux command line lets students control a computer by typing commands into a terminal. This cheat sheet covers the core commands used to move through folders, inspect files, manage files, and get help. It is useful for programming, cybersecurity, web development, data science, and working with remote servers.

Students need these commands because many professional computing tools are built around the terminal.

Key Facts

  • pwd prints the full path of the current working directory.
  • ls lists files and folders, and ls -la shows hidden files plus detailed permissions, owners, sizes, and dates.
  • cd foldername changes into a folder, cd .. moves up one level, and cd ~ returns to the home directory.
  • mkdir name creates a directory, touch file.txt creates an empty file, cp source destination copies, mv source destination moves or renames, and rm file deletes a file.
  • cat file.txt prints a file to the terminal, less file.txt opens a scrollable view, and head -n 10 file.txt shows the first 10 lines.
  • command > file writes output to a file, command >> file appends output, and command < file uses a file as input.
  • command1 | command2 sends the output of command1 into command2, such as cat names.txt | sort.
  • chmod permissions file changes file permissions, such as chmod u+x script.sh to give the owner execute permission.

Vocabulary

Terminal
A text-based program where users type commands to control the operating system.
Shell
A command interpreter that reads typed commands and runs programs, with Bash being a common Linux shell.
Directory
A folder in the file system that can contain files and other directories.
Path
The location of a file or directory, such as /home/student/projects.
Option
A modifier added to a command, often starting with -, that changes how the command works.
Permission
A rule that controls whether a user can read, write, or execute a file or directory.

Common Mistakes to Avoid

  • Using rm without checking the filename is dangerous because deleted files are often not moved to a trash folder and may be hard to recover.
  • Forgetting spaces between a command and its arguments is wrong because the shell reads cdprojects as one command instead of cd projects.
  • Confusing > and >> can destroy data because > overwrites a file while >> adds new output to the end.
  • Running commands from the wrong directory causes errors because relative paths depend on the current working directory shown by pwd.
  • Using sudo when it is not needed is risky because administrator privileges can change or delete important system files.

Practice Questions

  1. 1 You are in /home/student and need to enter /home/student/projects. What command should you type?
  2. 2 Write a command that creates a directory named labs and then creates an empty file named notes.txt inside it.
  3. 3 A file named data.txt has 50 lines. What command shows only the first 10 lines?
  4. 4 Explain why a programmer might use a pipe, such as ls | sort, instead of running two completely separate commands.