Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

": > file" VS "> file"

Tags:

bash

shell

sh

touch

Is there any differences between ": > file" and "> file"?

$ : > file.out
$ ls -l file.out
-rw-rw----   1 user    user             0 Mar 18 21:08 file.out
$ > file.out
$ ls -l  file.out
-rw-rw----   1 user    user             0 Mar 18 21:08 file.out
like image 973
Volodymyr Bezuglyy Avatar asked Mar 18 '10 19:03

Volodymyr Bezuglyy


1 Answers

: is the shell built-in NO-OP or null operation. So yeah, directing it to a file ends up with an empty file, as does directing nothing to a file. There's a sense, I suppose, in which your source is a different kind of nothing, but the result is the same. According to the advanced Bash scripting guide, the "> file.out" formulation won't work on some systems.

Note that in both cases (unlike "touch") the file contents will be replaced with nothing if the file already exists.

like image 127
Jacob Mattison Avatar answered Sep 18 '22 15:09

Jacob Mattison