snipt

Ctrl+h for KB shortcuts

Bash

Recursively find and list the last modified files in a directory

stat --printf="%y %n\n" $(ls -tr $(find * -type f))
https://snipt.net/embed/658e81891f567c2b90931e8f90e60846/
https://snipt.net/raw/658e81891f567c2b90931e8f90e60846/
658e81891f567c2b90931e8f90e60846
bash
Bash
1
2016-09-26T19:25:48
True
False
False
Jan 31, 2014 at 06:10 AM
/api/public/snipt/109821/
recursively-find-and-list-the-last-modified-files-in-a-directory
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>stat --printf<span class="o">=</span><span class="s2">&quot;%y %n\n&quot;</span> <span class="k">$(</span>ls -tr <span class="k">$(</span>find * -type f<span class="k">))</span> </span></pre></div> </td></tr></table>
date, find, ls, stat

Shell Session

How many files in a folder

"ls *.pdf | wc -l"
https://snipt.net/embed/71df761d41673c79edc53c6427b60f3f/
https://snipt.net/raw/71df761d41673c79edc53c6427b60f3f/
71df761d41673c79edc53c6427b60f3f
shell-session
Shell Session
1
2016-09-27T19:53:06
True
False
False
Jan 14, 2014 at 08:27 AM
/api/public/snipt/105795/
how-many-files-in-a-folder
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="go">&quot;ls *.pdf | wc -l&quot;</span> </span></pre></div> </td></tr></table>
ls, unix

Bash

List directories in Linux

ls -d */
https://snipt.net/embed/e98a97a309bca1a86772d351bf8f93a5/
https://snipt.net/raw/e98a97a309bca1a86772d351bf8f93a5/
e98a97a309bca1a86772d351bf8f93a5
bash
Bash
1
2016-09-24T17:00:35
True
False
False
/api/public/snipt/25569/
list-directories-in-linux
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ls -d */ </span></pre></div> </td></tr></table>
bash, linux, ls, sh

Bash

Monitor directory changes in real-time

watch -d -n 2 'df; ls -FlAt;'
https://snipt.net/embed/e36d223de92f747858add061ce0848b9/
https://snipt.net/raw/e36d223de92f747858add061ce0848b9/
e36d223de92f747858add061ce0848b9
bash
Bash
1
2016-09-26T02:35:36
True
False
False
/api/public/snipt/14358/
monitor-directory-changes-in-real-time
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>watch -d -n <span class="m">2</span> <span class="s1">&#39;df; ls -FlAt;&#39;</span> </span></pre></div> </td></tr></table>
bash, ls, watch

Text only

sort a *nix directory listing by size

ls -al | sort -nk5
https://snipt.net/embed/d92de5da00b322eb959f56540cb0de34/
https://snipt.net/raw/d92de5da00b322eb959f56540cb0de34/
d92de5da00b322eb959f56540cb0de34
text
Text only
1
2016-09-27T13:47:05
True
False
False
/api/public/snipt/14176/
sort-a-nix-directory-listing-by-size
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ls -al | sort -nk5 </span></pre></div> </td></tr></table>
ls, size, sort

Bash

Get the number of files and directories in the current directory

echo "`ls -la | wc -l`-3" | bc -l
https://snipt.net/embed/52481bf013ddfe19011c87c65dad36ea/
https://snipt.net/raw/52481bf013ddfe19011c87c65dad36ea/
52481bf013ddfe19011c87c65dad36ea
bash
Bash
1
2016-09-23T13:58:53
True
False
False
/api/public/snipt/6604/
get-the-number-of-files-and-directories-in-the-current-directory
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nb">echo</span> <span class="s2">&quot;`ls -la | wc -l`-3&quot;</span> <span class="p">|</span> bc -l </span></pre></div> </td></tr></table>
bash, bc, echo, ls, wc

Text only

List only subdirectories

ls -l | grep ^d
https://snipt.net/embed/47011b1cd7672a34f9313510de82393f/
https://snipt.net/raw/47011b1cd7672a34f9313510de82393f/
47011b1cd7672a34f9313510de82393f
text
Text only
1
2016-09-22T09:37:04
True
False
False
/api/public/snipt/4112/
list-only-subdirectories
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ls -l | grep ^d </span></pre></div> </td></tr></table>
linux, ls, unix
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.