7
1
If the current path is /data/db_1
, and /data
has three subpath, db_1, db_2, db_3
.
I want to know db_1
’s modification, owner and group.
Currently I use ls -li /data |grep db_1
, but I think there must better way to do it?
7
1
If the current path is /data/db_1
, and /data
has three subpath, db_1, db_2, db_3
.
I want to know db_1
’s modification, owner and group.
Currently I use ls -li /data |grep db_1
, but I think there must better way to do it?
8
To see the permissions of the current directory, whatever it is, use:
ls -lid .
How it works:
-l
asks ls
for a long directory listing.
-i
asks ls
for inode information (optional).
-d
tells ls
to report on the directory itself, not what is in it.
.
refers, as is conventional for Unix, to the current directory.
Because POSIX ls
supports the -l
, -i
, and -d
options, this method is portable.
7
Don't use ls
at all. It is generally a bad idea to try and parse ls
output and there are other tools that are specifically designed for the job. In this case, you can use stat
:
$ stat -c '%G %U %y' .
terdon terdon 2015-03-03 19:37:48.007033824 +0200
-c --format=FORMAT
use the specified FORMAT instead of the default; output a new‐
line after each use of FORMAT
%G group name of owner
%U user name of owner
%y time of last modification, human-readable
So, the command above will print the user (%U
), group (%G
) and modification time (%y
) of .
, the current directory. It can also print other pieces of information, pretty much anything you will ever need. See man stat
for more.
1Who says he's trying to parse the output, I think he just wants to view it. – Barmar – 2015-03-06T23:50:38.157
@Barmar ls -li /data |grep db_1
is parsing the output of ls
. What if you have a file or directory called foo\ndb_1
? Or db1 and db2
? Anyway, stat
is specifically designed for this and is the better tool for the job. – terdon – 2015-03-09T12:21:41.980
Why not just
ls -lid /data/db_1
if you know the name? – Barmar – 2015-03-09T14:31:29.470