1887
Comment: ow can I get the permissions of a file without parsing ls -l output?
|
3569
<a href="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en">My Note</a> [URL="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en"]My No
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
[[Anchor(faq87)]] == How can I get the permissions of a file without parsing ls -l output? == There are several potential ways, most of which are system-specific. They also depend on precisely ''why'' you want the permissions. The majority of the cases where you might ask this question -- such as ''I want to find any files with the setuid bit set'' -- can be answered by the information in [:UsingFind#permissions:]. As the page name implies, those answers are based on the `find(1)` command. For some questions, such as ''I want to make sure this file has 0644 permissions'', you don't actually need to ''check'' what the permissions are. You can just use `chmod 0644 myfile` and set them directly. If your needs aren't met by any of those, then we can look at a few alternatives: * On GNU/Linux systems, and possibly others, there is a command called `stat(1)`. On older GNU/Linux systems, this command take no options -- just a filename -- and you will have to parse its output. {{{$ stat / File: "/" Size: 1024 Filetype: Directory Mode: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Device: 8,0 Inode: 2 Links: 25 Access: Wed Oct 17 14:58:02 2007(00000.00:00:01) Modify: Wed Feb 28 15:42:14 2007(00230.22:15:49) Change: Wed Feb 28 15:42:14 2007(00230.22:15:49)}}} In this case, one could extract the 0755 from the `Mode:` line, using `awk` or similar commands. * On newer GNU/Linux systems, the `stat` command takes arguments which allow you to specify which information you want: {{{$ stat -c %a / 755}}} That's obviously a lot easier to parse. * On systems with perl 5, you can use: {{{ perl -e 'printf "%o\n", 07777 & (stat $ARGV[0])[2]' "$filename"}}} This returns the same octal string that the `stat -c %a` example does, but is far more portable. (And slower.) |
<a href="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en">My Note</a> [URL="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en"]My Note[/URL] [URL="http://www.xanga.com/cannabin"]My Blog[/URL] <a href="http://www.xanga.com/cannabin">My Blog</a>, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html">lipitor and zocor studies</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html"]lipitor and zocor studies[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html lipitor and zocor studies 8-]], <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html">fosamax lipitor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html"]fosamax lipitor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html fosamax lipitor =O, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html">order zocor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html"]order zocor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html order zocor wcm, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html">difference between lipitor and zocor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html"]difference between lipitor and zocor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html difference between lipitor and zocor hagw, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html">genic plavix</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html"]genic plavix[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html genic plavix 8-))), <a href="http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html">young men using viagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html"]young men using viagra[/url]http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html young men using viagra jleu, <a href="http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html">recreational viagra use</a>[url="http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html"]recreational viagra use[/url]http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html recreational viagra use 619, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html">viagra free shipping</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html"]viagra free shipping[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html viagra free shipping 785643, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html">viagra pfizer patent</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html"]viagra pfizer patent[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html viagra pfizer patent indlm, <a href="http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html">similar to viagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html"]similar to viagra[/url]http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html similar to viagra 220704, ---- CategoryCategory |
<a href="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en">My Note</a> [URL="http://www.google.com/notebook/public/14143202924783996150/BDQ7EQwoQhrfWuNwi?hl=en"]My Note[/URL] [URL="http://www.xanga.com/cannabin"]My Blog[/URL] <a href="http://www.xanga.com/cannabin">My Blog</a>, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html">lipitor and zocor studies</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html"]lipitor and zocor studies[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-and-zocor-studies.html lipitor and zocor studies 8-]], <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html">fosamax lipitor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html"]fosamax lipitor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/fosamax-lipitor.html fosamax lipitor =O, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html">order zocor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html"]order zocor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/order-zocor.html order zocor wcm, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html">difference between lipitor and zocor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html"]difference between lipitor and zocor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/difference-between-lipitor-and-zocor.html difference between lipitor and zocor hagw, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html">genic plavix</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html"]genic plavix[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/genic-plavix.html genic plavix 8-))), <a href="http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html">young men using viagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html"]young men using viagra[/url]http://www.ibm.com/links?cannabin.info/viagra/young-men-using-viagra.html young men using viagra jleu, <a href="http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html">recreational viagra use</a>[url="http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html"]recreational viagra use[/url]http://www.ibm.com/links?cannabin.info/viagra/recreational-viagra-use.html recreational viagra use 619, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html">viagra free shipping</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html"]viagra free shipping[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-free-shipping.html viagra free shipping 785643, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html">viagra pfizer patent</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html"]viagra pfizer patent[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-pfizer-patent.html viagra pfizer patent indlm, <a href="http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html">similar to viagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html"]similar to viagra[/url]http://www.ibm.com/links?cannabin.info/viagra/similar-to-viagra.html similar to viagra 220704,