Day 12 : Linux and Git Commands

File and Directory Management

CommandDescription
lsLists files and directories in the current directory.
ls -lDisplays detailed file information in a long format.
ls -aLists all files, including hidden ones.
cd <directory>Changes the current directory to the specified one.
pwdDisplays 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

CommandDescription
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

CommandDescription
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 -lDisplays file permissions in long format.

Process Management

CommandDescription
psLists currently running processes.
ps auxDisplays detailed information about all running processes.
topDisplays real-time process information.
kill <PID>Terminates a process by its Process ID (PID).
kill -9 <PID>Forces termination of a process.
jobsLists background jobs.
fg <job>Brings a background job to the foreground.

User Management

CommandDescription
whoamiDisplays the current logged-in user.
whoShows 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

CommandDescription
df -hDisplays 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.
lsblkLists information about block devices (disks).
fdisk -lDisplays partition information for all disks.

Networking

CommandDescription
ifconfigDisplays or configures network interfaces.
ip addrShows IP address information for interfaces.
ping <host>Sends ICMP packets to check connectivity to a host.
netstat -tulnDisplays 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

CommandDescription
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.

System Information

CommandDescription
uname -aDisplays system information.
hostnameDisplays the hostname of the system.
uptimeShows how long the system has been running.
free -hDisplays memory usage in a human-readable format.
vmstatDisplays CPU and memory statistics.

Package Management (Debian/Ubuntu)

CommandDescription
apt updateUpdates the package list.
apt upgradeUpgrades 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

CommandDescription
git initInitializes a new Git repository in the current directory.
git clone <repo-url>Creates a copy of an existing repository from a remote URL.
git statusDisplays 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 logShows the commit history of the repository.
git log --onelineDisplays the commit history in a compact, one-line format.

Branching and Merging

CommandDescription
git branchLists 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

CommandDescription
git remote -vLists 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

CommandDescription
git restore <file>Discards unstaged changes in the specified file.
git restore --staged <file>Unstages a file without discarding changes.
git reset --hardResets 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

CommandDescription
git stashSaves uncommitted changes temporarily and cleans the working directory.
git stash listShows the list of saved stashes.
git stash applyRestores the most recent stash without removing it.
git stash popRestores and removes the most recent stash.
git stash dropDeletes the most recent stash.

Cherry-picking

CommandDescription
git cherry-pick <commit>Applies changes from a specific commit to the current branch.
git cherry-pick --abortAborts the cherry-pick process.
git cherry-pick --continueResumes cherry-picking after resolving conflicts.

Tagging

CommandDescription
git tagLists 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

CommandDescription
git diffShows 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

CommandDescription
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 -fRemoves untracked files from the working directory.
git archive <branch> --output=<file>Creates an archive (ZIP/TAR) of the specified branch.