Skip to content

Instantly share code, notes, and snippets.

@ikidnapmyself
Last active August 18, 2022 13:26
Show Gist options
  • Save ikidnapmyself/d7f62b93433cb76f8ad9f6bef80394c1 to your computer and use it in GitHub Desktop.
Save ikidnapmyself/d7f62b93433cb76f8ad9f6bef80394c1 to your computer and use it in GitHub Desktop.
Useful Terminal Commands I Like

Stop all service containers

docker stop $(docker ps -a -q)

Removes stopped service containers

docker rm $(docker ps -a -q)

The docker system prune command removes all stopped containers, dangling images, and unused networks:

docker system prune

This command will prompt you to confirm the operation:

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N]

Use the -f or --force option to bypass the prompt.

By default, the command doesn’t remove unused volumes to prevent losing important data. To remove all unused volumes, pass the --volumes option:

docker system prune --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

"This project" containers

docker-compose ps

Restart "elasticsearch" container

docker-compose restart elasticsearch

Reset local repository branch to be just like remote repository HEAD

Fetch origin

git fetch origin

And then reset repository

git reset --hard origin/master

If you want to save your current branch's state before doing this (just in case), you can do: Commit first

git commit -a -m "Saving my work, just in case"

And create a branch

git branch my-saved-work

How can I determine the URL that a local Git repository was originally cloned from?

git remote show origin

Pull submodules

git submodule update --init

Show difference

git diff

Get missing submodules

git submodule update --init --recursive

### Generate a new SSH key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

ll command allias

alias ll='ls -lG'

Install Python 3

brew install python3

Can't chown /usr/local for homebrew in Mac OS

First remove Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Then re-install

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Flush DNS Cache

sudo killall -HUP mDNSResponder

Home Brew

To tap home brew packages: https://formulae.brew.sh/

Install Package
brew install *<package_name>*
Trouble Shooting
brew update
brew doctor
Restart Local Nginx
sudo nginx -s reload

Export chosen tables into a file

<database_name> your database name <table_name_1> optionally your table name <table_name_2> optionally add some other tables too <table_name_2> file name

mysqldump -u <user> -p <database_name> [<table_name_1>[, ... <table_name_2>]]  > <file_name>

Table 'performance_schema.session_variables' doesn't exist

https://stackoverflow.com/questions/31967527/table-performance-schema-session-variables-doesnt-exist

Upgrade

mysql_upgrade -u root -p --force

Restart mysql

sudo service mysql restart

Initialize virtualenv

python3 -m venv /path/to/new/virtual/environment

Activate virtualenv

source venv/bin/activate

Deactivate virtualenv

deactivate

Create requirements.txt

pip freeze > requirements.txt

Install requirements

pip install -r requirements.txt

### Generate a new SSH key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Number of file and directories in a subdirectory

find . -type f -print | wc -l

Mount a drive

sudo mount /dev/DRIVE_NAME /path/to/local/target

Flush DNS Cache

/etc/init.d/named restart
/etc/init.d/nscd restart

Port Testing

telnet google.com 8080

List MySQL configuration files

/usr/local/bin/mysql --verbose --help | grep -A 1 "Default options"

Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

List Active Ports

sudo netstat -lntp

All the files exceeding certain size

find . -size +500k

Delete ll the files exceeding certain size

find . -size +500k -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment