• About PinoyLinux
    • PinoyLinux.org
    • Documentation
    • Support
    • Feedback
Skip to content
PinoyLinux
Menu
  • HOME
  • EBOOKS
  • TOPICS+
    • Artificial Intelligence
    • Containers
    • Desktop
    • DevOps
    • Linux Kernel
    • Mobile
    • Network Administration
    • Programing
    • Privacy and Security
    • Servers
    • Storage
    • System Adminstration
Menu

The very powerful ‘ls’ command

Posted on April 15, 2016

An ls (pronouced as el es) utility appeared in the original version of AT&T UNIX. Today, two popular versions of ls are the Free Software Foundation’s (part of the GNU coreutils package) and the one released by various BSD variants, such as FreeBSD, OpenBSD, NetBSD, and Apple Computer’s Darwin. Both are free software and open source.

The ls command is one of the most used and important command that we as linux user and linux/unix administrator can’t live without. It is the basic utility that a beginner must learn and one of the commands that a Unix/Linux administrator should not forget. In this article, we will explore on how we can use the ls more efficiently and take advantage about its power.

1. Opening the last file edited.

To open the last edited file in the current directory use the combination of ls, head and vi commands as shown below. ls -t sorts the file by modification time, showing the last edited file first. head -1 picks up this first file.

$ nano `ls -t | head -1`

Be aware with the tick `, because it is important to make the command work.

2. Display one file per line.

To display files and directories per line, use -1.

$ ls -1
Applications
Desktop
Documents
Downloads
xincoClientConfig.dat
3. Display all information To display a list of information about the file/directory, use -l.
$ ls -l
drwxr-xr-x 2 johndoe staff 68 Feb 18 2011 Applications
drwx——+ 30 johndoe  staff 1020 Feb 17 16:21 Desktop
drwx——+ 126 johndoe  staff 4284 Feb 17 15:01 Documents
drwx——+ 63 johndoe  staff 2142 Feb 19 22:25 Downloads
-rw-r–r– 1 johndoe staff 20960 Jun 6 2011 xincoClientConfig.dat
1st Character – File Type: First character specifies the type of the file. A hyphen (-) in the 1st character indicates that this is a normal file while a letter d means it is a directory.
– normal file
d directory
s socket file
l link file
Column 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and world.
Column 2 – Number of links: Second field specifies the number of links for that file. In this example, 2 indicates only two link to this directory.
Column 3 – Owner: Third field specifies owner of the file. In this example, this files and directory is owned by username ‘johndoe’.
Column 4 – Group: Fourth field specifies the group of the file. In the example above, this file belongs to ‘staff’ group.
Column 5 – Size: Fifth field specifies the size of file. In the example above, ’64’,’1020′, ‘4284’, ‘2142’, ‘936’ indicates the directory and file size respectively.
Column 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file.
Column 7 – File name: The last field is the name of the file.
4. Display file size in a human readable format. User ls -lh (h stands for human readable form), to display file siez in easy to read format (M for MB, K for KB, G for GB).
$ ls -l
-rw-r–r– 1 johndoe staff 20960 Jun 6 2011 xincoClientConfig.dat
$ ls -lh
-rw-r–r– 1 johndoe staff 20K Jun 6 2011 xincoClientConfig.dat
5. Display Directory Information When you use “ls -l” you will get the details of directories content. But if you want the details of directory then you can use -d option.

Author Profile

lordfrancs3
lordfrancs3
Lordfrancis3 is a member of PinoyLinux since its establishment in 2011. With a wealth of experience spanning numerous years, he possesses a profound understanding of managing and deploying intricate infrastructure. His contributions have undoubtedly played a pivotal role in shaping the community's growth and success. His expertise and dedication reflect in every aspect of the journey, as PinoyLinux continues to champion the ideals of Linux and open-source technology. LordFrancis3's extensive experience remains an invaluable asset, and his commitment inspires fellow members to reach new heights. His enduring dedication to PinoyLinux's evolution is truly commendable.
Latest entries
  • nginx+redis-ratelimit-queueSoftware and TechnologySeptember 18, 2023Nginx Reverse Proxy with Redis for Rate Limiting and Queues for Performance Optimization
  • Automating tasks for efficiencySystem AdminstrationAugust 27, 2023Automating Yourself Out of Your Job
  • ecurity-alert-privilege-escalation-vulnerability-impacts-charitable-vulnPrivacy and SecurityAugust 22, 2023Security Alert: Privilege Escalation Vulnerability Impacts Over 10,000 Charitable WordPress Sites
  • centos deepServersAugust 14, 2023Why Red Hat Abandoned CentOS 7 and the Best Alternatives

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Breaking News

  • New 'Mirrored' Network Mode Introduced in Windows Subsystem for Linux
  • Linux Threat Report: Earth Lusca Deploys Novel SprySOCKS Backdoor in Attacks on Government Entities
  • Linux Kernel Faces Reduction in Long-Term Support Due to Maintenance Challenges
  • Linux Celebrates 32 Years with the Release of 6.6-rc2 Version
  • Introducing Bavarder: A User-Friendly Linux Desktop App for Quick ChatGPT Interaction

Site Stats

  • 6
  • 11
  • 45
  • 226
  • 19,405
©2023 PinoyLinux | All Rights Reserved
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}