data-science-ipython-notebooks/commands/linux.ipynb

172 lines
3.2 KiB
Plaintext

{
"metadata": {
"name": "",
"signature": "sha256:e595a63f61ca91bdd492a8932695aa68c3ef680260edee4cfe01574de3e4a431"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Linux Commands"
]
},
{
"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": [
"df -h"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display human-readable (-h) disk usage statistics:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"du -h ./"
],
"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": [
"du -sh ../"
],
"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": [
"du -csh ./"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"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": [
"wc -l < file.txt"
],
"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": [
"grep -c \".\" file.txt"
],
"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": [
"split -l 20 file.txt new"
],
"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": [
"split -l 802 -a 1 file.csv dir/part-user-csv.tbl-"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}