One-liners: Difference between revisions

m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
No edit summary
Line 7: Line 7:
<syntaxhighlight lang="bash">du -cks -- * | sort -rn | head</syntaxhighlight>
<syntaxhighlight lang="bash">du -cks -- * | sort -rn | head</syntaxhighlight>
<code>du --total --block-size=1K --summarize</code> and the double dash argument means 'take the arguments from STDIN' then the asterisk is the glob character that matches 'everything in this directory', so each file and directory in the current working directory is summarized. This is the piped to <code>sort</code> with the reverse, numeric options and then piped to <code>head</code> for showing just the top 10. Adjust to taste.
<code>du --total --block-size=1K --summarize</code> and the double dash argument means 'take the arguments from STDIN' then the asterisk is the glob character that matches 'everything in this directory', so each file and directory in the current working directory is summarized. This is the piped to <code>sort</code> with the reverse, numeric options and then piped to <code>head</code> for showing just the top 10. Adjust to taste.
== Truncate a file ==
Redirecting (null) input to the file will truncate that file.
If the 'noclobber' option is set, then trying to redirect to an existing file will give an error message. You can work around this without changing your noclobber setting by simply using a pipe, as shown in the second instance. By the way, you can check all options with <code>set -o</code><syntaxhighlight lang="bash">
> /my/big/debug.log
# or, add a pipe
>| /my/big/debug.log
</syntaxhighlight>If you need to be root to overwrite the file, then either use sudo with tee or the truncate command
<code>echo -n "" | sudo tee error.log</code>
The <code>-n</code> option is to avoid the automatic trailing newline - so it truly makes the file empty.
<code>sudo truncate --size=0 error.log</code>
<code>-s</code> is the short option for <code>--size</code> so <code>sudo truncate -s0 error.log</code> works identically.


==Mount remote filesystem==
==Mount remote filesystem==