Skip to main content
posix-ified `find`
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

If you're on a system with the stat command, there's another way to solve the problem:

for f in *
do
  stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done

It's dangerous to rely on the output of ls; consider someone who created a file like this:

touch $'foo\n-rwx some file'

... that will create a separate line in the ls output that (falsely) matches the regular expression. Using a shell glob (*) avoids that issue.

Yet another way is to use find (with maxdepth, if you have it, to match ls's behavior):

find . ! -maxdepthname 1. -prune -perm -700 -ls

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

If you're on a system with the stat command, there's another way to solve the problem:

for f in *
do
  stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done

It's dangerous to rely on the output of ls; consider someone who created a file like this:

touch $'foo\n-rwx some file'

... that will create a separate line in the ls output that (falsely) matches the regular expression. Using a shell glob (*) avoids that issue.

Yet another way is to use find (with maxdepth, if you have it, to match ls's behavior):

find . -maxdepth 1 -perm -700 -ls

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

If you're on a system with the stat command, there's another way to solve the problem:

for f in *
do
  stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done

It's dangerous to rely on the output of ls; consider someone who created a file like this:

touch $'foo\n-rwx some file'

... that will create a separate line in the ls output that (falsely) matches the regular expression. Using a shell glob (*) avoids that issue.

Yet another way is to use find:

find . ! -name . -prune -perm -700 -ls
added 470 characters in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

If you're on a system with the stat command, there's another way to solve the problem:

for f in *
do
  stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done

It's dangerous to rely on the output of ls; consider someone who created a file like this:

touch $'foo\n-rwx some file'

... that will create a separate line in the ls output that (falsely) matches the regular expression. Using a shell glob (*) avoids that issue.

Yet another way is to use find (with maxdepth, if you have it, to match ls's behavior):

find . -maxdepth 1 -perm -700 -ls

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'

If you're on a system with the stat command, there's another way to solve the problem:

for f in *
do
  stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done

It's dangerous to rely on the output of ls; consider someone who created a file like this:

touch $'foo\n-rwx some file'

... that will create a separate line in the ls output that (falsely) matches the regular expression. Using a shell glob (*) avoids that issue.

Yet another way is to use find (with maxdepth, if you have it, to match ls's behavior):

find . -maxdepth 1 -perm -700 -ls
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Your print command needs to come at the end, and you also want to suppress printing by default:

ls -l | sed -n '/^.rwx/p'