2015-03-01 01:30:36 +08:00
|
|
|
{
|
|
|
|
"metadata": {
|
|
|
|
"name": "",
|
2015-03-13 19:59:28 +08:00
|
|
|
"signature": "sha256:7cdf1e36fef9e69cd9007eb0c5945e4d6440b31108bfddd6f19aa71d0d1a06ab"
|
2015-03-01 01:30:36 +08:00
|
|
|
},
|
|
|
|
"nbformat": 3,
|
|
|
|
"nbformat_minor": 0,
|
|
|
|
"worksheets": [
|
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2015-03-01 19:22:43 +08:00
|
|
|
"# Linux Commands\n",
|
|
|
|
"\n",
|
|
|
|
"* Disk Usage\n",
|
|
|
|
"* Splitting Files\n",
|
2015-03-12 08:30:23 +08:00
|
|
|
"* Grep, Sed\n",
|
2015-03-01 19:22:43 +08:00
|
|
|
"* Compression\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"* Curl\n",
|
2015-03-02 04:51:25 +08:00
|
|
|
"* View Running Processes\n",
|
2015-03-01 21:16:23 +08:00
|
|
|
"* Terminal Syntax Highlighting\n",
|
|
|
|
"* Vim"
|
2015-03-01 01:30:36 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Disk Usage"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Display human-readable (-h) free disk space:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!df -h"
|
2015-03-01 01:30:36 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Display human-readable (-h) disk usage statistics:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!du -h ./"
|
2015-03-01 01:30:36 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Display human-readable (-h) disk usage statistics, showing only the total usage (-s):"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!du -sh ../"
|
2015-03-01 01:30:36 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Display the human-readable (-h) disk usage statistics, showing also the grand total for all file types (-c):"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!du -csh ./"
|
2015-03-01 01:30:36 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 01:32:08 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Splitting Files"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Count number of lines in a file with wc:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!wc -l < file.txt"
|
2015-03-01 01:32:08 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Count the number of lines in a file with grep:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!grep -c \".\" file.txt"
|
2015-03-01 01:32:08 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Split a file into multiple files based on line count:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!split -l 20 file.txt new"
|
2015-03-01 01:32:08 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Split a file into multiple files based on line count, use suffix of length 1:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!split -l 802 -a 1 file.csv dir/part-user-csv.tbl-"
|
2015-03-01 01:32:08 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 01:37:18 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2015-03-12 08:30:23 +08:00
|
|
|
"## Grep, Sed"
|
2015-03-01 01:37:18 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2015-03-12 08:30:23 +08:00
|
|
|
"List number of files matching \u201c.txt\":"
|
2015-03-01 01:37:18 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!ls -1 | grep .txt | wc -l"
|
2015-03-01 01:37:18 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Check number of MapReduce records processed, outputting the results to the terminal:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!cat * | grep -c \"foo\" folder/part*"
|
2015-03-01 01:37:18 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 01:38:52 +08:00
|
|
|
},
|
2015-03-12 08:30:23 +08:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Delete matching lines in place:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!sed -i '/Important Lines: /d\u2019 original_file"
|
2015-03-12 08:30:23 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
2015-03-01 01:38:52 +08:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Compression"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-03 23:17:10 +08:00
|
|
|
"# Compress zip\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!zip -r archive_name.zip folder_to_compress\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Compress zip without invisible Mac resources\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!zip -r -X archive_name.zip folder_to_compress\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Extract zip\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!unzip archive_name.zip\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Compress TAR.GZ\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!tar -zcvf archive_name.tar.gz folder_to_compress\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Extract TAR.GZ\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!tar -zxvf archive_name.tar.gz\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Compress TAR.BZ2\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!tar -jcvf archive_name.tar.bz2 folder_to_compress\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Extract TAR.BZ2\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!tar -jxvf archive_name.tar.bz2\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Extract GZ\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!gunzip archivename.gz\n",
|
2015-03-03 23:17:10 +08:00
|
|
|
"\n",
|
|
|
|
"# Uncompress all tar.gz in current directory to another directory\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!for i in *.tar.gz; do echo working on $i; tar xvzf $i -C directory/ ; done"
|
2015-03-01 01:38:52 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 01:40:18 +08:00
|
|
|
},
|
2015-03-02 05:27:48 +08:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Curl"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"# Display the curl output:\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl donnemartin.com\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Download the curl output to a file:\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl donnemartin.com > donnemartin.html\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Download the curl output to a file -o\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -o image.png http://i1.wp.com/donnemartin.com/wp-content/uploads/2015/02/splunk_cover.png\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Download the curl output to a file, keeping the original file name -O\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -O http://i1.wp.com/donnemartin.com/wp-content/uploads/2015/02/splunk_cover.png\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
" \n",
|
|
|
|
"# Download multiple files, attempting to reuse the same connection\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -O url1 -O url2\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Follow redirects -L\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -L url\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Resume a previous download -C -\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -C - -O url\n",
|
2015-03-02 05:27:48 +08:00
|
|
|
"\n",
|
|
|
|
"# Authenticate -u\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!curl -u username:password url"
|
2015-03-02 05:27:48 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
2015-03-02 04:51:25 +08:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## View Running Processes"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"# Display sorted info about processes\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!top\n",
|
2015-03-02 04:51:25 +08:00
|
|
|
"\n",
|
|
|
|
"# Display all running processes\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!ps aux | less\n",
|
2015-03-02 04:51:25 +08:00
|
|
|
"\n",
|
2015-03-12 08:30:23 +08:00
|
|
|
"# Display all matching running processes with full formatting\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!ps -ef | grep python\n",
|
2015-03-12 08:30:23 +08:00
|
|
|
"\n",
|
2015-03-02 04:51:25 +08:00
|
|
|
"# See processes run by user dmartin\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!ps -u dmartin\n",
|
2015-03-02 04:51:25 +08:00
|
|
|
"\n",
|
|
|
|
"# Display running processes as a tree\n",
|
2015-03-13 19:59:28 +08:00
|
|
|
"!pstree"
|
2015-03-02 04:51:25 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
2015-03-01 01:40:18 +08:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2015-03-01 19:22:43 +08:00
|
|
|
"## Terminal Syntax Highlighting"
|
2015-03-01 01:40:18 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Add the following to your ~/.bash_profile:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
|
|
|
"export PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\W\\[\\033[00m\\]\\$ '\n",
|
|
|
|
"export CLICOLOR=1\n",
|
|
|
|
"export LSCOLORS=ExFxBxDxCxegedabagacad\n",
|
|
|
|
"alias ls='ls -GFh'"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Reload .bash_profile:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!source ~/.bash_profile"
|
2015-03-01 01:40:18 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 21:16:23 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Vim"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2015-03-01 21:18:24 +08:00
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-01 21:16:23 +08:00
|
|
|
"Normal mode: esc\n",
|
|
|
|
"\n",
|
|
|
|
"Basic movement: h, j, k, l\n",
|
|
|
|
"Word movement: w, W, e, E, b, B\n",
|
|
|
|
"\n",
|
|
|
|
"Go to matching parenthesis: %\n",
|
|
|
|
"Go to start of the line: 0\n",
|
|
|
|
"Go to end of the line: $\n",
|
|
|
|
"\n",
|
|
|
|
"Find character: f\n",
|
|
|
|
"\n",
|
|
|
|
"Insert mode: i\n",
|
|
|
|
"Append to line: A\n",
|
|
|
|
"\n",
|
|
|
|
"Delete character: x\n",
|
|
|
|
"Delete command: d\n",
|
|
|
|
"Delete line: dd\n",
|
|
|
|
"\n",
|
|
|
|
"Replace command: r\n",
|
|
|
|
"Change command: c\n",
|
|
|
|
"\n",
|
|
|
|
"Undo: u (U for all changes on a line)\n",
|
|
|
|
"Redo: CTRL-R\n",
|
|
|
|
"\n",
|
|
|
|
"Copy the current line: yy\n",
|
|
|
|
"Paste the current line: p (P for paste above cursor)\n",
|
|
|
|
"\n",
|
|
|
|
"Quit without saving changes: q!\n",
|
2015-03-12 08:30:23 +08:00
|
|
|
"Write the current file and quit: :wq"
|
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Run the following command to enable the tutorial:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!vimtutor"
|
2015-03-12 08:30:23 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Run the following commands to enable syntax colors:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"collapsed": false,
|
|
|
|
"input": [
|
2015-03-13 19:59:28 +08:00
|
|
|
"!cd ~\n",
|
|
|
|
"!vim .vimrc\n",
|
|
|
|
"# Add the following to ~/.vimrc\n",
|
2015-03-01 21:16:23 +08:00
|
|
|
"syntax on\n",
|
|
|
|
":wq"
|
2015-03-01 21:18:24 +08:00
|
|
|
],
|
|
|
|
"language": "python",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": []
|
2015-03-01 01:30:36 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|