I want to get the list of all the files in my home folder, having rwx
(read-write-execute) or 777 permissions for everyone.
Also, what is the command to know the permissions of a file?
I want to get the list of all the files in my home folder, having rwx
(read-write-execute) or 777 permissions for everyone.
Also, what is the command to know the permissions of a file?
The terminal opens up in your home directory by default. From anywhere else, type cd ~
to return to the home directory.
ls -l
will show you the file permissions at the beginning, e.g.
-rwxr-xr-x 1 izx izx 11217428 Oct 2 2011 wkhtmltoimage-amd64
You can then filter with grep to get your desired result:
ls -l | grep -P ".{7}rwx.*"
rwx
which in my home directory shows:
-rwxrwxrwx 1 izx izx 0 Jun 15 23:42 sd.png -rwxrwxrwx 1 izx izx 0 Jun 15 23:42 slashdot.png drwxrwxrwx 3 izx izx 4096 Jun 15 21:31 src
In your home directory, type find . -perm -a+rwx
rwx
by all; the results will be displayed with full relative paths, e.g../.mozilla/firefox/lr5z24b3.default/lock ./src ./src/accountsservice-0.6.15/src/libaccountsservice/.libs/libaccountsservice.so ./src/accountsservice-0.6.15/src/libaccountsservice/.libs/libaccountsservice.la ./src/accountsservice-0.6.15/src/libaccountsservice/.libs/libaccountsservice.so.0 ./src/accountsservice-0.6.15/debian/libaccountsservice-dev/usr/lib/libaccountsservice.so ./src/accountsservice-0.6.15/debian/libaccountsservice0/usr/lib/libaccountsservice.so.0 ./src/accountsservice-0.6.15/debian/tmp/usr/lib/libaccountsservice.so ./src/accountsservice-0.6.15/debian/tmp/usr/lib/libaccountsservice.so.0 ./.pulse/676238f89edd1f57138b3da400000004-runtime ./sd.png ./slashdot.png ./XnView/lib/libQtGui.so.4 ./XnView/lib/libQtWebKit.so.4 ./XnView/lib/libQtXml.so.4 ./XnView/lib/libQtDBus.so.4 ./XnView/lib/libQtNetwork.so.4 ./XnView/lib/libQtCore.so.4 ./XnView/lib/libQtSvg.so.4
The bold entries in the home directory also showed up in the first method.
For more ways on using find
to accomplish what you want, please refer to Eliah Kagan's answer just above or below this one.
Usually you would use the ls
command to find out about files' permissions. But for a specific task, where you want to list files automatically that have certain permissions, using ls
, even if you filter the output with another utility like grep
, will quickly become very complex to do correctly. So for such tasks, you are better off using find
.
If you want to list all files that are...
contained anywhere within your home directory (including in subdirectories of your home directory, subdirectories of those subdirectories, and so forth), and
that are also explicitly readable, writable, and executable by everyone
...then this command will do that for you:
find ~ -perm 777
It's really that simple.
If you only want to list files that meet the above two conditions and reside directly within the home directory (not inside any subdirectory), use this command instead:
find ~ -maxdepth 1 -perm 777
In this case, 777
will indicate files that are readable, writable, and executable for you, your group, and everyone else. If some of the files might have strange permission sets, such 477 (you can read the file, and everyone else can execute and write the file), you probably want to use:
find ~ -maxdepth 1 -perm -o+rwx
The leading hyphen before -o+rwx
means the file can have other permissions, and o+rwx
means that others (outside the group and user who own that file) can read, write, and execute this file, without checking any other permissions.
See man find
for details about how to perform these and similar operations, and man chmod
for the meaning of 777
and other numeric modes.
Change to that directory where you want to know the permissions of file by the command:
cd "Directory"
Replace the text in quotes with the directory name that you need.
Then enter another command:
ls -l
This command (ls
) is usually used to get the file names. The -l
argument to that will give complete information about the files.
So you will also be able to see the file permissions.
R
flag to thels
command. When piped togrep
, it would then be unclear where each of the files was located within the home directory (i.e., in what subpath). Do you know of a way to get around this problem, with anls
-using method? The other problem with this is that files that are setuid, setgid, or sticky will haves
ort
as one of the mode flags and not be matched by thegrep
command. – Eliah Kagan Jun 16 '12 at 09:25