cheatsheets/command_line.html

615 lines
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang='en' class='no-js '>
<head>
<meta charset='utf-8'>
<meta content='width=device-width, initial-scale=1.0' name='viewport'>
<link href='./assets/favicon.png' rel='shortcut icon'>
<meta content='/command_line.html' name='app:pageurl'>
<title>Command line stuff cheatsheet</title>
<meta content='Command line stuff cheatsheet' property='og:title'>
<meta content='Command line stuff cheatsheet' property='twitter:title'>
<meta content='article' property='og:type'>
<meta content='https://assets.devhints.io/previews/command_line.jpg?t=20200705155142' property='og:image'>
<meta content='https://assets.devhints.io/previews/command_line.jpg?t=20200705155142' property='twitter:image'>
<meta content='900' property='og:image:width'>
<meta content='471' property='og:image:height'>
<meta content="The one-page guide to Command line stuff: usage, examples, links, snippets, and more." name="description">
<meta content="The one-page guide to Command line stuff: usage, examples, links, snippets, and more." property="og:description">
<meta content="The one-page guide to Command line stuff: usage, examples, links, snippets, and more." property="twitter:description">
<link rel="canonical" href="https://devhints.io/command_line">
<meta name="og:url" content="https://devhints.io/command_line">
<meta content='Devhints.io cheatsheets' property='og:site_name'>
<meta content='Others' property='article:section'>
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-106902774-1'></script>
<script>
window.dataLayer=window.dataLayer||[];
function gtag(){dataLayer.push(arguments)};
gtag('js',new Date());
gtag('config','UA-106902774-1');
</script>
<meta property='page:depth' content='1'>
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
<script>(function(H){H.className=H.className.replace(/\bNoJs\b/,'WithJs')})(document.documentElement)</script>
<script>(function(d,s){if(window.Promise&&[].includes&&Object.assign&&window.Map)return;var js,sc=d.getElementsByTagName(s)[0];js=d.createElement(s);js.src='https://cdn.polyfill.io/v2/polyfill.min.js';sc.parentNode.insertBefore(js, sc);}(document,'script'))</script>
<!--[if lt IE 9]><script src='https://cdnjs.cloudflare.com/ajax/libs/nwmatcher/1.2.5/nwmatcher.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/json2/20140204/json2.js'></script><script src='https://cdn.rawgit.com/gisu/selectivizr/1.0.3/selectivizr.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script><![endif]-->
<style>html{opacity:0}</style>
<link rel="stylesheet" href="./assets/2015/style.css?t=20200705155142">
<link href="./assets/style.css?t=20200705155142" rel="stylesheet" />
<link href="./assets/print.css?t=20200705155142" rel="stylesheet" media="print" />
</head>
<body>
<div class='all'>
<div class='site-header'>
<div class='container'>
This is <a href="."><em>Devhints.io cheatsheets</em></a> &mdash; a collection of cheatsheets I've written.
</div>
</div>
<script type='application/ld+json'>
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://google.com/article"
},
"headline": "Command line stuff cheatsheet",
"image": [ "https://assets.devhints.io/previews/command_line.jpg?t=20200705155142" ],
"description": "The one-page guide to Command line stuff: usage, examples, links, snippets, and more."
}
</script>
<script type='application/ld+json'>
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://devhints.io/#others",
"name": "Others"
}
},{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "https://devhints.io/command_line",
"name": "Command line stuff"
}
}]
}
</script>
<div class='post-list -single -cheatsheet'>
<div class='post-item'>
<div class='post-headline -cheatsheet'>
<p class='prelude'><span></span></p>
<h1><span>Command line stuff</span></h1>
<div class='pubbox'>
<div class='HeadlinePub' role='complementary'>
<script async src='https://pubsrv.devhints.io/carbon.js?serve=CE7IK5QM&placement=devhintsio' id="_carbonads_js"></script>
<span class='placeholder -one'></span>
<span class='placeholder -two'></span>
<span class='placeholder -three'></span>
<span class='placeholder -four'></span>
</div>
</div>
</div>
<div class='post-content -cheatsheet'>
<h2 id="list-ls">List (ls)</h2>
<pre><code>ls [options] [paths]
</code></pre>
<h3 id="format">Format</h3>
<table class="shortcuts">
<thead>
<tr>
<th>Switch</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-1</code></td>
<td>One entry per line</td>
</tr>
<tr>
<td><code>-l</code></td>
<td>Long view</td>
</tr>
<tr>
<td><code>-o</code></td>
<td>Long view (without groups)</td>
</tr>
<tr>
<td><code>-C</code></td>
<td>Multicolumn (sorted horizontally)</td>
</tr>
<tr>
<td><code>-x</code></td>
<td>Multicolumn (sorted vertically)</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-F</code></td>
<td>Add / after directories</td>
</tr>
<tr>
<td><code>-G</code></td>
<td>Color</td>
</tr>
</tbody>
</table>
<h3 id="options">Options</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-R</code></td>
<td>Recurse</td>
</tr>
<tr>
<td><code>-a</code></td>
<td>Include hidden (dotfiles)</td>
</tr>
<tr>
<td><code>-A</code></td>
<td>Include hidden (but not . and ..)</td>
</tr>
</tbody>
</table>
<h3 id="sorting">Sorting</h3>
<table class="shortcuts">
<thead>
<tr>
<th>Switch</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-r</code></td>
<td>reverse order</td>
</tr>
<tr>
<td><code>-S</code></td>
<td>sort by size</td>
</tr>
<tr>
<td><code>-t</code></td>
<td>sort by time modified</td>
</tr>
<tr>
<td><code>-u</code></td>
<td>sort by time accessed</td>
</tr>
<tr>
<td><code>-U</code></td>
<td>sort by time created</td>
</tr>
<tr>
<td><code>-c</code></td>
<td>sort by time status was changed</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-h</code></td>
<td>Human-readable size (3k)</td>
</tr>
</tbody>
</table>
<p><br /></p>
<h2 id="tail">Tail</h2>
<pre><code>tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]
</code></pre>
<h3 id="modes">Modes</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-f</code></td>
<td>follow</td>
</tr>
<tr>
<td><code>-F</code></td>
<td>follow by filename (accounts for log rotation)</td>
</tr>
<tr>
<td><code>-r</code></td>
<td>Reverse order</td>
</tr>
</tbody>
</table>
<h3 id="options-1">Options</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-bN</code></td>
<td>N*512 bytes</td>
</tr>
<tr>
<td><code>-cN</code></td>
<td>N bytes</td>
</tr>
<tr>
<td><code>-nN</code></td>
<td>N lines</td>
</tr>
<tr>
<td><code>+N</code></td>
<td>Start from line N</td>
</tr>
</tbody>
</table>
<p><br /></p>
<h2 id="sudo">Sudo</h2>
<pre><code>sudo [options] &lt;command&gt;
</code></pre>
<h3 id="listing">Listing</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-l</code></td>
<td>List allowed commands</td>
</tr>
</tbody>
</table>
<h3 id="options-2">Options</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-A</code></td>
<td>Use $SUDO_ASKPASS</td>
</tr>
<tr>
<td><code>-b</code></td>
<td>Run in background</td>
</tr>
<tr>
<td><code>-E</code></td>
<td>Preserve environment</td>
</tr>
<tr>
<td><code>-H</code></td>
<td>use targets $HOME</td>
</tr>
<tr>
<td><code>-n</code></td>
<td>Dont prompt for password</td>
</tr>
<tr>
<td><code>-P</code></td>
<td>Preserve group vector</td>
</tr>
<tr>
<td><code>-S</code></td>
<td>Read password from stdin</td>
</tr>
</tbody>
</table>
<h3 id="file-descriptors">File descriptors</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-C fd</code></td>
<td>Close all open file descriptors</td>
</tr>
</tbody>
</table>
<h3 id="prompt">Prompt</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-p prompt</code></td>
<td>Custom prompt (-p “%p password:”)</td>
</tr>
</tbody>
</table>
<h3 id="interactive">Interactive</h3>
<table class="shortcuts">
<thead>
<tr>
<th>Switch</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-i [cmd]</code></td>
<td>Interactive shell without variables</td>
</tr>
<tr>
<td><code>-s [cmd]</code></td>
<td>Interactive shell</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-u user</code></td>
<td>run as this user</td>
</tr>
<tr>
<td><code>-g group</code></td>
<td>run as this group</td>
</tr>
</tbody>
</table>
<h3 id="timestamp">Timestamp</h3>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-v</code></td>
<td>revalidate timestamp for 5 mins</td>
</tr>
<tr>
<td><code>-k</code></td>
<td>invalidate timestamp</td>
</tr>
<tr>
<td><code>-K</code></td>
<td>just like -k</td>
</tr>
</tbody>
</table>
<p><br /></p>
<h2 id="wc-word-count">wc (Word count)</h2>
<pre><code>... | wc [options]
</code></pre>
<table class="shortcuts">
<tbody>
<tr>
<td><code>-c</code></td>
<td>Bytes</td>
</tr>
<tr>
<td><code>-l</code></td>
<td>Lines</td>
</tr>
<tr>
<td><code>-m</code></td>
<td>Characters (incl multi-byte)</td>
</tr>
<tr>
<td><code>-w</code></td>
<td>Words</td>
</tr>
</tbody>
</table>
<p><br /></p>
<h2 id="search-and-replace-in-all-files">Search-and-replace in all files</h2>
<pre><code>perl -p -i -e 's/hello/HELLO/g' **/*
</code></pre>
<p><br /></p>
<h2 id="grep">Grep</h2>
<pre><code>grep [options] [pattern] [file ...]
</code></pre>
<h3 id="options-3">Options</h3>
<table class="shortcuts">
<thead>
<tr>
<th>Switch</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-A num</code></td>
<td>Print <code>num</code> lines of training context</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-G</code></td>
<td>basic-regexp (default)</td>
</tr>
<tr>
<td><code>-E</code></td>
<td>extended-regexp</td>
</tr>
<tr>
<td><code>-P</code></td>
<td>perl-regexp</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-f file</code></td>
<td>file (Get patterns for file)</td>
</tr>
<tr>
<td><code>-F</code></td>
<td>fixed-strings</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-h</code></td>
<td>no-filename</td>
</tr>
<tr>
<td><code>-H</code></td>
<td>with-filename</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-l</code></td>
<td>files-with-matches (just print filenames)</td>
</tr>
<tr>
<td><code>-L</code></td>
<td>files-without-match</td>
</tr>
</tbody>
<tbody>
<tr>
<td><code>-r, -R</code></td>
<td>recursive</td>
</tr>
<tr>
<td><code>-v</code></td>
<td>invert-match</td>
</tr>
<tr>
<td><code>-i</code></td>
<td>ignore-case</td>
</tr>
</tbody>
</table>
<h3 id="synonyms">Synonyms</h3>
<pre><code>egrep =&gt; grep -E
fgrep =&gt; grep -F
</code></pre>
</div>
<ul class="social-list ">
<li class="facebook link hint--bottom" data-hint="Share on Facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https://devhints.io/command_line.html" target="share"><span class="text"></span></a></li>
<li class="twitter link hint--bottom" data-hint="Share on Twitter"><a href="https://twitter.com/intent/tweet?text=The%20ultimate%20cheatsheet%20for%20Command%20line%20stuff.%20https://devhints.io/command_line.html" target="share"><span class="text"></span></a></li>
</ul>
</div>
</div>
<div class="about-the-site">
<div class="container">
<p class='blurb'>
<strong><a href=".">Devhints.io cheatsheets</a></strong> is a collection of cheatsheets I've written over the years.
Suggestions and corrections? <a href='https://github.com/rstacruz/cheatsheets/issues/907'>Send them in</a>.
<i class='fleuron'></i>
I'm <a href="http://ricostacruz.com">Rico Sta. Cruz</a>.
Check out my <a href="http://ricostacruz.com/til">Today I learned blog</a> for more.
</p>
<p class='back'>
<a class='big-button -back -slim' href='.#toc'></a>
</p>
<p>
</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
<script src="https://cdn.rawgit.com/rstacruz/unorphan/v1.0.1/index.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
<script>unorphan('h1, h2, h3, p, li, .unorphan')</script>
</body>
</html>