Linux find command permission denied - shell

I want to filter out the unnecessary information "Permission denied".
these are outputs from command "find -type f -name sources.list"
find: './run/lxcfs': Permission denied
find: './run/sudo': Permission denied
find: './run/lvm': Permission denied
find: './tmp/systemd-private-99eef94819d84080adc7df3e60efee5b-systemd-timesyncd.service-HE48k9': Permission denied
find: './lost+found': Permission denied
find: './dev/vboxusb': Permission denied
find: './root': Permission denied
./etc/apt/sources.list
find: './etc/sudoers.d': Permission denied
I tried to use "! -readable -prune" in conjunction with the find command as above to suppress the "Permission denied" information, but it still doesn't work.

try the following
find -type f -name sources.list 2>/dev/null
This will redirect stderr output stream, which is used to report all errors, including the "Access denied" one, to null device.

Something like this should work
find -type d ! -readable -prune -o -type f -name sources.list

The following worked for me:
find / -mount -readable -name "<whatever>" -print
Here I only wanted to search the root file system, and not descent into any of the mounted file systems. Hence -mount.
The problem files that were throwing errors were not readable (yielding "permission denied"). Hence -readable.
The rest is obvious.
(Note: In Ubuntu 16.04 the files in /var/lib/lxcfs are not readable, even for root. The above solved the problem for me.)

First you can check the ACL of folders with the help of
getfacl -R /foldername
if read permission is there to particular folder,then run;
find foldername -type f -name sources.list
else
skip command

Related

Permission denied when running shell script using 'wkhtmltopdf' tool

Hi!
So, I am using the wkhtmltopdf tool in a script on my Ubuntu terminal...
#!/bin/bash
#search for every '*.html' extension and store it in 'output.txt' file
find /home/guidine/09 -name '*.html' > output.txt
#read 'output.txt' file executing the command 'wkhtmltopdf' syntax for each line
for word in $(cat /home/guidine/bin/output.txt)
do
$wkhtmltopfd $word $word".pdf"
done
Which returns every line (it's a path) in the 'output.txt' with the 'Permission denied' message (example annexed), can anyone help me?
Screenshot of output
I've already did $ chmod +x wkhtmltopdf.sh.
I've found an alternative that satisfied me and I'm closing the question.
find <directory> -name '*.html' -exec wkhtmltopdf {} {}.pdf \;

Get "unknown predicate `-delete" Error in script

The following script I have saved in an .sh file on the server that clears a few directories of old files and directories.
#!/bin/bash
find /PATH_TO_DIRECTORY_1 -mtime +5 -type f -delete
find /PATH_TO_DIRECTORY_2 -mtime +5 -type f -delete
find /PATH_TO_DIRECTORY_3 -mtime +5 -type d -exec rm -rv {} +
This is the error message when I run the script:
'ind: unknown predicate `-delete
In addition to
$'\r': command not found
I don't think the latter disturbs the code but the first one surely does.
Mind that I edit my code on Windows 10 and my server is an Ubuntu 64x run through Amazon Web Services (EC2).
I encountered the same issue.
The problem was that my file was in dos format.
Using the command dos2unix on my file, solve the problem.

Check if user has permission to execute file

as in title: how to check if user(script parameter) have permission to execute file using find in bash?
I think is something with -perm but i tottaly dont now how to start with that.
Use find as in the following example, given user as script parameter $1:
$ find /path/to/dir/ -user $1 -type f -perm -u+x

Stop bash script when find gets to a folder with permission denied

How can I stop script when command "find" gets to a folder with permission denied.
I make a list of all folders in my PC.
I would like to stop the searching process when "find" finds a permission denied folder.
DIRS=$(find . -type d)
Thanks a lot
Can't test this now, but you should check with exec if the folder is executable.
Something like
find -type d -print0 -not -exec test -x '{}' \; -quit

Find command in windows 7

Recently migrated from windows XP to Windows 7.
I am using the eclipse environment for building the project. I have a make file with the below command
clean:
find . -type f -name "*.o" -exec rm {} \;
This was used to search and delete the object files in the current directory.
After I moved to windows 7 the same command does not work. Below is the output of the command on Windows 7.
cs-make all
find . -type f -name "*.o" -exec rm {} \;
Access denied - .
File not found - -TYPE
File not found - F
File not found - -NAME
File not found - -EXEC
File not found - RM
File not found - {}
File not found - ;
cs-make: *** [clean] Error 1***
My account has admin rights. Also I tried running eclipse using "run as admin".
If someone knows the solution please let me know.

Resources