Get in touch with your deepest darkest file.

  1. First open up a brand new terminal window.
  2. Navigate to your home directory. The easiest way to do this is to type cd and then press enter.
  3. Now you can enter the following commands one at a time:

mkdir computer-spirit-guide

this command creates a new folder in your home folder called computer-spirit-guide. this is where all of the new files created throughout this journey will go. do not cd into it just yet...

find . -iname "*.txt" -print 2>&1 | grep -v "Permission denied" | sed -e 's/^/./' -e 's/ /\\ /g' > ./computer-spirit-guide/files.txt

this command searches your entire system and finds any files with the extension of txt. if you want to get in touch with a different kind of file you can replace .txt with .pdf or any other kind of file. the find command is equivalent use the spotlight search (⌘ CMD + Space) in the GUI. the command makes sure to ignore the files that return with "permission denied".

finally it places one extra period before the file path. this ensures that the path is absolute rather than relative. once it has all of the file paths for each file the command copies all of them into to a new file called files.txt

if you are a programmer it might take a while...

cd computer-spirit-guide

cd stands for change directory. after running this command your terminal will execute all future commands INSIDE of the computer-spirit-guide directory

sed -e 's;[^/]*/; 📁;g;s; |; 📁;g' ./files.txt > file-tree.txt

sed is a magical command that makes it easy to edit and replace text. this command finds all of the forward slashes and spaces in the files.txt and replaces it with the folder emoji.

once everything is replaced it copies each of the the new paths with the folder emojis into file-tree.txt

touch spirit-guide.sh

touch your spirit guide. this command creates a new file called spirit-guide.sh

.sh stands for shell, we want to use a shell script because we will be writing executable commands inside so that we can eventually just make one call to this file and it will run everything inside of it.

now you can open this file spirit-guide.sh in a code editor

you can find the file in your home folder or type open spirit-guide.sh on the command line

now paste the following code into the file:

#!/bin/bash

while read f; do
echo -n "$f "
done <./file-tree.txt

maxPath=0
deepestDarkestPath=0
while read path; do
countPath=$(echo ${path} | grep -o '/' | wc -l)
if (( $countPath > $maxPath )); then
maxPath=$countPath;
deepestDarkestPath=$path;
fi;
done <./files.txt

cat $deepestDarkestPath > ./deepest-file.txt

open ./deepest-file.txt

this code creates two new variables. one called maxPath and one called deepestDarkestFile. the deepestDarkestFile will be equal to the file that has the most folders before it in its path. the maxPath variable will be equal to the amount of folders in the deepest file's path.

while read is a bash command that reads each line of a given text file. in this case the file being read is file-tree.txt.

finally we use cat to copy the deepestDarkestPath into a file called deepest-file.txt and open this

chmod u+x spirit-guide.sh

this command gives your computer permission to execute the commands of the file

./spirit-guide.sh

:-)

Computer Spirit Guide - Get in touch wi…
···