Giter VIP home page Giter VIP logo

linuxtips's Introduction

Linux Notes

This is a list of things I either think are neat, or things I'm always Googling.

Locale Settings:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Process Tree:

pstree -p

Create a .gitkeep file in all empty directories:

find . -type d -empty -print0 | xargs -0 -I{} touch {}/.gitkeep

Remove all files in /tmp older than 2 days

find /tmp -maxdepth 1 -type f -mtime +2 -exec rm -i "{}" \;

Shell Startup Files:

  • Linux/Bash/TTY:
    /etc/profile → first of ~/.bash_profile, ~/.bash_login, ~/.profile that exists

  • Linux/Bash/XTerm:
    /etc/bash.bashrc.bashrc

  • Linux/Bash/Scripts (#!/usr/bin/env bash):
    looks for $BASH_ENV var and sources the expansion of that variable

  • Linux/ZShell/TTY:
    /etc/zshenv~/.zshenv/etc/zprofile~/.zprofile/etc/zshrc~/.zshrc/etc/zlogin~/.zslogin (/etc/z* is the default; however /etc/zsh/z* seems to be common (at least on Ubuntu))

  • Linux/ZShell/XTerm:
    /etc/zshrc~/.zshrc

  • Linux/ZShell/Scripts (#!/usr/bin/env zsh):
    /etc/zshenv

  • OSX/Bash/TTY/XTerm:
    /etc/profile → first of ~/.bash_profile, ~/.bash_login, ~/.profile that exists

  • OSX/Bash/Scripts (/usr/bin/env bash):
    looks for $BASH_ENV var and sources the expansion of that variable

  • OSX/ZShell/TTY/XTerm:
    /etc/zshenv~/.zshenv/etc/zprofile~/.zprofile/etc/zshrc~/.zshrc/etc/zlogin~/.zslogin

  • OSX/ZShell/Scripts (/usr/bin/env zsh):
    /etc/zshenv

Setting your hostname—Debian and Ubuntu:

  1. Edit /etc/hostname and add you unqualified hostname, e.g., echo "parabola" > /etc/hostname

  2. Run hostname -F /etc/hostname to update your hostname

  3. Edit /etc/hosts:

    127.0.1.1 parabola.tylercipriani.com parabola localhost

Cronjob Time Syntax:

  • m h dom m dow <what_to_do>
    • m - minute(0–59)
    • h - hour(0–23)
    • dom - day-of-month(0–31)
    • m - month(0-11)
    • dow - day-of-week(0–6)
    • <what_to_do> - anycommand

Send mail

echo "Message Body" | mail -s "Mail Subject" [email protected]

Send mail to multiple people:

echo "Message Body" | mail -s "Mail Subject" -c "[email protected] [email protected]" [email protected]

Git show contents of stash

git stash show -p stash@{1}

IPTables

  • Block an IPAddress

    iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP
    
  • Insert a rule to allow inbound tcp traffic on port 8000 (puts the rule at the top)

    iptables -I INPUT -i eth0 -p tcp --dport 8000 -j ACCEPT
    

Tar (Tape Archive Utility)

  • Create gzipped tar from file or directory

    tar -cvzf tarfile.tar.gz directory file otherfile
    
  • Create bzipped tar file from file or directory

    tar -cvjf tarfile.tar.bz2 directory file otherfile
    
  • List contents of tar.gz file

    tar -tvzf tarfile.tar.gz
    

Wget/cURL

  • Rip a whole site with wget:

    wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains <domain-name> --no-parent http://<domain>
    
  • Upload file via cURL

    curl -X 'POST' -H 'Accept: application/json' -F 'file_name=Test File' -F 'file_contents=@/path/to/file.type' www.example.com/file/add
    
  • Fill login form via cURL

    curl -X 'POST' -F 'username=tyler' -F 'password=pass123' www.example.com/login
    

MySQL

  • Single DB Dump

    mysqldump --compress -h localhost --quick --single-transaction [db_name] > [dumpfile]
    
  • Nice DB Dump

    mysqldump -h localhost -u [username] -p --add-drop-database --skip-comments --routines --compress --quick --single-transaction --databases [db_name] > [dumpfile]
    
  • Dump tables that match pattern:

    mysqldump -h localhost --quick --single-transaction [db_name] `mysql -ND [db_name] -h localhost -e "show tables like '[pattern]'" | awk '{ printf $1" " }'` > dumpfile.sql
    

Debug bash scripts, add:

set -x

Forward new port in existing SSH session:

<newline>
~C
ssh> ?

List currently established, closed, orphaned and waiting TCP sockets:

ss -s

netstat -tlnp vs ss -ln

$ time netstat -tlnp                                                                                                   127 ↵
netstat -tlnp  0.00s user 0.02s system 97% cpu 0.016 total

$ time ss -ln       
ss -ln  0.00s user 0.00s system 83% cpu 0.005 total

Check disk I/O:

vmstat 1 10

What's using disk I/O:

dstat --top-io --top-bio

Show io per-device (needs sysstat package on debian):

iostat -sk 2

Linux Fun Crap

linuxtips's People

Contributors

thcipriani 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.