Can anyone explain this odd behavior from the "find" command?

C

CrazedNerd

Guest
EDIT: Wasn't a "find" error but mistaken about permission numbers.

So I've been testing more complicated results of the find command with finding files with certain permissions. With the first attempt, I use an or operator to display files with 0611 and 0700, because there are only a few of these files in my home directory:

Code:
find . -maxdepth 1 \( -perm 0611 \) -or \( -perm 0700 \)

However, the output only displays these hidden folders with 0700 permissions:

Code:
./.ssh
./.config
./.psensor
./snap
./.mozilla
./.gnupg
./.pki

I tried to get find to show the files with 0611 permissions in my home directory by including type, but it outputs absolutely nothing:

Code:
find -maxdepth 1 \( -type f -perm 0611 \) -or \( -type f -perm 0700 \)

Pretty complex stuff...thanks in advance for even trying. Why isn't bash behaving like i think it should? "-or" would be used in this instance to find files with both 0611 and 0700, correct?
 
Last edited by a moderator:


Seems like it works.. just tried it out:
Code:
[rob test ]$ ls -al
total 24
drwxrwxr-x  2 rob rob  4096 Jul  7 11:34 .
drwxr-xr-x 86 rob rob 12288 Jul  6 13:29 ..
-rw---x--x  1 rob rob     0 Jul  7 11:34 0611.txt
-rwx------  1 rob rob     0 Jul  7 11:34 0700.txt
-rwxr-xr-x  1 rob rob     0 Jul  7 11:34 0755.txt
-rw-rw-r--  1 rob rob   291 Jul  8  2021 50.yaml
-rw-rw-r--  1 rob rob   342 Jul  8  2021 50.yaml.bk
[rob test ]$ find -maxdepth 1 -type f \( -perm 0611 -o -perm 0700 \)
./0700.txt
./0611.txt
[rob test ]$
 
Have you tried using 'or' like this?
find -maxdepth 1 -type f \( -perm "0611" -o -perm "0700" \)
wierd, i copied and pasted that, even tried replacing the quotes with single quotes and absence of quotes, and i got no output. Maybe there is something wrong with my ubuntu installation...*shrugs*, i'll try an update and see what happens, and then try this on a VM just to be sure...cuz i'm not gonna just move from this error, it's just too weird. I haven't had much in the way of problems with any of the other command binaries, even though i expect some things to have changed since the book i'm using to figure this out was published in 2019. Maybe i'll try this in Fedora since that's the OS William Shotts is using.
 
wierd, i copied and pasted that, even tried replacing the quotes with single quotes and absence of quotes, and i got no output. Maybe there is something wrong with my ubuntu installation...*shrugs*, i'll try an update and see what happens, and then try this on a VM just to be sure...cuz i'm not gonna just move from this error, it's just too weird. I haven't had much in the way of problems with any of the other command binaries, even though i expect some things to have changed since the book i'm using to figure this out was published in 2019. Maybe i'll try this in Fedora since that's the OS William Shotts is using.
As is, I also get nothing, until I remove -maxdepth. Then I get lots of goodies.
 
Weird.. what's the version of find you're using?

Code:
[rob ~ ]$ find -version
find (GNU findutils) 4.8.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

I'm using PopOS (ubuntu really) 21.10
 
As is, I also get nothing, until I remove -maxdepth. Then I get lots of goodies.
Okay, thanks for that as well, i just don't find the "find" command to be very useful without -maxdepth. Locate works just fine, you can even do it like "locate /<search-term>" to search every directory on your computer (the "/" is root).
 
Weird.. what's the version of find you're using?

Code:
[rob ~ ]$ find -version
find (GNU findutils) 4.8.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

I'm using PopOS (ubuntu really) 21.10
mine is 4.7, so that might explain the problem!
 
mine is 4.7, so that might explain the problem!
Mine is 4.8 on LMDE5, which I think means it's probably not a version issue, since I got nothing when maxdepth was used.
 
Mine is 4.8 on LMDE5, which I think means it's probably not a version issue, since I got nothing when maxdepth was used.
Well, could be there's just no results in your current directory it sounds like. That's telling it to only look 1 directory (your current) deep. Change that to 2, 3 or 5 and you should see more results each time
 
Well, could be there's just no results in your current directory it sounds like. That's telling it to only look 1 directory (your current) deep. Change that to 2, 3 or 5 and you should see more results each time
In my case, this is a correct assessment. I entered a directory with a confirmed match, tested with maxdepth, and results were returned.
 
  • Like
Reactions: Rob
Well, could be there's just no results in your current directory it sounds like. That's telling it to only look 1 directory (your current) deep. Change that to 2, 3 or 5 and you should see more results each time
Nah, that can't be the problem, because i piped "ls -l" output for my home folder (i keep stuff related to computer education and programming there in depth 1 for easy bash access) and wrote down the octal representation for the permissions of each file, and 0611 or 0700 ain't catching everything. There are at least 3 files with 0611 permissions, and none of my attempts, at least in the complex form that "should work", have turned up sensible results. Plus, i just tried -maxdepth 2 with your copied/pased code and i got no output again. I would give more info but i somehow don't like the idea of putting my entire home directory online :p
 
