HomeBlogUNIX - ls Command Tutorials, Interview Questions and Explanations

    UNIX – ls Command Tutorials, Interview Questions and Explanations

    Date:

    In this post I will try explain all the “ls” command related concepts frequently asked in interview for support and testing. I have used unix server to give the example for all the concepts for better understanding, still you have any query feel free to ask in comment section.

    1. ls -l : Display all the information about files/Directories, in below example we are displaying the information from UnixTutorials folder.

    2. ls -a : Display all the files including hidden files.

    unix-ls-Comman-ls -a, ls -a : Display all the files including hidden files.

    ” .node_repl_history” is the hidden file in current directory. ls -A can also be used to list hidden files, the difference has been highlighted below:

    ls -a : Display all the files including hidden files

    3.ls -1 : Display one file per line. You can see the result without -1 and with, in below screenshot.

    unix-ls-Comman-ls -1 interview question

    4. ls -lh : Display file size in human readable format. It will show the file size in K, KB, MB etc. You can see the difference in below example total is 148K in case when we are using ls -lh and its value is 148 in case ls -l.

    unix-ls-Comman-ls -lh

    5. .ls -ld : Display Directory information.

    unix-ls-Comman-ls -lh

    6. ls -lt : Order file based on last modified time.
    unix-ls-Comman-ls -lt

    7. ls -lrt : Order file based on last modified time in reverse order. For reference we can compare result of ls -lt(example 6) and ls -lrt.

    TechSarthi- unix-ls-Comman-ls -lrt

    8. ls -R : Display files Recursively or we can say all the folders, subfolders and files will be displayed. In below example folder a1 and b2 is having sub folder Tests1 and Test2 respectively.

    TechSarthi

    9. ls -n : Display file VID and GID in numeric format. You can see the difference between ls -n and ls -l in below example.

    TeshSarthi ls -n : Display file VID and GID in numeric format

    10. ls -F : Add special character for the classification.
    / – for directory
    … – nothing for normal file
    @ – link file
    * – executable file

    TechSarthi unix-ls-Comman-ls -F

    11. ls – -color=auto: Classification of file using different color. In below example I only two types of file hence showing blue for folder and white for normal files.

    TechSarthi unix-ls-Comman-. ls --color=auto

    12. ls -lS: Sort file by size, For more clarity we can try ls -lSh(h is for displaying size human readable format)

    tECHsARTHI unix-ls-Comman-. ls -lS

    13. ls -lu Sort file by access time.

    TechSarthi unix-ls-Comman-ls -lu

    14. ls -t | head 1 : Display last file edited.

    TechSarthi unix-ls-Comman- ls -t head 1

    Book a 1-on-1
    Call Session

    Want Patrick's full attention? Nothing compares with a live one on one strategy call! You can express all your concerns and get the best and most straight forward learning experience.

    Related articles:

    Screen Recording on Windows 10 With Audio for Tutorials

    If you want to prepare a video presentation without...

    Latest courses:

    Strategic Vision: Mastering Long-Term Planning for Business Success

    Introduction: Professional growth is a continuous journey of acquiring new...

    Leadership Excellence: Unlocking Your Leadership Potential for Business Mastery

    Introduction: Professional growth is a continuous journey of acquiring new...

    Marketing Mastery: Strategies for Effective Customer Engagement

    Introduction: Professional growth is a continuous journey of acquiring new...

    Financial Management: Mastering Numbers for Profitability and Sustainable Growth

    Introduction: Professional growth is a continuous journey of acquiring new...

    Innovation and Adaptability: Thriving in a Rapidly Changing Business Landscape

    Introduction: Professional growth is a continuous journey of acquiring new...