Quantcast
Viewing all articles
Browse latest Browse all 4909

Beginners • Re: I found a new command whereis

Maybe it is time for me to make a my own commend like findmw (short for find my work in the home partition)
That's what I would do, is what I did, though it ended up more advanced than you probably need.

You could start as simple as this -

Code:

#!/usr/bin/env python3import osimport sysuser = os.environ["USER"]print("Scanning /home/" + user)for path, dirs, files in os.walk("/home/" + user):  for file in files:    for match in sys.argv[1:]:      if file.lower().find(match.lower()) >= 0:        print(path + "/" + file)        break
Then optimise for speed and tailor to your own requirements. Hint: creating a list of files in a text file and searching that is faster than walking the tree every time.

Code:

pi@Pi4B:~/apps/ff $ ./findmw.py gcc-14Scanning /home/pi/home/pi/apps/riscv-for-aarch64/bin/riscv32-unknown-elf-gcc-14.2.1/home/pi/apps/riscv/riscv-gnu-toolchain/gcc-14/.git/logs/refs/heads/releases/gcc-14/home/pi/apps/riscv/riscv-gnu-toolchain/gcc-14/.git/refs/heads/releases/gcc-14/home/pi/apps/riscv/bin/riscv32-corev-elf-gcc-14.1.0pi@Pi4B:~/apps/ff $

Statistics: Posted by hippy — Mon Sep 16, 2024 8:18 pm



Viewing all articles
Browse latest Browse all 4909

Trending Articles