Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

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
  • 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
    
  • 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.

share|improve this answer
    
Presumably the OP wants to know about such files everywhere contained within the home directory, rather than just those directly inside it, which can be facilitated by adding the R flag to the ls command. When piped to grep, 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 an ls-using method? The other problem with this is that files that are setuid, setgid, or sticky will have s or t as one of the mode flags and not be matched by the grep command. –  Eliah Kagan Jun 16 '12 at 9:25
    
Furthermore, please note that there is an exception to the mantra that files in your home directory should not be world-everything. Symbolic links will always appear world-everything. –  Eliah Kagan Jun 16 '12 at 9:37
add comment
  • Open up the terminal.
  • 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.

share|improve this answer
add comment

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...

  1. contained anywhere within your home directory (including in subdirectories of your home directory, subdirectories of those subdirectories, and so forth), and

  2. 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.