The ls command is undoubtedly one of the most used. It basically serves to list files and directory content.
Your most common options are:
-C Show by columns
Examples:
$ ls -m /boot/ *138* /boot/config-4.14.138-114.102.amzn2.x86_64, /boot/initramfs-4.14.138-114.102.amzn2.x86_64.img, /boot/symvers-4.14.138-114.102.amzn2.x86_64.gz, /boot/System.Map-4.14.138-114.102.amzn2.x86_64.gz, /boot/System.Map-4.14.138-114.102.amzn2.x86_64.gz, /boot/System.Map-4.14.138-114.102.amzn2.x86_64.gz, /boot/System.Map-4.14.138-114.102.amzn2.x86_64.gz, /boot/System.Map-4.14.138-amzn2.x86_64, /boot/vmlinuz-4.14.138-114.102.amzn2.x86_64
$ ls -Sl ~/ -rw-rw-r-- 1 ec2-user ec2-user 221427 Dec 7 2018 mysqltuner.pl -rw-rw-r-- 1 ec2-user ec2-user 35487 May 21 2017 vfsync-2017-05-21.tar.gz
On Linux, files that start with “.” are hidden and are only shown with the -a option of ls. The file “.” is a pointer to the current directory. The file “..” is a pointer to the directory above (or earlier) All directories contain the files “.” and “..” |
File and directory names are case-sensitive
The following ls options are very useful for programmers:
Use the “-lt” option to show the files in order of modification:
$ ls -lt
-rw-r--r-- 1 ec2-user root 16172 May 6 22:19 List.php -rw-r--r-- 1 ec2-user root
6279 jan 20 13:47 SubForm.php -rw-r--r-- 1 ec2-user root
21195 jan 20 13:30 CapForm.php -rw-r--r-- 1 ec2-user root 16050 jan 20 13:30 CapList.php -rw-r--r-- 1 ec2-user root 16050 jan 20 13:30 -rw-r--r-- 1 ec2-user root 16050 jan 20 13:30
-rw-r--r-- 1 ec2-user root 16050 jan 20 13:30
-rw-r--r-- 1 ec2-user root 16050 jan 20 13:30 -rw-r--r-- root 7937 jan 20 13:30 Form.php
-rw-r–r– 1 ec2-user root 12598 jan 20 13:30 List.php
The “-lS” option is useful for showing files in order of size:
$ ls -lS
-rw-r--r-- 1 ec2-user root 21195 jan 20 13:30 CapForm.php -rw-r--r-- 1 ec2-user root
16172 May 6 22:19 List.php -rw-r--r-- 1 ec2-user root
16050 Jan 20 13:30 CapList.php -rw-r--r-- 1 ec2-user root 12598 jan 20 13:30 List.php -rw-r--r-- 1 ec2-user root 12598 jan 20 13:30 -rw-r--r-- 1 ec2-user root 12598 jan 20 13:30
-rw-r--r-- 1 ec2-user root 12598 jan 20 13:30 -rw-r--r-- 1 ec2-user root 12598 jan 20 13:30
-rw-r--r-- 1 ec2-user root 12598 jan 20 13:30 -rw-r--r-- 1 ec 7937 Jan 20 13:30 Form.php
-rw-r–r– 1 ec2-user root 6279 jan 20 13:47 SubForm.php
The following command is also useful for making an inventory of the files. In this case, the file names are sent to the text editor Vi:
$ ls -XR | vim -
Another text editor can be used, such as nano:
$ ls -XR | nano -
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Share
The sudo command on Linux executes a given command as if it were another user.…
The ss command on Linux is extremely useful for investigating sockets, providing various information about…
Free Linux command shows the amount of total memory in use and available, as well…
The shell has structures for testing conditions and executing certain program sequences several times (loop),…
The /etc/fstab file stores the configuration of which devices should be mounted and what is…
The Netcat Command in Linux or nc is a utility used to do “almost anything”…
This website uses cookies.