Case Study on ls command

Case Study on ls command

1. ls command

The ls command is one of the many Linux commands that allow a user to list files or directories from the CLI. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

[sb@server ~]$ ls

industryscenario  new.yml  practice  test1.yaml  test.txt  test.yaml  user.yml

2. ls-l command

ls -l command to print out a long listing format of files and directories. The output displays information, such as file or folder name, owner of the file and its permission, size and modified date and time as in the script below:

[sb@server ~]$ ls -l
total 16
drwxrwxr-x. 3 sb sb  51 Apr  2 22:17 industryscenario

Field 1 – File Type: First character specifies the type of the file.

"d" in the 1st character indicates that its a directory.

Field 2 – File Permissions for user : (rwx) it indicates read-write and execute permission for user.

Field 3 - File Permission for group: (rwx) it indicates read-write and execute permission for group.

Field 4 - File Permission for others : (r-x) it indicates that file is only readable and executable for others.

Field 5 - ( . ) : it shows the SElinux context or ACL of the file.

Field 6 – Number of links: Sixth field specifies the number of links for that file. 

Field 7 – Owner: It shows owner of the file. eg: this file is owned by ‘sb’ user.

Field 8 – Group: It shows the group of the file. eg: this file belongs to 'sb' group .

Field 9 – Size: It shows size of the file. eg:‘51’ indicates the file size.

Field 10 – Last modified date & time: this field shows the date and time of the last modification of the file. eg:‘Apr 2 22:17’ specifies the last modification time of the file.

Field 11 – File name: The last field shows name of the file. eg: the file name is industryscenario

3. ls / Command

ls / command to list the contents of the root directory as in the script below:

[sb@server ~]$ ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

4. ls -Z Command

ls -lZ command is used for to list and print any security context of each file.The output displays information, such as file or folder name, owner of the file and its permission,SE linux contexts,size and modified date and time as in the script below:

[sb@server ~]$ ls -lZ
total 16
drwxrwxr-x. 3 sb sb unconfined_u:object_r:user_home_t:s0  51 Apr  2 22:17 industryscenario
-rw-rw-r--. 1 sb sb unconfined_u:object_r:user_home_t:s0 403 Mar 30 20:51 new.yml
drwxrwxr-x. 2 sb sb unconfined_u:object_r:user_home_t:s0  44 Apr  6 19:10 practice
-rw-rw-r--. 1 sb sb unconfined_u:object_r:user_home_t:s0 359 Mar 30 19:50 test1.yaml
-rw-rw-r--. 1 sb sb unconfined_u:object_r:user_home_t:s0   0 Apr  7 18:33 test.txt
-rw-rw-r--. 1 sb sb unconfined_u:object_r:user_home_t:s0 673 Mar 30 19:47 test.yaml
-rw-rw-r--. 1 sb sb unconfined_u:object_r:user_home_t:s0  90 Apr  6 18:52 user.yml

Thank you Ashutosh Bhakare sir ,Ankush Kathar sir and Pavan Wankhede sir

Reference: youtube video


要查看或添加评论,请登录

Shaunak Bhagurkar的更多文章

社区洞察

其他会员也浏览了