File and Directory Management
Command | Description |
ls | Lists files and directories in the current directory. |
ls -l | Displays detailed file information in a long format. |
ls -a | Lists all files, including hidden ones. |
cd <directory> | Changes the current directory to the specified one. |
pwd | Displays the current working directory. |
mkdir <directory> | Creates a new directory. |
rmdir <directory> | Deletes an empty directory. |
rm <file> | Deletes a file. |
rm -r <directory> | Deletes a directory and its contents recursively. |
cp <source> <destination> | Copies files or directories. |
mv <source> <destination> | Moves or renames files or directories. |
find <directory> -name <name> | Searches for files or directories by name. |
File Viewing and Editing
Command | Description |
cat <file> | Displays the contents of a file. |
less <file> | Opens a file for viewing one screen at a time. |
head <file> | Displays the first 10 lines of a file. |
tail <file> | Displays the last 10 lines of a file. |
nano <file> | Opens the file in the Nano text editor. |
vi <file> | Opens the file in the Vi editor. |
echo "text" > <file> | Writes text to a file (overwrites if the file exists). |
echo "text" >> <file> | Appends text to a file. |
File Permissions and Ownership
Command | Description |
chmod <permissions> <file> | Changes the permissions of a file or directory. |
chown <user>:<group> <file> | Changes the owner and group of a file or directory. |
ls -l | Displays file permissions in long format. |
Process Management
Command | Description |
ps | Lists currently running processes. |
ps aux | Displays detailed information about all running processes. |
top | Displays real-time process information. |
kill <PID> | Terminates a process by its Process ID (PID). |
kill -9 <PID> | Forces termination of a process. |
jobs | Lists background jobs. |
fg <job> | Brings a background job to the foreground. |
User Management
Command | Description |
whoami | Displays the current logged-in user. |
who | Shows all logged-in users. |
adduser <username> | Adds a new user to the system. |
passwd <username> | Changes the password for a user. |
deluser <username> | Removes a user account. |
Disk and File System Management
Command | Description |
df -h | Displays disk space usage in a human-readable format. |
du -h <directory> | Shows the size of a directory and its contents. |
mount <device> <directory> | Mounts a filesystem. |
umount <directory> | Unmounts a filesystem. |
lsblk | Lists information about block devices (disks). |
fdisk -l | Displays partition information for all disks. |
Networking
Command | Description |
ifconfig | Displays or configures network interfaces. |
ip addr | Shows IP address information for interfaces. |
ping <host> | Sends ICMP packets to check connectivity to a host. |
netstat -tuln | Displays active network connections and listening ports. |
curl <URL> | Fetches data from a URL. |
wget <URL> | Downloads files from a URL. |
traceroute <host> | Shows the route packets take to reach a host. |
Archiving and Compression
Command | Description |
tar -cvf <archive.tar> <files> | Creates a tar archive. |
tar -xvf <archive.tar> | Extracts files from a tar archive. |
gzip <file> | Compresses a file using Gzip. |
gunzip <file.gz> | Decompresses a Gzip file. |
zip < archive.zip > <files> | Creates a ZIP archive. |
unzip < archive.zip > | Extracts files from a ZIP archive. |
Command | Description |
uname -a | Displays system information. |
hostname | Displays the hostname of the system. |
uptime | Shows how long the system has been running. |
free -h | Displays memory usage in a human-readable format. |
vmstat | Displays CPU and memory statistics. |
Package Management (Debian/Ubuntu)
Command | Description |
apt update | Updates the package list. |
apt upgrade | Upgrades installed packages. |
apt install <package> | Installs a specific package. |
apt remove <package> | Removes a specific package. |
For CentOS (a Red Hat-based Linux distribution), package management is typically handled using yum
or dnf
, depending on the version of CentOS
Basic Git Commands
Command | Description |
git init | Initializes a new Git repository in the current directory. |
git clone <repo-url> | Creates a copy of an existing repository from a remote URL. |
git status | Displays the status of your working directory and staging area. |
git add <file> | Adds changes in the specified file(s) to the staging area. |
git add . | Stages all changes (new, modified, deleted files) in the current directory. |
git commit -m "message" | Commits the staged changes with a descriptive commit message. |
git log | Shows the commit history of the repository. |
git log --oneline | Displays the commit history in a compact, one-line format. |
Branching and Merging
Command | Description |
git branch | Lists all branches in the repository. |
git branch <branch-name> | Creates a new branch with the specified name. |
git checkout <branch-name> | Switches to the specified branch. |
git checkout -b <branch-name> | Creates and switches to a new branch in one command. |
git merge <branch-name> | Merges the specified branch into the current branch. |
git branch -d <branch-name> | Deletes the specified branch (only if it’s fully merged). |
git branch -D <branch-name> | Force-deletes the specified branch. |
Remote Repositories
Command | Description |
git remote -v | Lists remote repositories associated with the local repo. |
git remote add <name> <url> | Adds a new remote repository. |
git push <remote> <branch> | Pushes changes from the local branch to the remote branch. |
git fetch <remote> | Retrieves updates from the remote without merging them. |
git pull <remote> <branch> | Fetches and merges updates from the remote branch into the current branch. |
Undoing Changes
Command | Description |
git restore <file> | Discards unstaged changes in the specified file. |
git restore --staged <file> | Unstages a file without discarding changes. |
git reset --hard | Resets the working directory to the last commit, discarding all changes. |
git reset <commit> | Moves the HEAD to the specified commit without affecting the working directory. |
git revert <commit> | Creates a new commit that reverses the changes of a specific commit. |
Stashing Changes
Command | Description |
git stash | Saves uncommitted changes temporarily and cleans the working directory. |
git stash list | Shows the list of saved stashes. |
git stash apply | Restores the most recent stash without removing it. |
git stash pop | Restores and removes the most recent stash. |
git stash drop | Deletes the most recent stash. |
Cherry-picking
Command | Description |
git cherry-pick <commit> | Applies changes from a specific commit to the current branch. |
git cherry-pick --abort | Aborts the cherry-pick process. |
git cherry-pick --continue | Resumes cherry-picking after resolving conflicts. |
Tagging
Command | Description |
git tag | Lists all tags in the repository. |
git tag <tag-name> | Creates a lightweight tag with the specified name. |
git tag -a <tag-name> -m "message" | Creates an annotated tag with a message. |
git push <remote> <tag-name> | Pushes a specific tag to the remote repository. |
Inspection and Debugging
Command | Description |
git diff | Shows differences between the working directory and the staging area. |
git diff <branch1> <branch2> | Shows differences between two branches. |
git blame <file> | Displays the commit history for each line of a file. |
git show <commit> | Displays detailed information about a specific commit. |
Miscellaneous
Command | Description |
git config --global user.name "Name" | Sets the global username for Git commits. |
git config --global user.email "Email" | Sets the global email for Git commits. |
git clean -f | Removes untracked files from the working directory. |
git archive <branch> --output=<file> | Creates an archive (ZIP/TAR) of the specified branch. |