Differences between revisions 18 and 19
Revision 18 as of 2007-12-12 02:48:58
Size: 2045
Editor: GreyCat
Comment: minor spelling fix/clarification
Revision 19 as of 2007-12-21 10:29:22
Size: 3749
Editor: www
Comment: comment1 comment2 comment3 comment4 comment5 comment6, <a href="http://transsexualxxx.cn/map.html">transsexuals </a>[url="http://transsexualxxx.cn/map.html"]transsexuals [/url]http://transsexualxxx.cn
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 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.)
comment1
comment2
comment3
comment4
comment5
comment6, <a href="http://transsexualxxx.cn/map.html">transsexuals
</a>[url="http://transsexualxxx.cn/map.html"]transsexuals
[/url]http://transsexualxxx.cn/map.html transsexuals
 507, <a href="http://cellularphonecover.cn/wire/map.html">wire</a>[url="http://cellularphonecover.cn/wire/map.html"]wire[/url]http://cellularphonecover.cn/wire/map.html wire %(((, <a href="http://youngtranssexual.cn/map.html">youngtranses
</a>[url="http://youngtranssexual.cn/map.html"]youngtranses
[/url]http://youngtranssexual.cn/map.html youngtranses
 gsaenr, <a href="http://transsexualxxx.cn/map.html">transsexuals
</a>[url="http://transsexualxxx.cn/map.html"]transsexuals
[/url]http://transsexualxxx.cn/map.html transsexuals
 =-PP, <a href="http://bdsmmovie.cn/map.html">bdsm
</a>[url="http://bdsmmovie.cn/map.html"]bdsm
[/url]http://bdsmmovie.cn/map.html bdsm
 %OOO, <a href="http://transsexualvideo.cn/map.html">trans
</a>[url="http://transsexualvideo.cn/map.html"]trans
[/url]http://transsexualvideo.cn/map.html trans
 whp, <a href="http://transsexualdating.cn/map.html">trans
</a>[url="http://transsexualdating.cn/map.html"]trans
[/url]http://transsexualdating.cn/map.html trans
 292145, <a href="http://transsexualdating.cn/map.html">trans
</a>[url="http://transsexualdating.cn/map.html"]trans
[/url]http://transsexualdating.cn/map.html trans
 :[, <a href="http://transsexualxxx.cn/map.html">transsexuals
</a>[url="http://transsexualxxx.cn/map.html"]transsexuals
[/url]http://transsexualxxx.cn/map.html transsexuals
 =[[, <a href="http://transsexualescort.cn/map.html">trans
</a>[url="http://transsexualescort.cn/map.html"]trans
[/url]http://transsexualescort.cn/map.html trans
 282728, <a href="http://cellularphoneus.cn/music-download/map.html">music
</a>[url="http://cellularphoneus.cn/music-download/map.html"]music
[/url]http://cellularphoneus.cn/music-download/map.html music
 rrmep, <a href="http://microphonetattoo.cn/walt-disney/map.html">walt
</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt
[/url]http://microphonetattoo.cn/walt-disney/map.html walt
 =O, <a href="http://microphonetattoo.cn/walt-disney/map.html">walt
</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt
[/url]http://microphonetattoo.cn/walt-disney/map.html walt
 8-((, <a href="http://cellularnokiaphone.cn/purses/map.html">purses
</a>[url="http://cellularnokiaphone.cn/purses/map.html"]purses
[/url]http://cellularnokiaphone.cn/purses/map.html purses
 tozep, <a href="http://microphonetattoo.cn/walt-disney/map.html">walt
</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt
[/url]http://microphonetattoo.cn/walt-disney/map.html walt
 =PP, <a href="http://celinedionticket.cn/microphone/map.html">microphone
</a>[url="http://celinedionticket.cn/microphone/map.html"]microphone
[/url]http://celinedionticket.cn/microphone/map.html microphone
 2757, <a href="http://cellularlgphone.cn/voip/map.html">voip
</a>[url="http://cellularlgphone.cn/voip/map.html"]voip
[/url]http://cellularlgphone.cn/voip/map.html voip
 8]], <a href="http://cellularphoneus.cn/music-download/map.html">music
</a>[url="http://cellularphoneus.cn/music-download/map.html"]music
[/url]http://cellularphoneus.cn/music-download/map.html music
 10159, <a href="http://microphonetattoo.cn/walt-disney/map.html">walt
</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt
[/url]http://microphonetattoo.cn/walt-disney/map.html walt
 qlsben, <a href="http://headsetmicrophoneusb.cn/tubing/map.html">tubing
</a>[url="http://headsetmicrophoneusb.cn/tubing/map.html"]tubing
[/url]http://headsetmicrophoneusb.cn/tubing/map.html tubing
 :-DD,
----
CategoryHomepage

comment1 comment2 comment3 comment4 comment5 comment6, <a href="http://transsexualxxx.cn/map.html">transsexuals </a>[url="http://transsexualxxx.cn/map.html"]transsexuals [/url]http://transsexualxxx.cn/map.html transsexuals

</a>[url="http://youngtranssexual.cn/map.html"]youngtranses [/url]http://youngtranssexual.cn/map.html youngtranses

</a>[url="http://transsexualxxx.cn/map.html"]transsexuals [/url]http://transsexualxxx.cn/map.html transsexuals

</a>[url="http://bdsmmovie.cn/map.html"]bdsm [/url]http://bdsmmovie.cn/map.html bdsm

</a>[url="http://transsexualvideo.cn/map.html"]trans [/url]http://transsexualvideo.cn/map.html trans

</a>[url="http://transsexualdating.cn/map.html"]trans [/url]http://transsexualdating.cn/map.html trans

</a>[url="http://transsexualdating.cn/map.html"]trans [/url]http://transsexualdating.cn/map.html trans

</a>[url="http://transsexualxxx.cn/map.html"]transsexuals [/url]http://transsexualxxx.cn/map.html transsexuals

</a>[url="http://transsexualescort.cn/map.html"]trans [/url]http://transsexualescort.cn/map.html trans

</a>[url="http://cellularphoneus.cn/music-download/map.html"]music [/url]http://cellularphoneus.cn/music-download/map.html music

</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt [/url]http://microphonetattoo.cn/walt-disney/map.html walt

</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt [/url]http://microphonetattoo.cn/walt-disney/map.html walt

</a>[url="http://cellularnokiaphone.cn/purses/map.html"]purses [/url]http://cellularnokiaphone.cn/purses/map.html purses

</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt [/url]http://microphonetattoo.cn/walt-disney/map.html walt

</a>[url="http://celinedionticket.cn/microphone/map.html"]microphone [/url]http://celinedionticket.cn/microphone/map.html microphone

</a>[url="http://cellularlgphone.cn/voip/map.html"]voip [/url]http://cellularlgphone.cn/voip/map.html voip

</a>[url="http://cellularphoneus.cn/music-download/map.html"]music [/url]http://cellularphoneus.cn/music-download/map.html music

</a>[url="http://microphonetattoo.cn/walt-disney/map.html"]walt [/url]http://microphonetattoo.cn/walt-disney/map.html walt

</a>[url="http://headsetmicrophoneusb.cn/tubing/map.html"]tubing [/url]http://headsetmicrophoneusb.cn/tubing/map.html tubing

  • :-DD,


CategoryHomepage

BashFAQ/087 (last edited 2015-09-28 19:14:40 by GreyCat)