/ft_ls-hive

In this project I recoded a light version of the command “ls”.

Primary LanguageC

Intro

The ls command is one of the first commands everyone has to learn in order to use shell. It is also probably the most used command of every programmer. To Recode ls and some of its options allowed me to find out how to interact with the file system using C. I used my own created printf, that I created in a different Hive project to make ft_ls a pleasant project experience.

It's a smaller version of ls, flags that are currently working -> -GRalrt
-a (Include directory entries whose names begin with a dot (.))
-l (List in long format.If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.)
-r (Reverse the order of the sort to get reverse lexicographical order or the oldest entries first.)
-t (Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.)
-R (Recursively list subdirectories encountered.)
-G (Enable colorized output)

How to install

1. `git clone` the repo
2. complie the executable wiht `make`
3. `./ft_ls` is ready to use with the flags shown in the usage bellow

usage: ft_ls [-GRalrt] [file ...]

I used the merge sort (for linked list) algorithm for this project.
MergeSort(headRef)

  1. If the head is NULL or there is only one element in the Linked List then return.
  2. Else divide the linked list into two halves.
    FrontBackSplit(head, &a, &b); /* a and b are two halves */
  3. Sort the two halves a and b. MergeSort(a); MergeSort(b);
  4. Merge the sorted a and b (using SortedMerge() discussed here) and update the head pointer using headRef. *headRef = SortedMerge(a, b);

Sources:

https://codeforwin.org/2018/03/c-program-to-list-all-files-in-a-directory-recursively.html
https://stackoverflow.com/questions/3554120/open-directory-using-c
https://stackoverflow.com/questions/8436841/how-to-recursively-list-directories-in-c-on-linux
https://www.geeksforgeeks.org/merge-sort-for-linked-list/
https://stackoverflow.com/questions/2589533/what-is-a-cursor-linked-list-c

Videos: Linux File Types