Skip to content

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

pwd

Go to your home directory

cd ~

Create a training directory

mkdir linux_training

Enter the training directory

cd linux_training

Verify you're in the right place

pwd

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

pwd

ls - List Files and Folders

List files in current directory

ls

List files with detailed information (long format)

ls -l

List files with human-readable sizes (KB, MB, GB)

ls -lh

List all files including hidden ones (starting with .)

ls -a

cd - Change Directory

Go to home directory

cd ~

Go back to training directory

cd ~/linux_training

Go up one level (to parent directory)

cd ..

Check where you are now

pwd

Go back to training directory

cd ~/linux_training

Go back to previous directory

cd -

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

cd ~/linux_training

mkdir - Make Directory

Create a folder called "vectri_runs"

mkdir vectri_runs

List to see the new folder

ls

Create nested folders (parent folders created automatically with -p)

mkdir -p data/raw/temperature

Create multiple folders at once

mkdir results scripts output

List all folders

ls

touch - Create Empty Files

Create a new empty file

touch hello.txt

Create multiple files at once

touch data1.txt data2.txt data3.txt

Create a file in a subfolder

touch results/summary.txt

List files to see what you created

ls -lh

3. Copying, Moving, and Renaming

cp - Copy Files

Copy a file

cp hello.txt hello_backup.txt

List to see both files

ls

Copy a file to another directory

cp hello.txt results/

Copy a folder and all its contents (recursive with -r)

cp -r vectri_runs vectri_runs_backup

List to see the copied folder

ls

mv - Move or Rename

Rename a file

mv hello_backup.txt hello_copy.txt

Move a file into a folder

mv data1.txt data/

Move multiple files into a folder

mv data2.txt data3.txt data/

Rename a folder

mv vectri_runs_backup old_runs

List to see changes

ls

rm - Remove Files and Folders

Be Careful!

The rm command permanently deletes files. There is no trash/recycle bin!

Remove a single file

rm hello_copy.txt

Remove a folder and all its contents (recursive with -r)

rm -r old_runs

Force remove without confirmation (-rf) - USE WITH EXTREME CAUTION!

# Don't run this unless you're sure!
# rm -rf dangerous_folder

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 >

echo "Temperature data for Nairobi" > data/temperature.txt

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

cat data/temperature.txt

head - Show First Lines

Show first 3 lines

head -n 3 data/temperature.txt

tail - Show Last Lines

Show last 2 lines

tail -n 2 data/temperature.txt

less - View File Page by Page

View file with scrolling (press q to quit)

less data/temperature.txt

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

vi data/temperature.txt

Edit a file with vim (improved version)

vim data/temperature.txt

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

vi ~/linux_training/data/notes.txt

Practice these steps:

  1. Press i to enter Insert Mode
  2. Type: "This is my first vi file"
  3. Press Enter for a new line
  4. Type: "Learning vi is essential for Linux"
  5. Press Esc to return to Normal Mode
  6. Type :wq and press Enter to save and quit

Verify the file was created

cat ~/linux_training/data/notes.txt

Open the file again and add more content

vi ~/linux_training/data/notes.txt

Practice these steps:

  1. Press G to go to the last line
  2. Press o to open a new line below and enter Insert Mode
  3. Type: "Vi has powerful editing capabilities"
  4. Press Esc then type :wq to save and quit

Open and delete a line

vi ~/linux_training/data/notes.txt

Practice these steps:

  1. Press j to move down to the second line
  2. Press dd to delete the entire line
  3. Press u to undo the deletion
  4. Type :q! to quit without saving

Vi Survival Guide

If you get stuck in vi:

  1. Press Esc multiple times to ensure you're in Normal Mode
  2. Type :q! and press Enter to quit without saving

If you want to save your changes:

  1. Press Esc to ensure you're in Normal Mode
  2. Type :wq and press Enter to save and quit

Nano Alternative

If you prefer a simpler editor, nano is also available on most systems:

nano data/temperature.txt
  • 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

cd ~/linux_training
touch results/output1.nc results/output2.nc results/data.csv

find - Find Files by Name

Find all .txt files in current directory and subdirectories

find . -name "*.txt"

Find all .nc files

find . -name "*.nc"

Find directories only

find . -type d

grep - Search Text in Files

Search for a word in a file

grep "Temperature" data/temperature.txt

Search for a word (case-insensitive with -i)

grep -i "temperature" data/temperature.txt

Search recursively in all files (-r)

grep -r "Nairobi" .

Search command history

history | grep "mkdir"

6. Pipes and Redirection

Pipes and redirection let you combine commands and save output.

> - Redirect Output (Overwrite)

Save directory listing to a file

ls -lh > file_list.txt

View the created file

cat file_list.txt

>> - Redirect Output (Append)

Add more content to the file

echo "--- End of List ---" >> file_list.txt

View the updated file

cat file_list.txt

| - Pipe Output to Another Command

List files and filter for .txt files

ls -l | grep ".txt"

Count how many files/folders are in current directory

ls | wc -l

Show disk usage and display only the top 5

du -sh * | sort -hr | head -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)

./scripts/hello.sh

chmod - Change File Permissions

Make the script executable

chmod +x scripts/hello.sh

Now run it

./scripts/hello.sh

View file permissions

ls -l scripts/hello.sh

Permission Notation

  • r = read (4)
  • w = write (2)
  • x = execute (1)
  • chmod 755 = owner can read/write/execute, others can read/execute
  • chmod +x = add execute permission for everyone

