The Linux command line is a text - based interface where users can enter commands to interact with the operating system. In the context of development, it serves as a control center for various tasks.
ls
is a simple command to list files and directories in the current location.|
) allow you to connect the output of one command to the input of another. Redirection operators (>
, <
, >>
) are used to send the output of a command to a file or take input from a file.cd
(Change Directory): This command is used to move between directories.# Move to the home directory
cd ~
# Move to a specific directory
cd /var/www/html
ls
(List): Lists files and directories in the current location.# List all files and directories including hidden ones
ls -a
nano
: A simple text editor that is easy to use for quick edits.# Create or edit a file named example.txt
nano example.txt
vim
: A more powerful and feature - rich text editor.# Open a file named script.py in vim
vim script.py
ps
: To view running processes.# List all running processes
ps -ef
kill
: To terminate a process.# Kill a process with a specific PID (Process ID)
kill -9 1234
Scripts are a sequence of commands saved in a file that can be executed together. For example, a simple shell script to create a new directory and a file inside it:
#!/bin/bash
# Create a new directory
mkdir new_project
# Move into the new directory
cd new_project
# Create a new file
touch main.py
Save the above code in a file named create_project.sh
, then make it executable:
chmod +x create_project.sh
And run it:
./create_project.sh
grep
: Searches for a pattern in a file or the output of a command.# Search for the word "error" in a file named log.txt
grep "error" log.txt
find
: Searches for files and directories in a directory hierarchy.# Find all .py files in the current directory and its subdirectories
find . -name "*.py"
apt
(Debian - based systems): Used to install, update, and remove software packages.# Update the package list
sudo apt update
# Install a package (e.g., python3)
sudo apt install python3
git
: A popular version control system.# Initialize a new git repository
git init
# Add all files to the staging area
git add.
# Commit changes
git commit -m "Initial commit"
Ctrl + A
: Move the cursor to the beginning of the line.Ctrl + E
: Move the cursor to the end of the line.Ctrl + R
: Reverse search through the command history..bashrc
or .zshrc
: These are configuration files for the Bash and Zsh shells respectively. You can add custom aliases and functions to speed up your workflow. For example, to create an alias for a long command:# Add this line to .bashrc or .zshrc
alias gs="git status"
After adding the alias, you can simply type gs
instead of git status
.
The Linux command line is a powerful tool that can significantly speed up your development workflow. By understanding the fundamental concepts, using the right commands, and following common and best practices, you can automate tasks, quickly navigate through files, and manage processes efficiently. With practice, you’ll find that the Linux command line becomes an indispensable part of your development toolkit.