DEV Community

crow
crow

Posted on

Basic Linux commands every AI tinkerer should know

Basic Linux Commands Every AI Tinkerer Should Know

If you’re just starting a home‑lab or an AI workstation, the first hurdle is usually the terminal. Even if you’re comfortable with the command line, there are a handful of commands that will make your life a lot easier when you’re juggling data sets, training models, and managing containers. Below is a practical, beginner‑friendly guide that covers the essentials—complete with concrete examples and short snippets you can copy‑paste right away.

TL;DR

  1. Navigation (cd, ls, pwd)
  2. File manipulation (cp, mv, rm, touch, nano)
  3. System info & monitoring (top, htop, free, df, du, ps)
  4. Networking (ping, curl, wget, ssh)
  5. Package management (apt, yum, dnf, pacman, pip)
  6. Process & job control (nohup, screen, tmux)
  7. Shell tricks (grep, awk, sed, cut, sort, uniq)
  8. Disk space & permissions (chmod, chown, umask)

1️⃣ Navigation – Getting to the Right Folder

Command What it does Example
pwd Print working directory pwd/home/alex/projects/ai
ls -la List all files, including hidden ones, with details ls -la /etc
cd .. Move up one directory cd ../home/alex/projects
cd ~ Go to your home folder cd ~
cd - Return to the previous directory cd -

Tip:

Use tab‑completion to avoid typos. Type the first few letters of a file or folder and press <Tab>.


2️⃣ File Manipulation – Creating, Moving, Deleting

Command What it does Example
touch filename.txt Create an empty file (or update timestamp) touch notes.md
cp source dest Copy files or directories cp model.pt /mnt/ssd/models/
mv oldname newname Move or rename mv data.csv backup/data-$(date +%F).csv
rm file Delete a single file rm temp.log
rm -r dir Recursively delete a directory rm -rf build/
nano filename Simple text editor in the terminal nano README.md

Safety:

Use -i with rm to get a prompt: rm -ri temp/.


3️⃣ System Info & Monitoring – Keep an Eye on Resources

# CPU + Memory usage (top)
top

# Interactive, easier interface (install first)
sudo apt install htop
htop

# RAM usage summary
free -h

# Disk free space
df -h

# Disk usage of a directory
du -sh ~/datasets/

# Find all running processes
ps aux | grep python
Enter fullscreen mode Exit fullscreen mode

Why it matters:

Training deep‑learning models can exhaust GPU, CPU or RAM. These commands let you spot bottlenecks before your job crashes.


4️⃣ Networking – Test Connectivity & Download Data

Command What it does Example
ping host Check if a host is reachable ping google.com -c 4
curl url Fetch content (shows response header by default) curl -I https://huggingface.co/bert-base-uncased
wget url Download files directly wget https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
ssh user@host Secure shell into another machine ssh alex@192.168.1.10

Download large datasets

Use aria2c -x 16 -s 16 url for multi‑threaded downloads.


5️⃣ Package Management – Installing Software

Distribution Install command Example
Ubuntu/Debian sudo apt install package sudo apt install python3-pip git
CentOS/Fedora sudo yum install package (or dnf) sudo dnf install gcc-c++
Arch Linux sudo pacman -S package sudo pacman -S htop
Python packages pip install package pip install torch torchvision

Virtual environments

python3 -m venv ~/ai-env
source ~/ai-env/bin/activate
Enter fullscreen mode Exit fullscreen mode

6️⃣ Process & Job Control – Keep Things Running

Command What it does Example
nohup command & Run a job that keeps running after logout nohup python train.py > log.txt 2>&1 &
screen Terminal multiplexer (install first) screen -S ai_session then <Ctrl-A d> to detach
tmux Another terminal multiplexer, more modern tmux new -s training

Tip:

In tmux, press <Ctrl-B c> to create a new window. Press <Ctrl-B w> to switch between windows.


7️⃣ Shell Tricks – Filtering & Manipulating Text

Command What it does Example
grep pattern file Search for text patterns grep -i "error" logs/*.log
awk '{print $1}' file Print the first column awk '{print $1}' data.csv
sed 's/old/new/g' file Replace text in place (use with -i) sed -i 's/localhost/0.0.0.0/g' config.yaml
cut -d',' -f1,3 file Cut specific fields by delimiter cut -d',' -f2 data.csv
`sort file uniq -c` Count unique lines

Pipeline example – Count how many times each model appears in a log:

grep "Model:" train.log | awk '{print $3}' | sort | uniq -c | sort -nr
Enter fullscreen mode Exit fullscreen mode

8️⃣ Disk Space & Permissions – Protect Your Data

Command What it does Example
chmod 755 file Set read/write/execute permissions chmod 700 ~/.ssh/id_rsa
chown user:group file Change ownership sudo chown alex:alex data/
umask 022 Default permission mask for new files umask 0022 (makes new files readable by group)

Secure your SSH key

chmod 600 ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Putting It All Together – A Mini Workflow

Let’s walk through a typical AI tinkering routine:

  1. Clone the repo
   git clone https://github.com/your-org/ai-project.git
   cd ai-project
Enter fullscreen mode Exit fullscreen mode
  1. Set up a virtual environment
   python3 -m venv .venv
   source .venv/bin/activate
   pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode
  1. Download the dataset (parallel, if large)
   aria2c -x 16 -s 16 https://example.com/dataset.zip
   unzip dataset.zip -d data/
Enter fullscreen mode Exit fullscreen mode
  1. Run training in a detached session
   screen -S train_job
   python train.py --epochs 10 > train.log 2>&1
   # Press Ctrl-A then D to detach
Enter fullscreen mode Exit fullscreen mode
  1. Monitor GPU usage (requires NVIDIA tools)
   watch -n 1 nvidia-smi
Enter fullscreen mode Exit fullscreen mode
  1. After training, check the results
   tail -n 20 train.log | grep "Accuracy"
Enter fullscreen mode Exit fullscreen mode
  1. Clean up old checkpoints
   find checkpoints/ -type f -mtime +30 -delete
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

Mastering these commands will let you:

  • Navigate your filesystem quickly and safely.
  • Manipulate files and directories without leaving the terminal.
  • Keep tabs on resource usage, preventing costly crashes.
  • Install software efficiently across distributions.
  • Run long‑running AI jobs that survive disconnections.
  • Filter logs and data with powerful text tools.

Don’t worry if you can’t remember every flag right away. The key is to practice—copy a command, run it, tweak the options, and see what happens. Over time, these commands will become second nature, letting you focus on what really matters: building awesome AI models in your home lab. Happy tinkering! 🚀

Top comments (0)