Skip to content

Basic Linux Commands for Development

As a developer, understanding essential Linux commands is crucial. Whether you're managing files, setting up Python environments, or working with directories, these commands will help you get started.


📁 File and Directory Management

List Files and Directories

List files in the current directory:

ls
Common options: - ls -l : Long format listing - ls -a : Show hidden files

Create and Remove Directories

Create a new directory:

mkdir directory_name
Remove an empty directory:
rmdir directory_name
Remove a non-empty directory:
rm -r directory_name

Change directory:

cd directory_name
Go up one level:
cd ..
Show current directory:
pwd

Copy, Move, and Delete Files

Copy a file:

cp source destination
Copy a directory:
cp -r source_dir destination_dir
Move or rename a file or directory:
mv source destination
Delete a file:
rm file_name


🐍 Python and Pip Basics

Check Python Version

python3 --version

Install pip (Python Package Manager)

Debian/Ubuntu:

sudo apt install python3-pip
RedHat/CentOS:
sudo yum install python3-pip

Manage Python Packages

Install a package:

pip install package_name
List installed packages:
pip list
Uninstall a package:
pip uninstall package_name


🏗️ Virtual Environments

Virtual environments isolate your project's dependencies from the global Python environment. This helps avoid conflicts and makes collaboration easier.

Using venv (Python 3.3+)

Create a virtual environment:

python3 -m venv env
Activate it:
source env/bin/activate
Install dependencies:
pip install package_name
Deactivate when done:
deactivate

Using virtualenv (Alternative)

Install virtualenv:

pip install virtualenv
Create a virtual environment:
virtualenv env_name
Activate:
source env_name/bin/activate
Deactivate:
deactivate

Tip: Use a requirements.txt file to share dependencies:

pip freeze > requirements.txt
pip install -r requirements.txt

More on Python virtual environments


🔒 File Permissions and Ownership

Change File Permissions

Make a file executable:

chmod +x script.sh
Set specific permissions:
chmod 644 file.txt

Change File Ownership

Change owner and group:

sudo chown user:group file_name


📦 Package Management (Debian/Ubuntu)

Update package lists:

sudo apt update
Upgrade installed packages:
sudo apt upgrade
Install a package:
sudo apt install package_name
Remove a package:
sudo apt remove package_name

More on apt package management


✅ Wrapping Up

These commands are foundational for Linux-based development environments. Whether you're organizing files, managing Python projects, or working with packages, mastering these commands will make your workflow more efficient.

Practice them, and you'll become more comfortable with Linux in no time!