Skip to content

Instantly share code, notes, and snippets.

@harrietty
Last active November 2, 2018 16:42
Show Gist options
  • Save harrietty/d05854ef6c467cc4c848e7d49b3920f2 to your computer and use it in GitHub Desktop.
Save harrietty/d05854ef6c467cc4c848e7d49b3920f2 to your computer and use it in GitHub Desktop.
Useful Bash commands

Useful Bash Commands

Network

netstat | grep ssh (mac)

netstat -vanp --tcp | grep 8080 (CentOS)

kill -9 <PID>

Git

git blame foo.js

git blame -L 40,60 foo.js (lines between)

NPM

npm list > /dev/null list modules, redirect stderr to black hole

npm list --depth=0 --prod Top level modules only

Bash

time node index.js time a process

rm outfile*.txt Remove files matching patterns

rm sequence_1_{2000..2999}.txt Remove files with numbers in a sequence

cat events.json | sed -e 's/}\,/}/g' > eventsNoCommas.json Substitute pattern using sed

cat events.json | sed -e 's/}\,/}/g' -e 's/foo/bar/' > eventsNoCommas.json Substitute 2 patterns in same script

csplit --prefix=event eventsNoCommas.json '/{/' '{*}' Split file into new files with the prefix 'event', using a pattern (first arg = matches the line from which the selection will be matched)

AWS

aws ec2 start-instances --instance-ids i-07a8794a416aaef84

aws ec2 describe-instance-status --instance-ids i-07a8794a416aaef84

Keyboard

Command Desc
^ a Move to start of line
^ e Move to end of line
^ r Command back search

Docker

Basic
Command Desc
docker container ls list running containers
docker ps list running containers
docker container ls -a list all containers
docker image ls list all images
docker rm <contaner_name/id> remove a stopped container
docker rm --force <contaner_name/id> dorce stop and remove a running container
Building images
Command Desc
docker build -t <image_name> . create an image from a Dockerfile in cwd
Running containers
Command Desc
docker run <image_name> run an image
docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run an image
docker run -d training/webapp python app.py Run an image and use python command to run the app
docker run --name <desired_container_name> <image_name> run an image and name the container
docker run -d <image_name> run an image in detached mode
docker run -p 4000:80 <image_name> map your local 4000 port to port 80
docker start <container_name> start a container
docker stop <container_name/id> stop a container
docker exec -it <contaienr_name> run a command in a started container
docker exec -it puppet bash attach tty terminal to a running puppet container
docker run -it --link some-redis:redis --rm redis redis-cli -h redis -p 6379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment