How do I list the public files in my home directory? (mode 777)
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?
Solution 1:
From the terminal:
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
First Method: The watch-and-learn way
-
You can then filter with grep to get your desired result:
ls -l | grep -P ".{7}rwx.*"
- the regular expression here tells grep to only select lines where characters 8-10 are
rwx
- the regular expression here tells grep to only select lines where characters 8-10 are
-
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
Second Method: The proper, recursive way
-
In your home directory, type
find . -perm -a+rwx
- You're telling find to look through the current (home) directory and all subdirectories, for files that are
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
- You're telling find to look through the current (home) directory and all subdirectories, for files that are
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.
Solution 2:
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, ando+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.