3470
Comment: <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
|
2599
finfo
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
<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-muscle-pain.html">lipitor muscle pain</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-muscle-pain.html"]lipitor muscle pain[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/lipitor-muscle-pain.html lipitor muscle pain 498, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/polio-post-zocor.html">polio post zocor</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/polio-post-zocor.html"]polio post zocor[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/polio-post-zocor.html polio post zocor =-DD, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/buy-norvasc-online.html">buy norvasc online</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/buy-norvasc-online.html"]buy norvasc online[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/buy-norvasc-online.html buy norvasc online %-], <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/zocor-qoclick-shop.html">zocor qoclick shop</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/zocor-qoclick-shop.html"]zocor qoclick shop[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/zocor-qoclick-shop.html zocor qoclick shop 37130, <a href="http://www.ibm.com/links?cannabin.info/blood-pressure/wisconsin-genic-plavix-drug.html">wisconsin genic plavix drug</a>[url="http://www.ibm.com/links?cannabin.info/blood-pressure/wisconsin-genic-plavix-drug.html"]wisconsin genic plavix drug[/url]http://www.ibm.com/links?cannabin.info/blood-pressure/wisconsin-genic-plavix-drug.html wisconsin genic plavix drug 136856, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-logo.html">viagra logo</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-logo.html"]viagra logo[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-logo.html viagra logo xwasw, <a href="http://www.ibm.com/links?cannabin.info/viagra/generig-viagra.html">generig viagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/generig-viagra.html"]generig viagra[/url]http://www.ibm.com/links?cannabin.info/viagra/generig-viagra.html generig viagra lzqetl, <a href="http://www.ibm.com/links?cannabin.info/viagra/oral-viagra-kamagra.html">oral viagra kamagra</a>[url="http://www.ibm.com/links?cannabin.info/viagra/oral-viagra-kamagra.html"]oral viagra kamagra[/url]http://www.ibm.com/links?cannabin.info/viagra/oral-viagra-kamagra.html oral viagra kamagra :OOO, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-and-1994-pct-patent.html">viagra and 1994 pct patent</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-and-1994-pct-patent.html"]viagra and 1994 pct patent[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-and-1994-pct-patent.html viagra and 1994 pct patent qdjof, <a href="http://www.ibm.com/links?cannabin.info/viagra/viagra-home-page.html">viagra home page</a>[url="http://www.ibm.com/links?cannabin.info/viagra/viagra-home-page.html"]viagra home page[/url]http://www.ibm.com/links?cannabin.info/viagra/viagra-home-page.html viagra home page :-)), ---- CategoryCategory |
<<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 you want to see if you can read, write or execute a file, there is test -r, -x and -w. If your needs aren't met by any of those, then we can look at a few alternatives: * On GNU/Linux systems, *BSD 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 and FreeBSD 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. (NetBSD and OpenBSD use `-f` instead of `-c`.) * 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.) * If your bash is compiled with [[BashLoadable|loadable builtin support]], you can build the `finfo` builtin (type `make` in the `examples/loadables/` subdirectory of your bash source tree), `enable` it, and then use: {{{ $ finfo -o .bashrc 644 }}} Beware that the `finfo.c` distributed with bash up through 4.0 contains at least one bug (in the `-s` option), so the code has clearly not been tested much. Most precompiled bash packages do not include compiled examples, so this may be a difficult alternative for most users. |
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 you want to see if you can read, write or execute a file, there is test -r, -x and -w.
If your needs aren't met by any of those, then we can look at a few alternatives:
On GNU/Linux systems, *BSD 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 and FreeBSD 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. (NetBSD and OpenBSD use -f instead of -c.)
- 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.)
If your bash is compiled with loadable builtin support, you can build the finfo builtin (type make in the examples/loadables/ subdirectory of your bash source tree), enable it, and then use:
$ finfo -o .bashrc 644
Beware that the finfo.c distributed with bash up through 4.0 contains at least one bug (in the -s option), so the code has clearly not been tested much. Most precompiled bash packages do not include compiled examples, so this may be a difficult alternative for most users.