Sorting and Listing Files, Directory in Linux - Basic commands



    In this article we will be seeing how to sort Files and Directory in a Linux system. We will be doing with a single command ls and with different flags.

    The  ls  command with no flag lists the files and directory on the current working directory. With  alone the directory will end with /.



Listing the files and directories in Ascending order:

    The default command itself list the files and directory in an ascending order,









Listing hidden files:

    Some files maybe hidden in a directory. These files are started with a period. To list such files we gonna use a flag  -a  along with ls. ( ll  command do the same thing).





    To list the hidden files with their properties,





Listing files with properties:

    To view the files permission with modified date we can use the flag  -l . This will list the files with file mode, User and group, File-size (in bytes), Modified time, Filename.





Listing the last accessed file first:

    The flag with  -t  sorts the last accessed files.





To list the last accessed file with the accessed time use  -lt  flag.

Listing the file size:

    To list the file and directory with its size use  -sh ( -s  alone do the trick but it list the size in bytes. For human understanding we can use  -h  along with that).





Listing the files in reverse order:

    We can use flag  -r  to list the files in reverse order.





Finding the number of files in a directory:

    To find the number of files in a directory we can use word count command  wc .





Listing particular files:

    For listing particular file either by its file type or name we can use the  grep  command. We will see more about grep on upcoming article.









Hope this article helps you. Feel free to ask if you have any questions.

Comments

Popular Posts on this blog

Apache Webserver - Installation from source (tar.gz and tar.bz2)

Setting up a Mail server using Roundcube - Part-1 - Centos 7

How to Install LAMP Stack on Linux - Centos 7

Installing Docker-Compose on Ubuntu

Apache Tomcat Installation - Ubuntu - 17.04

Setting up a Mail server using Roundcube - Part-3 - Centos 7

Blog Top Sites

Blog Log