Cheat sheet with commands for Windows, Linux and macOS (Terminal, VirtualEnv and Git)
You often have to switch between different operating systems while working. In order not to remember a lot of commands, I use a cheat sheet with basic commands, which I decided to share with you.
In it you will find basic commands for working in the terminal of Windows, Linux and macOS. Basic commands for working with Systemctl, VirtualEnv and Git are also described.
Basic Commands
Deleting a folder
Windows:
rmdir /s /q папка_для_удаления
Linux and macOS:
rm -rf папка_для_удаления
Creating a folder
Windows:
mkdir новая_папка
Linux and macOS:
mkdir новая_папка
Creating a virtual python environment via venv
Windows:
python -m venv venv
Linux and macOS:
python3 -m venv venv
Python virtual environment via venv
venv on Windows comes out of the box. To install on Linux and macOS, you may need to enter the following commands:
sudo apt install -y python3-venv
sudo apt install -y build-essential libssl-dev libffi-dev python3-dev
Activation on Windows:
venv\Scripts\activate
Activation on Linux and macOS:
source venv/bin/activate
Deactivation (Linux, macOS and Windows):
deactivate
Git Commands
Initiating a Git repository
git init
Linking a remote repository
git remote add origin ссылка_на_репозиторий
Unlinking the repository
git remote rm origin ссылка_на_репозиторий
Linking another repository
git remote set-url origin git@github.com:username/projectname.git
Setting the default branch
git config --global init.defaultBranch main
Cloning a repository
git clone ссылка_на_репозиторий
View repository status
git status
Adding files to the index
git add имя_файла_или_папки
Commit changes
git commit -m "сообщение коммита"
Updating the local repository (pull)
git pull origin main
Sending changes to a remote repository (push)
git push origin main
Create a new branch and switch to it
git checkout -b новая_ветка
View a list of branches
git branch
Switch to an existing branch
git checkout имя_ветки
Merging branches
git merge имя_ветки
Creating a GitHub repository via the command line
To do this you need to use the GitHub CLI. First install it and then run the following commands:
Installing GitHub CLI
Windows (via winget):
winget install --id GitHub.cli
macOS (via Homebrew):
brew install gh
Linux (via package manager):
Example for Ubuntu:
sudo apt install gh
Authorization in GitHub CLI
gh auth login
Creating a repository
Public repository:
gh repo create имя_репозитория --public
Private repository:
gh repo create имя_репозитория --private
Other Useful Shell Commands
View the contents of the current directory
Windows:
dir
Linux and macOS:
ls
Switching directory
cd путь_к_папке
Copying files
Windows:
copy исходный_файл целевой_файл
Linux and macOS:
cp исходный_файл целевой_файл
Moving files
Windows:
move исходный_файл целевой_файл
Linux and macOS:
mv исходный_файл целевой_файл
Outputting file contents
Windows:
type имя_файла
Linux and macOS:
cat имя_файла
Creating and editing files
Windows:
echo текст > имя_файла
notepad имя_файла
Linux and macOS:
echo "текст" > имя_файла
nano имя_файла
Terminal command block for Ubuntu (I use it most often)
Software update and installation
Updating the package list
sudo apt update
This command updates the list of available packages and their versions, but does not install or update any packages.
Updating installed packages
sudo apt upgrade
This command updates all installed packages to the newest versions that are available in the repositories.
Installing packages
sudo apt install <имя_пакета>
This command installs the specified package. For example, to install the Firefox browser, run:
sudo apt install firefox
Removing packages
sudo apt remove <имя_пакета>
This command removes the specified package but retains its configuration files.
Complete removal of packages
sudo apt purge <имя_пакета>
This command removes the specified package along with its configuration files.
Cleaning up unnecessary packages
sudo apt autoremove
This command removes unnecessary packages that were installed as dependencies and are no longer required.
System Services Management
Starting the service
sudo systemctl start <имя_службы>
This command starts the specified service. For example:
sudo systemctl start apache2
Stopping a service
sudo systemctl stop <имя_службы>
Restarting the service
sudo systemctl restart <имя_службы>
Checking service status
sudo systemctl status <имя_службы>
Enable the service at boot
sudo systemctl enable <имя_службы>
Disabling a service at boot
sudo systemctl disable <имя_службы>
Don't forget to bookmark this cheat sheet and like it if you found it useful.