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
- Navigation (
cd,ls,pwd)- File manipulation (
cp,mv,rm,touch,nano)- System info & monitoring (
top,htop,free,df,du,ps)- Networking (
ping,curl,wget,ssh)- Package management (
apt,yum,dnf,pacman,pip)- Process & job control (
nohup,screen,tmux)- Shell tricks (
grep,awk,sed,cut,sort,uniq)- 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-iwithrmto 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
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
Usearia2c -x 16 -s 16 urlfor 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
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:
Intmux, 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
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
Putting It All Together – A Mini Workflow
Let’s walk through a typical AI tinkering routine:
- Clone the repo
git clone https://github.com/your-org/ai-project.git
cd ai-project
- Set up a virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Download the dataset (parallel, if large)
aria2c -x 16 -s 16 https://example.com/dataset.zip
unzip dataset.zip -d data/
- 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
- Monitor GPU usage (requires NVIDIA tools)
watch -n 1 nvidia-smi
- After training, check the results
tail -n 20 train.log | grep "Accuracy"
- Clean up old checkpoints
find checkpoints/ -type f -mtime +30 -delete
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)