i've tried rob's example without the maxdepth at all, and interestingly and wierdly, i'm not getting ANY of the results located directly in the home folder, yet 13 results from the hidden mozilla directly popped up:

Code:
/home/xarathustra/.mozilla/firefox/bxc9c3px.default/times.json
/home/xarathustra/.mozilla/firefox/zo9sersu.default-release/times.json
/home/xarathustra/.mozilla/firefox/zo9sersu.default-release/gmp-gmpopenh264/1.8.1.2/libgmpopenh264.so
/home/xarathustra/.mozilla/firefox/zo9sersu.default-release/gmp-gmpopenh264/1.8.1.2/gmpopenh264.info
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/setup.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/check-runtime-conflicts.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/switch-runtime.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/fix-symlinks.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/check-symlinks.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/check-runtime-consistency.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/fix-debuglinks.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/scripts/check-program.sh
/home/xarathustra/.local/share/Steam/ubuntu12_32/steam-runtime.old/run.sh

And when i remove -maxdepth from my first line of code in the thread, i'm getting around 50 results but it's all in the hidden directories, it's not finding ANY of the files with those permissions directly in the home folder, even though there are those directories in the example and the files which i found myself.
 
Okay, so it must be related to Ubuntu or something i perhaps accidentally did to it. I booted a live VM for Fedora, created new files, made those permissions in its home directory, and Rob's shortened version of what i posted found all the files i made. Oh well, nobody really needs find anyway :p At least i was able to install steam on ubuntu!
 
Oh well, nobody really needs find anyway :p
Yep, not a staple in my toolbox at all. I always never, ever use it all the time. I should just delete it.
 
If it's GNU find, then it really should be working the same.

Don't discount find over something like locate though - if you're working with Linux professionally you'll see that you're going to use find quite a bit in various scripts and times in your job to get things done :)

we should figure out what's happening here. Perhaps set up a test directory how I did in the previous reply and see if you get the same result.
 
On each test OS, I built a test situation:
Code:
mkdir ~/findtest
cd ~/findtest
touch {0611,0700,0777}.txt
chmod 0611 0611.txt
chmod 0700 0700.txt
chmod 0777 0777.txt

Inside the findtest directory, I ran:
Code:
find -maxdepth 1 -type f \( -perm "0611" -o -perm "0700" \)

On all OS I tested, results were the same:
Code:
./0611.txt
./0700.txt

OS:
LMDE5, find (GNU findutils) 4.8.0
Linux Mint 20.3, find (GNU findutils) 4.7.0
Ubuntu 22.04, find (GNU findutils) 4.8.0
 
  • Like
Reactions: Rob
If it's GNU find, then it really should be working the same.

Don't discount find over something like locate though - if you're working with Linux professionally you'll see that you're going to use find quite a bit in various scripts and times in your job to get things done :)

we should figure out what's happening here. Perhaps set up a test directory how I did in the previous reply and see if you get the same result.

Okay! I think professionally i would do better as a developer, even though working with bash itself is pretty fun...First things first...

Code:
find (GNU findutils) 4.7.0
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

before moving on, in terms of anything i've done purposefully, i can only think that my aliases might be interfering with the normal operation of "find", even though i doubt this:

Code:
alias ls='ls --color=auto -hAF'

alias lsh='ls -d .* | grep -v /'

alias lsf='ls | grep -v /'

alias lsd='ls -d */ .*/'

alias lsdh='ls -d .* | grep -v *.txt'

i see slow coder is a little ahead of me, so this is in part why i'm being a little more extreme about it, plus i'm very productive when i get obsessed with something.

I'm going to create a test directory with "mkdir find", "cd find"...then make the files with those same permissions for ease/lazyness..."touch {1..10} bleep blop bunk cyanide jessie walter meth candy boobies kitties", "chmod 0611 {1..10}; chmod 0700 bleep blop bunk cyanide jessie walter meth candy boobies kitties". No errors so far...now with the final test, and the first thing i posted here did exactly what it should do:

Code:
./9
./boobies
./cyanide
./kitties
./3
./blop
./jessie
./2
./1
./7
./6
./meth
./bunk
./bleep
./8
./4
./walter
./5
./candy
./10

Here's the permissions just to show that it all went according to plan:

Code:
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 1*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 10*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 2*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 3*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 4*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 5*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 6*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 7*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 8*
-rw---x--x 1 xarathustra xarathustra 0 Jul  7 20:48 9*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 bleep*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 blop*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 boobies*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 bunk*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 candy*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 cyanide*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 jessie*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 kitties*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 meth*
-rwx------ 1 xarathustra xarathustra 0 Jul  7 20:48 walter*

I'm thinking that there's something different about the home directory that's causing this.
 
I'm open to inquiry since this is really interesting, there's nothing sensitive in that folder.
 

Staff online

Members online


Top