Not really a unix command, but a vi command that has been really useful, specially if you do lots of editing protected files and want to keep your custom vim configuration: !sudo tee %
:%!sudo tee %
81–90 of 135 posts
Not really a unix command, but a vi command that has been really useful, specially if you do lots of editing protected files and want to keep your custom vim configuration: !sudo tee %
:%!sudo tee %
Ctrl+l is my most used command. I need a clean terminal
Ctrl+D for quick logout too.
mount -t overlayfs -o lowerdir=$HOME,upperdir=/tmp/tmpHOME overlayfs $HOME
Earlier quoted context omitted.
Are you some kind of genius?
If you enjoy 'tac', you might also enjoy 'sponge'. Spong 'soaks up' input an releases it all on one chunk so that you can do things like: cat foo | sponge foo (`cat foo > foo` does not work) That's neat and all, but what if you don't have sponge? Well, just use tac twice! cat foo | tac | tac > foo (Obviously this is rather wasteful ;))
"cat foo > foo" breaks, because the shell truncates the file "foo" while it's setting up the redirection, before it launches "cat foo", and so cat has nothing to read.
"cat foo | sponge foo" works because the shell is not responsible for writing to foo; it launches cat (which opens the file for reading) then launches sponge (which eventually opens the file for writing).
I would thus expect "cat foo | tac | tac > foo" to fail in the same way as "cat foo > foo" because the shell is still going to open the file foo and truncate it, but experimentation shows that it does actually work. Is it because the shell launches each pipeline one at a time, so cat has read the file before "tac > foo" truncates it? Is it a race-condition or a corner-case?
Earlier quoted context omitted.
If you enjoy 'tac', you might also enjoy 'sponge'. Spong 'soaks up' input an releases it all on one chunk so that you can do things like: cat foo | sponge foo (`cat foo > foo` does not work) That's neat and all, but what if you don't have sponge? Well, just use tac twice! cat foo | tac | tac > foo (Obviously this is rather wasteful ;))
I cannot understand how this works. "cat foo > foo" breaks, because the shell truncates the file "foo" while it's setting up the redirection, before it launches "cat foo", and so cat has nothing to read. "cat foo | sponge foo" works because the shell is not responsible for writing to foo; it launches cat (which opens the file for reading) then launches sponge (which eventually opens the file for writing). I would thu…
Ctrl+l is my most used command. I need a clean terminal
Earlier quoted context omitted.
If you enjoy 'tac', you might also enjoy 'sponge'. Spong 'soaks up' input an releases it all on one chunk so that you can do things like: cat foo | sponge foo (`cat foo > foo` does not work) That's neat and all, but what if you don't have sponge? Well, just use tac twice! cat foo | tac | tac > foo (Obviously this is rather wasteful ;))
I cannot understand how this works. "cat foo > foo" breaks, because the shell truncates the file "foo" while it's setting up the redirection, before it launches "cat foo", and so cat has nothing to read. "cat foo | sponge foo" works because the shell is not responsible for writing to foo; it launches cat (which opens the file for reading) then launches sponge (which eventually opens the file for writing). I would thu…
Furthermore `cat foo | cat > foo` does not work, but `cat foo | cat | cat > foo` does work.
I suspect this behavior is actually a race condition of some sort.
Edit: definetly a race condition, shown by larger files:
% wc -l foo
1310720 foo
% cat foo | cat | cat > foo
% wc -l foo
16384 1