Linux Commands----------------------
ls
: Lists files and directories in the current location.- Example:
ls -l
(lists files and directories in long format)
- Example:
cd
: Changes the current directory.- Example:
cd /path/to/directory
(changes to the specified directory)
- Example:
pwd
: Prints the current working directory.- Example:
pwd
(displays the current working directory)
- Example:
mkdir
: Creates a new directory.- Example:
mkdir new_directory
(creates a directory named "new_directory")
- Example:
rm
: Removes files and directories.- Example:
rm file.txt
(removes the file.txt file)
- Example:
cp
: Copies files and directories.- Example:
cp file.txt new_location/
(copies file.txt to new_location/)
- Example:
mv
: Moves or renames files and directories.- Example:
mv file.txt new_name.txt
(renames file.txt to new_name.txt)
- Example:
cat
: Concatenates and displays file content.- Example:
cat file.txt
(displays the content of file.txt)
- Example:
grep
: Searches for a specific pattern in files.- Example:
grep "hello" file.txt
(searches for "hello" in file.txt)
- Example:
chmod
: Changes permissions of files and directories.sudo
: Executes a command with superuser/root privileges.- Example:
sudo apt-get update
(updates packages with root privileges)
- Example:
top
: Displays system resource usage and running processes.- Example:
top
(displays system resource usage)
- Example:
wget
: Downloads files from the web.- Example:
wget
https://example.com/file.txt
(downloads file.txt from the given URL)
- Example:
find
: Searches for files and directories.- Example:
find . -name "*.txt"
(finds all .txt files in the current directory and subdirectories)
- Example:
head
: Displays the beginning of a file.- Example:
head -n 10 file.txt
(displays the first 10 lines of file.txt)
- Example:
tail
: Displays the end of a file.- Example:
tail -n 5 file.txt
(displays the last 5 lines of file.txt)
- Example:
tar
: Archives and extracts files.- Example:
tar -czvf archive.tar.gz files/
(creates a compressed tar archive of files/)
- Example:
ssh
: Connects to a remote machine using SSH protocol.- Example:
ssh user@hostname
(establishes an SSH connection to the specified hostname)
- Example:
scp
: Copies files between local and remote machines over SSH.- Example:
scp file.txt user@remote:/path/to/destination
(copies file.txt to the remote machine)
- Example:
df
: Displays disk space usage.- Example:
df -h
(displays disk space usage in human-readable format)
- Example:
du
: Shows disk usage of files and directories.- Example:
du -sh directory/
(displays the total disk usage of the directory)
- Example:
man
: Displays the manual pages for a command.- Example:
man ls
(displays the manual page for the "ls" command)
- Example:
chown
: Changes file ownership.- Example:
chown user:group file.txt
(changes the owner and group.
- Example:
Git and GitHub Commands---------------
git init
: Initializes a new Git repository.- Example:
git init
(creates a new Git repository in the current directory)
- Example:
git clone
: Clones a remote repository to your local machine.- Example:
git clone
https://github.com/arnavs1999/repo.git
(clones the repository to your local machine)
- Example:
git add
: Adds files or changes to the staging area.- Example:
git add file.txt
(adds file.txt to the staging area)
- Example:
git commit
: Commits the changes in the staging area.- Example:
git commit -m "Added new feature"
(commits the changes with a commit message)
- Example:
git status
: Shows the status of your working directory.- Example:
git status
(displays the status of the repository)
- Example:
git push
: Pushes local changes to a remote repository.- Example:
git push origin master
(pushes changes to the master branch of the remote repository)
- Example:
git pull
: Fetches and merges change from a remote repository.- Example:
git pull origin master
(fetches and merges changes from the remote master branch)
- Example:
git branch
: Lists, creates, or deletes branches.- Example:
git branch
(lists all branches in the repository)
- Example:
git checkout
: Switches between branches or restores file versions.- Example:
git checkout new-feature
(switches to the "new-feature" branch)
- Example:
git merge
: Merges changes from one branch into another.- Example:
git merge feature-branch
(merges the changes from "feature-branch" into the current branch)
- Example:
git log
: Shows the commit history.- Example:
git log
(displays the commit history of the repository)
- Example:
git diff
: Shows the differences between commits, branches, etc.- Example:
git diff HEAD~1 HEAD
(displays the differences between the previous and current commit)
- Example:
git remote
: Manages remote repositories.- Example:
git remote add origin
https://github.com/user/repo.git
(adds a remote repository)
- Example:
git fetch
: Retrieves the latest changes from a remote repository.- Example:
git fetch origin
(fetches the latest changes from the remote repository)
- Example:
git revert
: Reverts a commit by creating a new commit with the opposite changes.git config
: Sets or retrieves Git configuration options.- Example:
git config --global
user.name
"John Doe"
(sets the global username to "John Doe")
- Example:
git log
: Shows the commit history.- Example:
git log --oneline
(displays the commit history in a concise format)
- Example:
git stash
: Stashes changes in a temporary area.- Example:
git stash save "Work in progress"
(saves the current changes in a stash)
- Example:
git reset
: Resets the current branch to a specific commit.- Example:
git reset HEAD~1
(resets the branch to the previous commit)
- Example:
git rebase
: Applies changes from one branch to another.- Example:
git rebase main
(applies the changes from the current branch to the "main" branch)
- Example:
git tag
: Manages tags (releases, versions, etc.).- Example:
git tag v1.0.0
(creates a tag for version 1.0.0)
- Example:
git cherry-pick
: Applies a specific commit to the current branch.- Example:
git cherry-pick abc123
(applies the commit with hash "abc123" to the current branch)
- Example:
git remote
: Manages remote repositories.- Example:
git remote -v
(displays the remote repositories and their URLs)
- Example:
git show
: Displays information about a specific commit.- Example:
git show abc123
(displays details about the commit with hash "abc123")
- Example:
git revert
: Reverts a commit by creating a new commit with the opposite changes.- Example:
git revert abc123
(creates a new commit that undoes the changes made in commit "abc123")
- Example:
git bisect
: Helps find the commit that introduced a bug using binary search.- Example:
git bisect start
followed bygit bisect bad
andgit bisect good
(starts the bisect process)
- Example:
git reflog
: Shows a log of all reference changes in the repository.- Example:
git reflog
(displays a log of all reference changes)
- Example:
git blame
: Shows who changed which lines in a file.- Example:
git blame file.txt
(displays line-by-line authorship information for file.txt)
- Example:
git archive
: Creates a tar or zip archive of a repository.- Example:
git archive --format=zip --output=repo.zip master
(creates a zip archive of the repository's master branch)
- Example:
git submodule
: Manages Git submodules within a repository.- Example:
git submodule add
https://github.com/user/repo.git
(adds a submodule to the repository)
- Example:
git clean
: Removes untracked files and directories from the working directory.- Example:
git clean -f
(removes untracked files forcefully)
- Example:
git show-branch
: Shows the branch structure and their commits.- Example:
git show-branch --all
(displays the branch structure and commits)
- Example:
GitHub Commands--------------------
git pull-request
: Creates a pull request on GitHub.git fork
: Creates a personal copy of a repository on GitHub.git remote add
: Adds a remote repository.hub clone
: Clones a repository from GitHub.hub create
: Creates a new repository on GitHub.hub fork
: Creates a fork of a repository on GitHub.hub browse
: Opens a GitHub repository or commits in a browser.hub compare
: Opens a GitHub compare page in a browser.hub release
: Creates a GitHub release.hub issue
: Manages GitHub issues.hub pull-request
: Manages GitHub pull requests.
-----------------------------------
Thank you for reading. I hope you were able to understand and learn something new from my blog.
Happy Learning!
Please follow me on Hashnode and do connect with me on LinkedIn ArnavSingh.