The contents of my home directory:
bin Desktop Documents Downloads folders Music Pictures Public Templates Videos
When I run the command
for file in /home/myself/*d*; do if [ -x "$file" ]; then echo $file; fi; done
it finds
/home/myself/Downloads
/home/myself/Videos
but not "folders".
Ubuntu 18.04.2; Xfce 4.12.3; kernel 4.15.0-45-generic; bash 4.4.19(1); Dell Inspiron-518
man test
yields:
-x FILE
FILE exists and execute (or search) permission is granted
Is folders
a directory?
What are its permissions?
1 Like
permissions fixed it! thanks!
edit: it is not a folder; I was just experimenting
Be very careful with using this because if there are filesname with spaces, tabs or other non-printing characters, it might break again.
You might be better to use find instead:-
find . -name "*d*" -print
I'm sure that this isn't all you want to do, but spaces in filenames (or other things) can cause problems. What is the overall requirement?
Kind regards,
Robin
1 Like
vbe
April 3, 2019, 12:44pm
5
Folders would be seen as files with execute perms, so the question is more are those "folder" true folders or files, because files dont necessarily need execution perms, but it gets more tricky when talking of subdirectories: not giving them x means you cannot traverse them...
1 Like
EDIT: fixed it. Putting -maxdepth before -name works!
@rbattel
When I run
find . -name "*d*" -print
several hundred files are found, as it delved into subdirectories (not my intent)
but when I try
find . -name -maxdepth 1 "*d*" -print
I get
find: paths must precede expression: `1'