When I run
ls command I get files like
opencv.sh~ in my output which is not visible if I check the home directory.
Basically, it also lists hidden files without supplying any other parameter. How can I prevent this ?
My dist is Ubuntu 14.04
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
opencv.sh~ is not a hidden file. POSIX defines a hidden file as one starting with a dot, but
opencv.sh~ does not start with a dot.
If you don't want to see these files, you can explicitly avoid them by using a glob that doesn't include them (for example,
shopt -s extglob followed by
ls !(*\~)), or (as I assume these are from vim), you can configure vim not to put backup files in the same directory.
There's no property on a file that indicates that it's hidden. Early versions of Unix had an
ls command that hid files whose name begins with
. (“dot files”) and that tradition stuck. The
ls command, by default, hides files whose name begins with
. and shows all other files.
Some graphical file managers hide files whose name begins with
., just like
ls, because that's what many users expect. Gnome has launched a new convention, which is that directories can contain a file called
.hidden which contains a list of files to hide (one file name per line, no patterns allowed).
You didn't mention which file manager you used, it's possible that it has different rules for hiding files. If
opencv.sh~ is hidden, that follows decidedly non-standard rules, so you can't legitimately complain that
ls isn't following these non-standard rules.
~ at the end of a file name is the convention for a backup file. That is,
opencv.sh~ is an earlier version of
opencv.sh, created by your editor when you saved
The GNU version of
ls supports an option
-I to ignore extra patterns (in addition to dot files). If you want to hide backup files from
ls, you can make an alias that adds
-I "*~" to the
alias ls='ls -I "*~"'
(plus any other option you wish, e.g.
alias ls='ls -I "*~"' --color to use colors to indicate file types). Put that line in your
.zshrc or whatever initialization file your shell uses.