In computing, ls is a command to list computer files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell. In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir command. The numerical computing environments MATLAB and GNU Octave include an ls function with similar functionality.
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines the application programming interface (API), along with command line shells and utility interfaces, for software compatibility with variants of Unix and other operating systems.
The Single UNIX Specification (SUS) is the collective name of a family of standards for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group. If an operating system is submitted to The Open Group for certification, and passes conformance tests, then it is deemed to be compliant with a UNIX standard such as UNIX 98 or UNIX 03. Very few BSD and Linux-based operating systems are submitted for compliance with the Single UNIX Specification, although system developers generally aim for compliance with POSIX standards, which form the core of the Single UNIX Specification.
Without options, ls displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
-l
long format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date and filename
-f
do not sort. Useful for directories containing large numbers of files.
-F
appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
-a
lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
-R
recursively lists subdirectories. The command ls -R / would therefore list all files.
-d
shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
-t
sort the list of files by modification time.
-h
print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.) This option is not part of the POSIX standard, although implemented in several systems, e.g., GNU coreutils in 1997, FreeBSD 4.5 in 2002, and Solaris 9 in 2002.
-1 (the numeric digit one)
force output to be one entry per line.
Demo
$ pwd
home/ashish/Desktop/ls_test
$ ls
file1.txt file2.txt ls_test_inner
$ ls -l
total 12
-rw-rw-r-- 1 ashish ashish 2 Mar 28 20:09 file1.txt
-rw-rw-r-- 1 ashish ashish 2 Mar 28 20:09 file2.txt
drwxrwxr-x 2 ashish ashish 4096 Mar 28 20:10 ls_test_inner
$ ls -a
. .. file1.txt file2.txt ls_test_inner
$ ls -r
ls_test_inner file2.txt file1.txt
$ ls -t
ls_test_inner file2.txt file1.txt
$ echo " " > file0.txt
$ ls -r
ls_test_inner file2.txt file1.txt file0.txt
$ ls -t
file0.txt ls_test_inner file2.txt file1.txt
$ ls -R
.:
file0.txt file1.txt file2.txt ls_test_inner
./ls_test_inner:
file3.txt
$ ls -h
file0.txt file1.txt file2.txt ls_test_inner
$ ls -lh
total 16K
-rw-rw-r-- 1 ashish ashish 2 Mar 28 20:31 file0.txt
-rw-rw-r-- 1 ashish ashish 2 Mar 28 20:09 file1.txt
-rw-rw-r-- 1 ashish ashish 2 Mar 28 20:09 file2.txt
drwxrwxr-x 2 ashish ashish 4.0K Mar 28 20:10 ls_test_inner
$ ls -F
file0.txt file1.txt file2.txt ls_test_inner/
$ echo " " > file3.sh
$ ls -F
file0.txt file1.txt file2.txt file3.sh ls_test_inner/
$ chmod 777 file3.sh
$ ls -F
file0.txt file1.txt file2.txt file3.sh* ls_test_inner/
$
So remember: FlarthR (pronounced Flarther)
Sunday, March 28, 2021
ls - command to list computer files in Unix
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment