Git Product home page Git Product logo

useful_commands's Introduction

Useful Commands

This is a collection of useful commands I have found over time.

Docker

Update containers using docker-compose

# Update your tags inside docker-compose file
# This method will ensure that everything with the new images is okay
# and then update the actual running containers. (avoid downtime)
# `start` and `restart` will NOT work
> docker-compose build
> docker-compose up -d

Find the ip address of a container

> docker inspect container_name | grep '"IPAddress"'

Use the same docker network for all the containers inside a docker-compose file

# This will be extremely helpful for using docker-compose in a modular manner.
# Multiple compose files can be used instead of one, without any extra modification, while allowing
# containers of different files to directly communicate with each other.

# Firstly, create the docker network "yourNetworkName"

> docker network create yourNetworkName

# Secondly, add the following lines to your docker-compose.yml and you're good to go.
networks:
  default:
    external:
      name: yourNetworkName

Stop all the active containers at once

> docker stop $(docker ps -q)

Login inside a docker container with admin rights, and an interactive terminal

> docker exec -u 0 -it container_name /bin/bash

Alternatively, you can use sh inside the container

> docker exec -u 0 -it container_name /bin/sh

Networking

Get web port usage of every service using it

> sudo lsof -itcp

COMMAND     PID     USER    FD  TYPE    DEVICE      SIZE/OFF    NODE    NAME
docker-pr   20887   root    4u  IPv6    225535203   0t0         TCP     *:1883 (LISTEN)

Generate strong ssh key for server setup

>  ssh-keygen -t rsa -b 4096

Files

Show files size in a directory and sort by size

> du -csh * | sort -rh

# du: Disk Usage
# -s: Summary for each file
# -h: Human readable format
# -c: Produce grand total

> du -csh * | sort -rh | head -n10

# head -n10: Reduces the output to only 10 rows for readability

Convert windows line endings to unix

dos2unix file.txt

Change ownership of all files on current directory to current user

> chown -R $USER:$USER .

# -R:		Do it recursively.
# .:		Do it for everything inside the current directory.
# $USER:	The user currently logged in.

PDF

Create 'PDF' by merging images, text files and pdfs

# sudo apt install imagemagick

> convert image1.jpg image2.png text.txt PDFfile.pdf outputFileName.pdf

Compress PDF files using ghostscript

> gs    -sDEVICE=pdfwrite           \
        -dCompatibilityLevel=1.4    \
        -dPDFSETTINGS=/ebook        \
        -dNOPAUSE                   \
        -dQUIET                     \
        -dBATCH                     \
        -sOutputFile=output.pdf     \
        input.pdf

# Additional options: http://milan.kupcevic.net/ghostscript-ps-pdf/

Do anything PDF related using a nice GUI. (not a command but hey)

> pdfsam

General

Run something from a terminal and detach it from it.

> thingToRun &
> disown

# All you have to do is type & after whatever you want to run.
# After the command runs, your terminal will seem detached, but if you exit, your application will be killed.
# So you just type disown, and profit! you can exit your terminal.

Count number of lines and words inside a file or console output.

input | wc -lw

# -l: Count number of lines
# -w: Count number of words

Friends

useful_commands's People

Contributors

stavrosfil avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.