Basic Linux Commands for VECTRI Users¶
This is a hands-on, practical guide for people who have never (or barely) used Linux before but want to install and run VECTRI (or any scientific software).
Cross-Platform Compatibility
Everything here works the same on Ubuntu, Linux Mint, WSL2 (Windows), Mac (Terminal) and most Linux servers.
Opening the Terminal¶
Press Ctrl + Alt + T
Press Cmd + Space → type "Terminal"
Type "wsl" in Windows search
Getting Started: Create Your Training Directory¶
Let's start by creating a dedicated folder for practicing these commands. Copy and paste each command below into your terminal.
Show your current location
Go to your home directory
Create a training directory
Enter the training directory
Verify you're in the right place
You should see something like /home/yourname/linux_training or /Users/yourname/linux_training
1. Navigation Commands¶
pwd - Print Working Directory¶
Show where you are right now
ls - List Files and Folders¶
List files in current directory
List files with detailed information (long format)
List files with human-readable sizes (KB, MB, GB)
List all files including hidden ones (starting with .)
cd - Change Directory¶
Go to home directory
Go back to training directory
Go up one level (to parent directory)
Check where you are now
Go back to training directory
Go back to previous directory
2. Creating Folders and Files¶
Let's create some practice files and folders in your training directory.
Make sure you're in the training directory
mkdir - Make Directory¶
Create a folder called "vectri_runs"
List to see the new folder
Create nested folders (parent folders created automatically with -p)
Create multiple folders at once
List all folders
touch - Create Empty Files¶
Create a new empty file
Create multiple files at once
Create a file in a subfolder
List files to see what you created
3. Copying, Moving, and Renaming¶
cp - Copy Files¶
Copy a file
List to see both files
Copy a file to another directory
Copy a folder and all its contents (recursive with -r)
List to see the copied folder
mv - Move or Rename¶
Rename a file
Move a file into a folder
Move multiple files into a folder
Rename a folder
List to see changes
rm - Remove Files and Folders¶
Be Careful!
The rm command permanently deletes files. There is no trash/recycle bin!
Remove a single file
Remove a folder and all its contents (recursive with -r)
Force remove without confirmation (-rf) - USE WITH EXTREME CAUTION!
4. Viewing and Editing Files¶
Let's create a file with some content and practice viewing it.
Create a file with content using echo and >
Add more lines using >>
echo "Date: 2025-01-15" >> data/temperature.txt
echo "Morning: 18°C" >> data/temperature.txt
echo "Afternoon: 26°C" >> data/temperature.txt
echo "Evening: 22°C" >> data/temperature.txt
cat - Show Entire File¶
Display the whole file
head - Show First Lines¶
Show first 3 lines
tail - Show Last Lines¶
Show last 2 lines
less - View File Page by Page¶
View file with scrolling (press q to quit)
Less Navigation
- Press Space to go down one page
- Press b to go back one page
- Press q to quit
- Press / to search
vi/vim - Powerful Text Editor¶
Vi (or Vim) is the standard text editor available on virtually every Linux/Unix system. Learning it is essential for working on remote servers.
Edit a file with vi
Edit a file with vim (improved version)
Vi Has Two Main Modes
- Normal Mode (default) - for navigation and commands
- Insert Mode - for typing text
Press i to enter Insert Mode, press Esc to return to Normal Mode.
Essential Vi Commands¶
Entering Insert Mode (to type text):
| Key | Action |
|---|---|
i | Insert before cursor |
I | Insert at beginning of line |
a | Append after cursor |
A | Append at end of line |
o | Open new line below |
O | Open new line above |
Saving and Quitting (in Normal Mode):
| Command | Action |
|---|---|
:w | Save (write) file |
:q | Quit (only if no changes) |
:wq | Save and quit |
:q! | Quit without saving (force) |
:wq! | Save and quit (force) |
ZZ | Save and quit (shortcut) |
Navigation (in Normal Mode):
| Key | Action |
|---|---|
h | Move left |
j | Move down |
k | Move up |
l | Move right |
0 | Go to beginning of line |
$ | Go to end of line |
gg | Go to first line |
G | Go to last line |
:10 | Go to line 10 |
Editing (in Normal Mode):
| Key | Action |
|---|---|
x | Delete character under cursor |
dd | Delete entire line |
dw | Delete word |
yy | Copy (yank) entire line |
p | Paste after cursor |
P | Paste before cursor |
u | Undo last change |
Ctrl + r | Redo |
Search (in Normal Mode):
| Command | Action |
|---|---|
/word | Search forward for "word" |
?word | Search backward for "word" |
n | Go to next match |
N | Go to previous match |
Search and Replace:
| Command | Action |
|---|---|
:%s/old/new/g | Replace all "old" with "new" in file |
:s/old/new/g | Replace all "old" with "new" in current line |
:%s/old/new/gc | Replace with confirmation |
Hands-On Vi Practice¶
Create a new file with vi
Practice these steps:
- Press
ito enter Insert Mode - Type: "This is my first vi file"
- Press
Enterfor a new line - Type: "Learning vi is essential for Linux"
- Press
Escto return to Normal Mode - Type
:wqand pressEnterto save and quit
Verify the file was created
Open the file again and add more content
Practice these steps:
- Press
Gto go to the last line - Press
oto open a new line below and enter Insert Mode - Type: "Vi has powerful editing capabilities"
- Press
Escthen type:wqto save and quit
Open and delete a line
Practice these steps:
- Press
jto move down to the second line - Press
ddto delete the entire line - Press
uto undo the deletion - Type
:q!to quit without saving
Vi Survival Guide
If you get stuck in vi:
- Press
Escmultiple times to ensure you're in Normal Mode - Type
:q!and pressEnterto quit without saving
If you want to save your changes:
- Press
Escto ensure you're in Normal Mode - Type
:wqand pressEnterto save and quit
Nano Alternative
If you prefer a simpler editor, nano is also available on most systems:
- Ctrl + O to save
- Ctrl + X to exit
- Ctrl + K to cut a line
- Ctrl + U to paste
5. Finding and Searching¶
Let's practice finding files and searching for text.
Create more files for practice
find - Find Files by Name¶
Find all .txt files in current directory and subdirectories
Find all .nc files
Find directories only
grep - Search Text in Files¶
Search for a word in a file
Search for a word (case-insensitive with -i)
Search recursively in all files (-r)
Search command history
6. Pipes and Redirection¶
Pipes and redirection let you combine commands and save output.
> - Redirect Output (Overwrite)¶
Save directory listing to a file
View the created file
>> - Redirect Output (Append)¶
Add more content to the file
View the updated file
| - Pipe Output to Another Command¶
List files and filter for .txt files
Count how many files/folders are in current directory
Show disk usage and display only the top 5
7. Permissions¶
Let's create a script and make it executable.
Create a simple shell script
cat > scripts/hello.sh << 'EOF'
#!/bin/bash
echo "Hello from VECTRI training!"
echo "Today is $(date)"
EOF
Try to run it (it will fail because it's not executable)
chmod - Change File Permissions¶
Make the script executable
Now run it
View file permissions
Permission Notation
r= read (4)w= write (2)x= execute (1)chmod 755= owner can read/write/execute, others can read/executechmod +x= add execute permission for everyone
8. Installing Software (Ubuntu/Debian/WSL)¶
Update package list
Install VECTRI dependencies
Install other useful tools
9. Environment Variables¶
Environment variables store configuration that programs can use.
Temporary Variables (Current Session Only)¶
Set a temporary variable
Display the variable
Display your home directory variable
Permanent Variables (Add to ~/.bashrc)¶
Open your .bashrc file with vi
Add these lines at the end (for VECTRI):
- Press
Gto go to the end of the file - Press
oto open a new line and enter Insert Mode - Type the following lines:
export VECTRI=$HOME/vectri
export NETCDF_LIB=$(nf-config --flibs)
export NETCDF_INCLUDE=$(nf-config --fflags)
export FC=$(nf-config --fc)
alias vectri="$VECTRI/vectri"
- Press
Escto return to Normal Mode - Type
:wqand pressEnterto save and quit
Alternative: Use echo to append (no editor needed)
Apply the changes immediately
Test the variable
10. Git - Version Control¶
Git helps you download and update code repositories.
Clone a Repository (First Time)¶
Clone the VECTRI repository
Enter the repository
List the contents
Update an Existing Repository¶
Make sure you're in the repository directory
Get the latest updates
Check the status
11. Process Management¶
Learn how to view and manage running programs.
View Running Processes¶
List all running processes
View processes in real-time (press q to quit)
Better process viewer (if htop is installed)
Find specific processes (e.g., python)
Stop Processes¶
Kill a process by ID (replace 12345 with actual process ID)
Force kill a process (use only when normal kill doesn't work)
Kill processes by name
12. Disk Space Management¶
Check how much space you're using.
Show disk space usage (human-readable format)
Show size of current directory
Show size of each item in current directory
Show size of training directory
Interactive disk usage explorer (if installed)
13. Compressing and Archiving¶
Save space by compressing files and folders.
Create a compressed archive of results folder
tar flags explained
c= createz= compress with gzipv= verbose (show progress)f= file name follows
List contents of archive without extracting
Extract the archive
Create a zip archive
Extract a zip file
14. Downloading Files¶
Download files from the internet.
wget - Download Files¶
Download a file
Download with a custom name
curl - Another Download Tool¶
Download a file
View file without downloading
15. Symbolic Links¶
Create shortcuts to files or folders in other locations.
Create a symbolic link to a folder
List to see the link (arrow shows where it points)
Access files through the link
Remove the link (not the original folder!)
16. Bash Scripting Basics¶
Create a simple script to automate tasks.
Create an analysis script
cat > scripts/analyze_data.sh << 'EOF'
#!/bin/bash
# VECTRI Data Analysis Script
echo "========================================"
echo "VECTRI Training Data Analysis"
echo "========================================"
echo ""
echo "Date: $(date)"
echo "User: $USER"
echo "Location: $(pwd)"
echo ""
echo "Files in data directory:"
ls -lh ~/linux_training/data/
echo ""
echo "Total disk space used:"
du -sh ~/linux_training
echo ""
echo "Analysis complete!"
EOF
Make it executable
Run the script
17. Useful Shortcuts and Tips¶
Command Line Shortcuts¶
Clear the terminal screen
Or press: Ctrl + L
Cancel current command
Press: Ctrl + C
Auto-complete file/folder names
Type first few letters and press: Tab
View command history
Run the last command again
18. Quick Reference Cheat-Sheet¶
Create a cheat sheet file
cat > ~/linux_cheat_sheet.txt << 'EOF'
=== LINUX COMMAND CHEAT SHEET ===
Navigation:
pwd - where am I?
ls -lh - list files nicely
cd folder - go into folder
cd .. - go up one level
cd ~ - go home
Files/Folders:
mkdir folder - create folder
touch file - create empty file
cp file1 file2 - copy file
mv old new - move/rename
rm file - delete file
rm -r folder - delete folder
Viewing Files:
cat file - show entire file
less file - view page by page
head file - first 10 lines
tail file - last 10 lines
Vi Editor:
vi file - edit file with vi
i - enter Insert Mode
Esc - return to Normal Mode
:w - save file
:q - quit
:wq - save and quit
:q! - quit without saving
dd - delete line
yy - copy line
p - paste
u - undo
/word - search for word
Finding:
find . -name "*.txt" - find files
grep "word" file - search in file
Redirection:
cmd > file - save output
cmd >> file - append output
cmd1 | cmd2 - pipe commands
System:
df -h - disk space
du -sh folder - folder size
ps aux - show processes
top - monitor processes
chmod +x file - make executable
Git:
git clone URL - download repo
git pull - update repo
git status - check status
Package Management (Ubuntu/Debian):
sudo apt update - update package list
sudo apt install package - install software
EOF
View your cheat sheet
Always keep it handy
19. Complete Hands-On Practice Workflow¶
Let's put everything together! Copy and run these commands one by one.
Go to your training directory
Create a project structure
Create some data files
echo "Station,Date,Temperature,Humidity" > vectri_project/data/weather.csv
echo "Nairobi,2025-01-15,26,60" >> vectri_project/data/weather.csv
echo "Nairobi,2025-01-16,28,55" >> vectri_project/data/weather.csv
echo "Mombasa,2025-01-15,32,75" >> vectri_project/data/weather.csv
Create a processing script
cat > vectri_project/scripts/process.sh << 'EOF'
#!/bin/bash
echo "Processing weather data..."
echo "Date: $(date)" > vectri_project/logs/process.log
echo "Processing complete" >> vectri_project/logs/process.log
cat vectri_project/data/weather.csv
EOF
Make script executable and run it
View the log file
Create a compressed backup
Check the backup size
View the project structure
Clean up (optional)
20. Troubleshooting Common Issues¶
Permission Denied¶
If you get "Permission denied" when running a script:
Command Not Found¶
If you get "command not found":
# For apt-based systems (Ubuntu/Debian)
sudo apt update
sudo apt install package-name
# Check if it's in your PATH
echo $PATH
No Space Left on Device¶
Check disk space:
Find large files:
File Already Exists¶
To force overwrite when copying:
To force overwrite when moving:
🎉 Congratulations!¶
You now speak basic Linux! You've learned:
✅ Navigation and file management
✅ Creating, editing, and viewing files
✅ Copying, moving, and removing files
✅ Searching and finding files
✅ Using pipes and redirection
✅ Managing permissions
✅ Installing software
✅ Version control with Git
✅ Basic scripting
✅ Troubleshooting common issues
Keep practicing these commands, and they'll become second nature! Happy computing! 🚀
📝 Test Your Knowledge¶
Ready to test your understanding of basic Linux commands? Take the interactive quiz to assess your knowledge and reinforce what you've learned.
Take the Linux Commands Quiz →
🔗 Additional Resources¶
- Ubuntu Command Line Tutorial
- The Linux Command Line (Free Book)
- ExplainShell - Explains any shell command