{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# System" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " /etc/default/grub" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "64\n" ] } ], "source": [ "getconf LONG_BIT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Endianness\n", "https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html \n", "In big endian, you store the most significant byte(MSB) in the smallest address. \n", "In little endian, you store the least significant byte(LSB) in the smallest address. " ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Byte Order: Little Endian\r\n" ] } ], "source": [ "lscpu | egrep 'Byte Order'" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/bin/ps: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.26, BuildID[sha1]=50e7d32ac155ae75537703a8df299bc72388978e, stripped\r\n" ] } ], "source": [ "file /bin/ps # LSB for Little Endian" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "netstat -antp" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "dd if=/dev/urandom of=50MB.bin bs=1M count=50" ] }, { "cell_type": "code", "execution_count": 166, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " -r, --reverse reverse order while sorting\r\n", " extension -X, size -S, time -t, version -v\r\n", " -t sort by modification time, newest first\r\n" ] } ], "source": [ "ls --help | grep -E '[-][tr]\\b'" ] }, { "cell_type": "code", "execution_count": 151, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[....] nginx is running\u001b[?25l\u001b7\u001b[1G[\u001b[32m ok \u001b[39;49m\u001b8\u001b[?12l\u001b[?25h.\r\n", "[....] nginx is running\u001b[?25l\u001b7\u001b[1G[\u001b[32m ok \u001b[39;49m\u001b8\u001b[?12l\u001b[?25h.\r\n" ] } ], "source": [ "service nginx status\n", "/etc/init.d/nginx status" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "update-rc.d: using dependency based boot sequencing\r\n", "update-rc.d: error: not enough arguments\r\n", "usage: update-rc.d [-n] [-f] remove\r\n", " update-rc.d [-n] defaults [NN | SS KK]\r\n", " update-rc.d [-n] start|stop NN runlvl [runlvl] [...] .\r\n", " update-rc.d [-n] disable|enable [S|2|3|4|5]\r\n", "\t\t-n: not really\r\n", "\t\t-f: force\r\n", "\r\n", "The disable|enable API is not stable and might change in the future.\r\n" ] } ], "source": [ "update-rc.d" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "echo 'CentOS'\n", "chkconfig nginx on\n", "chkconfig nginx" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\r\n", "mongodb 6934 0.3 1.4 107824 11084 ? Sl Aug09 46:43 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb.conf run\r\n", "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\r\n", "root 23154 0.0 6.9 224388 53196 ? Sl Aug10 10:15 /root/anaconda3/envs/py35/bin/python /root/anaconda3/envs/py35/bin/jupyter-notebook --certfile=.ssh/la1.tracert.win/cert1.pem --keyfile .ssh/la1.tracert.win/privkey1.pem --notebook-dir=/root/\r\n" ] } ], "source": [ "export count=2\n", "ps aux --sort=-pcpu | head -n $count\n", "ps aux --sort=-rss | head -n $count" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ssh root@10.2.3.6 'racadm serveraction powerup'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "find /home -iname tecmint.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Networking" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "export http_proxy=http://192.168.4.10:7778/\n", "export https_proxy=$http_proxy \n", "export no_proxy=\"localhost,127.0.0.1,192.168.*.*,10.*.*.*\"\n", "export ftp_proxy=$http_proxy\n", "export rsync_proxy=$http_proxy" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bash: In: command not found\r\n", "127\r\n" ] } ], "source": [ "echo 'ubuntu set apt-get proxy'\n", "cat /etc/apt/apt.conf\n", "#Acquire::http::Proxy \"http://Username:Password@proxy.foo.bar.edu.au:8080\";" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "http://askubuntu.com/questions/257263/how-to-display-network-traffic-in-terminal" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# detect proxy type\n", "nmap -sV -p5201 127.0.0.1" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bash: set: --: invalid option\r\n", "set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]\r\n" ] } ], "source": [ "set -h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## curl github\n", "https://github.com/settings/tokens" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "curl -H 'Authorization: token INSERT_ACCESS_TOKEN_HERE' \\\n", " -H 'Accept: application/vnd.github.v3.raw' -O -L \\\n", " https://api.github.com/repos/owner/repo/contents/path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Firewall " ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "xterm\r\n" ] } ], "source": [ "echo $TERM" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "tcp 0 0 0.0.0.0:10220 0.0.0.0:* LISTEN 3289/sshd \r\n", "tcp6 0 0 :::10220 :::* LISTEN 3289/sshd \r\n" ] } ], "source": [ "netstat -lntup | grep sshd" ] }, { "cell_type": "code", "execution_count": 93, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000\r\n", " link/ether 56:00:00:2d:da:d9 brd ff:ff:ff:ff:ff:ff\r\n", " inet 108.61.217.233/24 brd 255.255.255.0 scope global eth0\r\n", " inet6 fe80::5400:ff:fe2d:dad9/64 scope link \r\n", " valid_lft forever preferred_lft forever\r\n" ] } ], "source": [ "ip addr show dev eth0" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "default via 108.61.217.1 dev eth0 \r\n", "10.99.0.0/16 dev eth1 proto kernel scope link src 10.99.0.10 \r\n", "108.61.217.0/24 dev eth0 proto kernel scope link src 108.61.217.233 \r\n", "169.254.169.254 via 108.61.217.1 dev eth0 \r\n" ] } ], "source": [ "ip route" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "parted -s /dev/vdb mklabel gpt\n", "parted -s /dev/vdb unit mib mkpart primary 0% 100%\n", "\n", "mkfs.ext4 /dev/vdb1\n", "\n", "mkdir /mnt/data\n", "echo >> /etc/fstab\n", "echo /dev/vdb1 /mnt/data ext4 defaults,noatime 0 0 >> /etc/fstab\n", "mount /mnt/data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mount -o loop,ro CentOS-7-x86_64-Everything-1511.iso /mnt/CentOS\n", "\n", "mount.nfs nfs_server:/dir /dir\n", "mount -tnfs4 -ominorversion=1 server_nfs_4.1:/dir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Text file Operations\n", "http://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total 24\n", "drwxr-xr-x 12 root root 4096 Aug 10 10:02 anaconda3\n", "drwxr-xr-x 3 root root 4096 Aug 9 18:23 btsync\n", "drwxr-xr-x 2 root root 4096 Aug 9 13:45 certbot\n", "drwx------ 7 root root 4096 Aug 9 17:34 Dropbox\n", "-rw-r--r-- 1 root root 0 Aug 10 10:06 py35.yml\n", "drwxr-xr-x 3 root root 4096 Jul 22 04:47 serverspeeder\n", "drwxr-xr-x 2 root root 4096 Jul 22 05:19 ss-libev\n", "-rw-r--r-- 1 root root 0 Aug 10 06:24 testfile\n", "lrwxrwxrwx 1 root root 21 Jul 22 06:25 www -> /usr/share/nginx/www/\n", "Wed Aug 10 10:08:18 UTC 2016\n" ] } ], "source": [ "%%bash\n", "cd ~\n", "ls -l\n", "date\n", "cat py35.yml" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'nginx,sudo,btsync,bc,shadowsocks-libev,aria2,unifi_sysvinit_all,unifi,-f unifi,-f unifi,-f'" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h = !cat .bash_history \n", "','.join([s.split('install ')[1] for s in h if 'apt-get install' in s])" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " -y do not show flags, show rss (only with -l)\n" ] } ], "source": [ "%%bash\n", "ps --help all | grep rss" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mkdir -p /not/existing/folder" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "name: root \n", "dependencies:\n", "- _nb_ext_conf=0.2.0=py35_0\n", "- alabaster=0.7.8=py35_0\n", "http://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files\n" ] } ], "source": [ "cd ~\n", "cat py35.yml | head -n 4\n", "\n", "sed -i 's/(?<=name: )root/py352/' py35.yml\n", "cat py35.yml | head -n 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Scripts" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "one\n", "two\n", "three\n", "one two three\n", "one two three\n" ] } ], "source": [ "# http://tldp.org/LDP/abs/html/quotingvar.html\n", "List=\"one two three\"\n", "\n", "for a in $List # Splits the variable in parts at whitespace.\n", "do\n", " echo \"$a\"\n", "done\n", "\n", "for a in \"$List\" # Preserves whitespace in a single variable.\n", "do # ^ ^\n", " echo \"$a\"\n", " echo \"${a}\"\n", "done\n", "# one two three" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bash: [: too many arguments\n", "2\n" ] } ], "source": [ "a=\"zero zoo\"\n", "\n", "if [ $a == z* ] \n", "then\n", " echo '1'\n", "fi\n", "\n", "if [[ $a == z* ]]\n", "then\n", " echo '2'\n", "fi\n", "\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0=>1\r\n", "1=>2\r\n", "2=>3\r\n" ] } ], "source": [ "string=\"1:2:3\"\n", "set -f # avoid globbing (expansion of *).\n", "array=(${string//:/ })\n", "for i in \"${!array[@]}\"\n", "do\n", " echo \"$i=>${array[i]}\"\n", "done" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "echo 'ps grep excluding grep pid'\n", "RESULT_ssh_agent =`ps -aux | sed -n /[s]sh-agent/p`\n", "\n", "if [ \"${RESULT_ssh_agent:-null}\" = null ]; then\n", "\tchmod 600 /home/fzinfz/.ssh/id_rsa_vultr\n", "\teval $(ssh-agent -s)\n", "\tssh-add /home/fzinfz/.ssh/id_rsa_vultr\n", "else\n", " echo \"ssh-agent running,skip adding\"\n", "fi" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\r", "Reading package lists... 0%\r", "\r", "Reading package lists... 100%\r", "\r", "Reading package lists... Done\r", "\r\n", "\r", "Building dependency tree... 0%\r", "\r", "Building dependency tree... 0%\r", "\r", "Building dependency tree... 50%\r", "\r", "Building dependency tree... 50%\r", "\r", "Building dependency tree \r", "\r\n", "\r", "Reading state information... 0%\r", "\r", "Reading state information... 0%\r", "\r", "Reading state information... Done\r", "\r\n", "E: Unable to locate package git,aria2\r\n" ] } ], "source": [ "apt-get install git,aria2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "dpkg --get-selections | grep postgres" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Sync\n", "## Rsync" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "rsync -aP /root/_bin root@remote:/root\n", "rsync -aP -e \"ssh -p 10220\" /root/data/docker-config root@remote:/root --remove-source-files" ] }, { "cell_type": "code", "execution_count": 167, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " -v, --verbose increase verbosity\r\n", " -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\r\n", " --no-OPTION turn off an implied OPTION (e.g. --no-D)\r\n", " -r, --recursive recurse into directories\r\n", " -l, --links copy symlinks as symlinks\r\n", " -p, --perms preserve permissions\r\n", " -o, --owner preserve owner (super-user only)\r\n", " -g, --group preserve group\r\n", " -D same as --devices --specials\r\n", " -t, --times preserve modification times\r\n", " -S, --sparse handle sparse files efficiently\r\n", " -e, --rsh=COMMAND specify the remote shell to use\r\n", " --partial keep partially transferred files\r\n", " --partial-dir=DIR put a partially transferred file into DIR\r\n", " -z, --compress compress file data during the transfer\r\n", " --progress show progress during transfer\r\n", " -P same as --partial --progress\r\n" ] } ], "source": [ "rsync --help | grep -E '[-][ezaPrlptgoDv]\\b|partial|progress|sparse'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "tar -zcvf new.tar.gz directory-name\n", "\n", "tar -ztvf my-data.tar.gz\n", "tar -tvf my-data.tar.gz\n", "tar -tvf my-data.tar.gz '*.py'\n", "\n", "tar -zxvf toExtract.tar.gz\n", "\n", "gunzip file.gz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dropbox" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cd ~ && wget -O - \"https://www.dropbox.com/download?plat=lnx.x86_64\" | tar xzf -" ] }, { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Killed\r\n" ] } ], "source": [ "~/.dropbox-dist/dropboxd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "deploying Let's Encrypt certificates: https://certbot.eff.org/" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "./certbot-auto certonly --webroot -w /usr/share/nginx/www/ -d example.com -d www.example.com\n", "/etc/letsencrypt/live/example.com/ -> /etc/letsencrypt/archive/example.com/ \n", "cert.pem chain.pem fullchain.pem privkey.pem -> cert1.pem chain1.pem fullchain1.pem privkey1.pem" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "apt-get install qemu-system\n", "\n", "qemu-system-aarch64 qemu-system-m68k qemu-system-mipsel qemu-system-s390x qemu-system-unicore32\n", "qemu-system-alpha qemu-system-microblaze qemu-system-moxie qemu-system-sh4 qemu-system-x86_64\n", "qemu-system-arm qemu-system-microblazeel qemu-system-or32 qemu-system-sh4eb qemu-system-x86_64-spice\n", "qemu-system-cris qemu-system-mips qemu-system-ppc qemu-system-sparc qemu-system-xtensa\n", "qemu-system-i386 qemu-system-mips64 qemu-system-ppc64 qemu-system-sparc64 qemu-system-xtensaeb\n", "qemu-system-lm32 qemu-system-mips64el qemu-system-ppcemb qemu-system-tricore " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Bash", "language": "bash", "name": "bash" }, "language_info": { "codemirror_mode": "shell", "file_extension": ".sh", "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 1 }