Your answer lies in the first output you provided:
$ stat /home/jzhu/other
File: `/home/jzhu/other' -> `/root/other/'
This shows that /home/jzhu/other
is a symlink to /root/other
.
So basically to access anything in /home/jzhu/other/
you are going to need access to /root/other
. This means that your user must have execute permissions on both /root
and /root/other
.
Next lets go on to this command:
$ stat /home/jzhu/other/
stat: cannot stat `/home/jzhu/other/': Permission denied
The reason why this fails and the one above works is because of the trailing /
. On any command which works with a path, if the final component of that path (eg: other
) is a symlink, and the path ends with a trailing /
, then any system calls to operate on that path will try to dereference the symlink, and operate on what the symlink points to instead of the symlink itself.
Solutions:
There are 2 possible solutions to this.
1. Change permissions on /root/other
:
As mentioned, add execute capability to both /root
and /root/other
. You can do this with basic or extended filesystem attributes.
You can add the jzhu
user to the root
group (usermod -a -G root jzhu
) and add group execute to the path (chmod g+x /root; chmod g+x /root/other
).
This isn't an ideal solution as it grants your access to anything restricted to the root
group.
Use filesystem ACLs.
setfacl -m u:jzhu:x /root
setfacl -R -m u:jzhu:x /root/other
setfacl -d -R -m u:jzhu:x /root/other
This makes it so that your specific user gets execute access to /root/other
and anything inside it.
It's still not ideal as if these resources are shared, they shouldn't be in root's home directory.
Note that in both these solutions we only grant the execute (x
) bit. The execute bit is needed on a directory for a user to access anything inside that directory. However you also need the read (r
) bit to be able to list (ls
) the directory. Meaning that without the read bit, you'll have to know exactly where in /root/other
the files are. If you want to allow read, just change the x
in the last 2 setfacl
commands to rx
(for example, -m u:jzhu:rx
).
2. Move the resources outside /root/other
.
This is the preferred solution. You can either get rid of the symlink at /home/jzhu/other
and create a directory in it's place, or put them in a shared location somewhere else on the system (without knowing what it is, I can't recommend a good location though).
The reason this is the preferred solution is that if these resources are shared among users, then they don't belong to a specific user and shouldn't be in that user's home directory.
You can also use file test operators:
[[ -e ./last_dump.sql ]] && mysql -D my_database < ./last_dump.sql
See here for more info about these operators: File test operators
But if you prefer to use stat
you can divert its output to /dev/null
:
stat ./last_dump.sql >/dev/null && mysql -D my_database < ./last_dump.sql
Notice ./
in the commands above which means current directory.
Also I should note that if you want to make stat completely silent (even in case of errors) divert errors to /dev/null
as well using &>/dev/null
or >/dev/null 2>&1
(have same result).
Best Answer
tells you how big each block is on the file system. On most file systems, this is the smallest amount of space any file can take up. Each file uses a multiple of this.
For example,
I'm not 100% sure it always works like this. For example, I expect it could also decide to print
512
or1024
, even if the underlying block size is different, providedstat -c %b FILE
*stat -f -c %S FILE
=du --block-size=1 FILE
. The exact implementation would depend on the file system.suggests how many bytes you should read at a time if you're copying large files, for example what you should use as the
bs
(blocksize) parameter when usingdd
. But on the systems I checked, it always prints4096
, even where larger values might be faster. See Is there a way to determine the optimal value for the bs parameter to dd? for more discussion of that.Technically, this information (and all the information from
stat -f
) comes from thestatvfs
system call.%s
corresponds to thef_bsize
field, and%S
isf_frsize
.So you could look into their precise meanings starting with the statvfs man page