Truncate a file: Difference between revisions

Content added Content deleted
Line 660: Line 660:
<lang bash>
<lang bash>
# 1. simplest one-liner
# 1. simplest one-liner
-bash$ >file

# or the more clear/verbose:
echo -n>file
echo -n>file


Line 686: Line 689:
+ f=bad
+ f=bad
+ echo -n
+ echo -n
-bash: bad: No such file or directory

# Try again with the shortest version: f="bad"<$f>$f
+ ls -l bad
-rw-r--r-- 1 fieldsa fieldsa 8192 Dec 5 01:04 bad
-bash-4.2$ f="bad" <$f>$f
+ f=bad
-bash-4.2$ ls -l
+ ls -l
-rw-r--r-- 1 fieldsa fieldsa 0 Dec 5 01:04 bad
-bash-4.2$ rm bad
+ rm bad
-bash-4.2$ f="bad" <$f>$f
+ f=bad
-bash: bad: No such file or directory
-bash: bad: No such file or directory