Useful Linux Commands for CS Courses#
If you are new to the terminal, start with Terminal Basics before using this reference.
The current course syllabus, assignment instructions, and applicable CSN or college policies take precedence over anything on this website.
Basic navigation#
Use these commands to find where you are and move around the Bellagio server.
| Command | Use |
|---|---|
pwd |
Print the directory you are currently in. |
ls |
List files in the current directory. |
ls -l |
List files with details. |
ls -a |
Include hidden files. |
cd directory |
Move into directory. |
cd .. |
Move up one directory. |
cd |
Return to your home directory. |
Files and directories#
| Command | Use |
|---|---|
mkdir cs135 |
Create a directory named cs135. |
mkdir -p cs202/project |
Create nested directories if they do not already exist. |
cp old.cpp new.cpp |
Copy a file. |
mv old.cpp new.cpp |
Rename or move a file. |
rm old.cpp |
Remove a file. Be careful: this does not move it to a trash folder. |
rmdir empty_directory |
Remove an empty directory. |
Viewing files#
| Command | Use |
|---|---|
cat main.cpp |
Print a short file to the terminal. |
less main.cpp |
View a longer file one screen at a time. Press q to quit. |
head main.cpp |
Show the first lines of a file. |
tail main.cpp |
Show the last lines of a file. |
Compiling and running C++ programs#
Use the compiler settings required by your course documents.
g++ $CXXFLAGS main.cpp -o main
./mainIf your program uses multiple source files, list them in the compile command:
g++ $CXXFLAGS main.cpp helper.cpp -o main
./mainIf the compiler prints errors, start with the first error message. Later messages may be caused by the first problem.
Debugging C++ programs#
Compile with debugging information:
g++ -ggdb $CXXFLAGS main.cpp -o mainStart GDB with the executable:
gdb ./mainFor basic GDB commands, see Debugging with GDB.
Checking C++ code with static analysis#
Static analysis tools inspect source code without running the program. They are extra checks, not replacements for compiling and testing.
Run cppcheck on one source file:
cppcheck --enable=all --std=c++14 --suppress=missingIncludeSystem main.cppRun cpplint on one source file:
cpplint main.cppFor more explanation and multi-file examples, see Lint and Static Analysis.
Checking your account#
| Command | Use |
|---|---|
passwd |
Change your password. |
quota |
Check disk usage and storage quota. |
history |
Show recent commands. |
clear |
Clear the terminal screen. |
reset |
Reset a terminal that is displaying incorrectly. |
Getting command help#
Many commands have manual pages:
man ls
man g++Press q to leave a manual page.
Some shell commands use built-in help:
help cdSafety habits#
- Read the command before pressing Enter.
- Be especially careful with
rm. - Keep backups of important work.
- Compile and run your program on Bellagio before submitting.
- Use the current syllabus and assignment instructions for submission rules.