The atypical โ€œlsโ€ or how linuxoids are entertained

Once in a telegram chat of the Petersburg Linux community SPbLUG I threw a funny puzzle:

List the files in your home directory with as many methods as possible, without using ls or its aliases (1 method - 1 point)


The same task flew into another chat a bit later, and here is what came of it:

1. echo and print



for i in ~/* ~/.* ; do echo $i ; done
      
      





Exactly the same thing will be returned by replacing the echo command with print.

In fact, you can do without a cycle, it will turn out not so beautifully, but it fits the condition of the task.



 echo ~/* ~/.*
      
      





2. tree



A more obvious way is to use tree, which is practically ls if you pick the right keys.



 tree -aiL 1 ~
      
      





3. find



Also a more than obvious solution.



 find ~ -maxdepth 1 -mindepth 1
      
      





4. du



Yes, people didnโ€™t forget about du.



 du -ad 1 ~
      
      





5. tar



We turn to water procedures with subtle perversions.



 tar -cvf /dev/null --no-recursion ~/* ~/.* 2>null
      
      





6. 7. Perl and Python



Since in the condition of the problem I forgot to put a restriction on the interpreters, which in modern Linux usually are out of the box in the system, the cooks and serpent farmers could not stay away:

Perl:



 perl -e 'use feature "say"; opendir my $dh, "." or die "Could not open . for reading: $!\n"; while (my $thing = readdir $dh) { say $thing; };'
      
      





Python:



 echo -e "import os\nfor i in os.listdir(os.getenv('HOME')): print(i)" | python
      
      





Out of competition



They even gave out the source code for C to the mountain, but even though the compiler is present almost everywhere, except for any emmbedded distributions, I considered this a completely complete mess. ;-)



 #include <stdio.h> #include <stdlib.h> #include <dirent.h> #define HOME getenv("HOME") int main(int argc, char const *argv[]) { struct dirent *dp; DIR *dir = opendir(HOME); while ((dp = readdir(dir)) != NULL) printf("%s\n", dp->d_name); closedir(dir); return 0; }
      
      





PS



Probably, somewhere in coreutils / findutils, the participants of the amusement missed something. There were unsuccessful attempts to use less / more, but maybe the Habrovsk people also got ideas on the non-standard use of standard utilities.



Upd. one



Thanks habr! Comments, this is just some kind of holiday! And based on their motives, I am preparing a new post. Stay in touch!



Upd. 2



As I promised, the second part of the Marlezon Ballet .



All Articles