Is it possible to list hidden files without using the characters mentioned above? This means not using any options or the * wildcard as well as some other characters (e.g this is not allowed ls -a
, ls -d
, .!(|.)
, echo .*
etc.).
4 Answers
find .
will list all files including hidden ones.
Corollary: Somebody thinks it's a good idea to teach about command injection by blacklisting individual characters and possibly even commands in your script. That is actively harmful to your learning about the shell because you end up with hacks like escape characters or relying on Ubuntu-specific default configuration, both of which won't be able to handle special file names.
It actually sounds like whoever came up with this wanted to use eval
for some reason (which is always* a terrible idea) rather than just executing the submitted code or script directly.
The absolutely simplest way to loop over hidden files is
for file in .*
do
my_command "$file"
done
* Or so damn close to always that you'd better have read and understood the entire Bash wiki article about it before even considering using it.
-
The command could not be executed cause it is executed within another program, which for some reason restricts it. Jun 22, 2014 at 0:18
-
4You must be running in an extremely restricted environment if
find
isn't even available. If this is part of the task then you should specify it in your question.– l0b0Jun 22, 2014 at 0:20
Ubuntu has a default alias for ls -la
. You can simply use
la
-
No aliases on the computer I am working on, including la and ll Jun 21, 2014 at 23:46
-
3The answer is valid and correct for Ubuntu. Are you using something else? If so...– RinzwindJun 21, 2014 at 23:53
-
.bashrc
is a personnal file. I, for instance, don't havela
in my .bashrc Jun 22, 2014 at 1:57 -
@Rinzwind The question was posted on Ask Ubuntu, so I can assume that OP's using Ubuntu. Otherwise, the question is off-topic.– enedilJun 22, 2014 at 10:34
-
echo .
<TAB><TAB>
It's already built into bash to do this. Don't even need to execute a command.
echo .
<Meta-*>
If you absolutely must have a command (but you still don't need any external processes.)
-
-
It isn't said that OP isn't using
bash
. Also, the question is taggedbash
.– JayenJun 23, 2014 at 2:20
la
is not present in all linuxes.