The ls
command has several options that can be used together to show more information.
Details/Rights
The l
option shows the file permissions, size, and last modified date. So if the root directory contained a dir called test
and a file someFile
the command:
user@linux-computer:~$ ls -l
Would output something like
-rw-r--r-- 1 user users 70 Jul 22 13:36 someFile.txt
drwxrwxrwx 2 user users 4096 Jul 21 07:18 test
The permissions are in format of drwxrwxrwx
. The first character represents the file type d
if it's a directory -
otherwise. The next three rwx
are the permissions the user has over the file, the next three are the permissions the group has over the file, and the last three are the permissions everyone else has over the file.
The r
of rwx
stands for if a file can be read, the w
represents if the file can be modified, and the x
stands for if the file can be executed. If any permission isn't granted a -
will be in place of r
, w
, or x
.
So from above user
can read and modify someFile.txt
but the group has only read-only rights.
To change rights you can use the chmod ### fileName
command if you have sudo rights. r
is represented by a value of 4, w
is represented by 2, and x
is represented by a 1.
So if only you want to be able to modify the contents to the test
directory
Owner rwx = 4+2+1 = 7
Group r-x = 4+0+1 = 5
Other r-x = 4+0+1 = 5
So the whole command is
chmod 755 test
Now doing a ls -l
would show something like
drwxr-xr-x 2 user users 4096 Jul 21 07:20 test
Readable Size
Used in conjunction with the l
option the h
option shows file sizes that are human readable. Running
user@linux-computer:~$ ls -lh
Would output:
total 4166
-rw-r--r-- 1 user users 70 Jul 22 13:36 someFile.txt
drwxrwxrwx 2 user users 4.0K Jul 21 07:18 test
Hidden
To view hidden files use the a
option. For example
user@linux-computer:~$ ls -a
Might list
.profile
someFile.txt
test
Total Directory Size
To view the size of the current directory use the s
option (the h
option can also be used to make the size more readable).
user@linux-computer:~$ ls -s
Outputs
total 4166
someFile.txt test
Recursive View
Lets say test
directory had a file anotherFile
and you wanted to see it from the root folder, you could use the R
option which would list the recursive tree.
user@linux-computer:~$ ls -R
Outputs
.:
someFile.txt test
./test:
anotherFile