8. Installing Software (Ubuntu/Debian/WSL)

Update package list

sudo apt update

Install VECTRI dependencies

sudo apt install git gfortran libnetcdf-dev libnetcdff-dev netcdf-bin cdo ncview nco

Install other useful tools

sudo apt install ncdu tree htop

9. Environment Variables

Environment variables store configuration that programs can use.

Temporary Variables (Current Session Only)

Set a temporary variable

export MYVAR="hello"

Display the variable

echo $MYVAR

Display your home directory variable

echo $HOME

Permanent Variables (Add to ~/.bashrc)

Open your .bashrc file with vi

vi ~/.bashrc

Add these lines at the end (for VECTRI):

  1. Press G to go to the end of the file
  2. Press o to open a new line and enter Insert Mode
  3. 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"
  1. Press Esc to return to Normal Mode
  2. Type :wq and press Enter to save and quit

Alternative: Use echo to append (no editor needed)

echo 'export VECTRI=$HOME/vectri' >> ~/.bashrc
echo 'export NETCDF_LIB=$(nf-config --flibs)' >> ~/.bashrc
echo 'export NETCDF_INCLUDE=$(nf-config --fflags)' >> ~/.bashrc
echo 'export FC=$(nf-config --fc)' >> ~/.bashrc
echo 'alias vectri="$VECTRI/vectri"' >> ~/.bashrc

Apply the changes immediately

source ~/.bashrc

Test the variable

echo $VECTRI

10. Git - Version Control

Git helps you download and update code repositories.

Clone a Repository (First Time)

Clone the VECTRI repository

cd ~
git clone https://gitlab.com/tompkins/vectri.git

Enter the repository

cd vectri

List the contents

ls -la

Update an Existing Repository

Make sure you're in the repository directory

cd ~/vectri

Get the latest updates

git pull

Check the status

git status

11. Process Management

Learn how to view and manage running programs.

View Running Processes

List all running processes

ps aux

View processes in real-time (press q to quit)

top

Better process viewer (if htop is installed)

htop

Find specific processes (e.g., python)

ps aux | grep python

Stop Processes

Kill a process by ID (replace 12345 with actual process ID)

# kill 12345

Force kill a process (use only when normal kill doesn't work)

# kill -9 12345

Kill processes by name

# pkill -f vectri

12. Disk Space Management

Check how much space you're using.

Show disk space usage (human-readable format)

df -h

Show size of current directory

du -sh .

Show size of each item in current directory

du -sh *

Show size of training directory

cd ~
du -sh linux_training

Interactive disk usage explorer (if installed)

ncdu ~/linux_training

13. Compressing and Archiving

Save space by compressing files and folders.

Create a compressed archive of results folder

cd ~/linux_training
tar -czvf results_backup.tar.gz results/

tar flags explained

  • c = create
  • z = compress with gzip
  • v = verbose (show progress)
  • f = file name follows

List contents of archive without extracting

tar -tzvf results_backup.tar.gz

Extract the archive

mkdir extracted
tar -xzvf results_backup.tar.gz -C extracted/

Create a zip archive

zip -r data_backup.zip data/

Extract a zip file

mkdir unzipped
unzip data_backup.zip -d unzipped/

14. Downloading Files

Download files from the internet.

wget - Download Files

Download a file

cd ~/linux_training
wget https://raw.githubusercontent.com/python/cpython/main/README.rst

Download with a custom name

wget -O python_readme.txt https://raw.githubusercontent.com/python/cpython/main/README.rst

curl - Another Download Tool

Download a file

curl -O https://raw.githubusercontent.com/python/cpython/main/LICENSE

View file without downloading

curl https://raw.githubusercontent.com/python/cpython/main/README.rst | head -20

Create shortcuts to files or folders in other locations.

Create a symbolic link to a folder

cd ~/linux_training
ln -s ~/linux_training/data data_link

List to see the link (arrow shows where it points)

ls -lh

Access files through the link

ls data_link/

Remove the link (not the original folder!)

rm data_link

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

chmod +x scripts/analyze_data.sh

Run the script

./scripts/analyze_data.sh

17. Useful Shortcuts and Tips

Command Line Shortcuts

Clear the terminal screen

clear

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

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

cat ~/linux_cheat_sheet.txt

Always keep it handy

less ~/linux_cheat_sheet.txt

19. Complete Hands-On Practice Workflow

Let's put everything together! Copy and run these commands one by one.

Go to your training directory

cd ~/linux_training

Create a project structure

mkdir -p vectri_project/{data,scripts,results,logs}

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

chmod +x vectri_project/scripts/process.sh
./vectri_project/scripts/process.sh

View the log file

cat vectri_project/logs/process.log

Create a compressed backup

tar -czvf vectri_project_backup.tar.gz vectri_project/

Check the backup size

ls -lh vectri_project_backup.tar.gz

View the project structure

tree vectri_project/

Clean up (optional)

# Uncomment to remove the project
# rm -r vectri_project
# rm vectri_project_backup.tar.gz

20. Troubleshooting Common Issues

Permission Denied

If you get "Permission denied" when running a script:

chmod +x your_script.sh

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:

df -h

Find large files:

du -sh * | sort -hr | head -10

File Already Exists

To force overwrite when copying:

cp -f source destination

To force overwrite when moving:

mv -f source destination

🎉 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

In Partnership With