-6

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.).

7
  • May I ask... why?
    – kraxor
    Jun 21, 2014 at 23:39
  • Part of a homework. ? and + are allowed. Any other suggestions? This did not work, tried everything possible on the internet. Need something that works in general. Jun 21, 2014 at 23:43
  • I'd be careful then... la is not present in all linuxes.
    – Rinzwind
    Jun 21, 2014 at 23:46
  • 1
    I need the hidden ones, it does not matter if it will display others or not. Jun 22, 2014 at 0:10
  • 2
    @IvayloToskov which version of Ubuntu are you running? It seems like you don't run an Ubuntu machine. Questions about linux distributions other than Ubuntu are asked here. Jun 22, 2014 at 9:31

4 Answers 4

7

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.

2
  • 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
  • 4
    You 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.
    – l0b0
    Jun 22, 2014 at 0:20
3

Ubuntu has a default alias for ls -la. You can simply use

la
5
  • No aliases on the computer I am working on, including la and ll Jun 21, 2014 at 23:46
  • 3
    The answer is valid and correct for Ubuntu. Are you using something else? If so...
    – Rinzwind
    Jun 21, 2014 at 23:53
  • .bashrc is a personnal file. I, for instance, don't have la in my .bashrc
    – MrVaykadji
    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.
    – enedil
    Jun 22, 2014 at 10:34
  • @enedil hence why I asked; I seriously doubt he is.
    – Rinzwind
    Jun 22, 2014 at 11:50
2
echo `printf '.\x2A'`

Unicode table for the win.

1

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.)

2
  • It isn't said that OP is using Bash.
    – enedil
    Jun 22, 2014 at 10:36
  • It isn't said that OP isn't using bash. Also, the question is tagged bash.
    – Jayen
    Jun 23, 2014 at 2:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .