Monday, April 29, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 4485  / 1 Year ago, sun, april 9, 2023, 8:18:58

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


More From » command-line

 Answers
2

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.


[#24500] Monday, April 10, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atelti

Total Points: 194
Total Questions: 129
Total Answers: 110

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;