Skip to content
/ ft_ls Public

As simple as listing the files in a directory.

Notifications You must be signed in to change notification settings

bricewge/ft_ls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_ls

Obligatory part [/]

flag -l

(The lowercase letter ``ell''.)  List in long format.  (See below.)
If the output is to a terminal, a total sum for all the file sizes is
output on a line before the long listing.

flag -R

Recursively list subdirectories encountered.

flag -a

Include directory entries whose names begin with a dot (.).

flag -r

Reverse the order of the sort to get reverse lexicographical order or
the oldest entries first (or largest files last, if combined with sort
by size

flag -t

Sort by time modified (most recently modified first) before sorting
the operands by lexicographical order.

Bonus part

flag -G, colors

Enable colorized output.  This option is equivalent to defining
CLICOLOR in the environment.  (See below.)

ACLs

flag -u

 Use time of last access, instead of last modification of the file for
sorting (-t) or long printing (-l).

flag -f

Output is not sorted.  This option turns on the -a option.

flag -g

This option is only available for compatibility with POSIX; it is used
to display the group name in the long (-l) format output (the owner
name is suppressed).

flag -d

Directories are listed as plain files (not searched recursively).

optimize speed for ls - lR

Roadmap

Recursivly list subdirs

Sort dir contents [0/6]

  • [ ] lexicographicly
  • [ ] lexicographicly reversed
  • [ ] modified time
  • [ ] modified time reversed
  • [ ] access time
  • [ ] access time reversed

Rewrite libc functions

scandir

qsort

2017-04-02

display files

  1. Parse options
  2. Sort arguments
  3. List files arguments
    • display
    • replace the argument by NULL
  4. List directory arguments

Fix moulitest errors

07-(02,05,06) sort by mtime

08-06 mtime in 10 000

touch -t 999912312459 future ls -lt

22

13

21 01,02

mkdir a ln -s a b rm -rf a

Read man

opendir / readdir / closedir

stat / lstat

getpwuid / getgrgid

time / ctime

readlink

perror / strerror

ls

mini sub-projects

list the contents of a directory

EÉcrire un programme qui utilise les fonctions opendir, readdir et closedir pour ouvrir un répertoire et lister les noms de ce qu’il contient sur la console.
$>mkdir -p toto/tyty
$>touch toto/{tata,titi,tutu}
$>./ft_list_dir toto
tata
titi
tutu
tyty
$>

get informations on a file

ÉEcrire un programme qui prend un fichier en paramètre et utilise, entre autres, la fonction stat pour obtenir des informations sur ce fichier et les afficher à l’écran.
$>./ft_inspect_file un_fichier_de_ouf
Nom: un_fichier_de_ouf
Type: Fichier
Modes: rwxr-xr-x
Nombre de liens: 1
Proprietaire: zaz
Groupe: staff
Taille: 2142 octets
Date de derniere modification: Sep 17 23:42
$>

Vous allez devoir utiliser plusieurs fonctions, données en début de ce document, afin d’interpréter les informations renvoyées par stat.

Notes

order of display based on type

  1. Errors
  2. Non directories
  3. Directories
$ ls test/ Makefile INVALID ana
ls: INVALID: No such file or directory
ls: ana: No such file or directory
Makefile

test/:
chmod000	dir		error.sh	getopt.sh	list_dir	symlink_dir

order of doing things

  1. Test options
  2. Order operands based on their type
  3. Print the result

Ressources

About

As simple as listing the files in a directory.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published