Its a cold Monday morning and the coffee doesn't seem to have hit the endpoint yet, or maybe it has and gotten a 400-500 HTTP status code response.
As I wait for that to resolve, I find warmth in being bourne again. I am in the bourne again shell, get it?
Bash has always felt a bit intimidating, and just a bit far out of my reach. Always looking mean and something too big to wrap my head around.
Wait, What is Bash?
Bash is a command-line interpreter and shell for Unix-like operating systems (Linux, macOS) that allows users to interact with the OS via text-based commands. It serves as the default interface for executing, automating, and scripting system tasks, acting as a bridge between the user and the kernel.π
But the problem, I think, was me trying to swallow it whole. Fast forward time to a few days ago, a peer introduced me to a game. Oh how I love games!!
This game gets you started on the essentials of bash. I was well versed with the very basic, or rather the ones I'd use on a daily basis: ls, mkdir, touch and a few others, so those ones didn't really raise my 'spidey senses'.
Basics?
So, lets go through what I call 'the very basics':
ls: lists contents of a directory
mkdir name: creates a new directory 'name' in the current directory
touch name: creates a new file 'name' in the current directory
Most of these commands take overloads or parameters or flags which are placed after the command to add more options or coverage to them.
As we have already seen, ls just outputs the contents of a directory, both files and folders, with barely no distinction.
Deep (or shallow) dive into ls
ls -l : This is "long listing". It will give you the contents of the current directory together with more info about each content. You will get an output resembling this:
drwxr-xr-x 2 ksilas cohort2 4096 Feb 17 13:27 algorithm
The first letter d shows that 'algorithm' is a directory. A file would be denoted with a -
The second batch (position 2,3,4) which are rwx represent the permission assigned to the user: r-read, w-write, x-execute
The next 3 in position 5,6,7 are also permissions for the group the user/file is in.
The last 3 are permissions for others. These permissions apply to users who are not owners and are not not in the user group.
The number that follows the permission, 2, represents the number of hard links in the directory.
The next text, ksilas represent the owner of the file, and cohort2 represents the group in which the file belongs to. By default, the group will be the one the owner belongs to.
4096 is the size, in bytes, of the file or directory
Feb 17 13:27 represents the date and time the file/directory was last modified.
algorithm would then finally represent the current items with the above stats.
Still There?
Already overwhelming, right???π Stay with me. I haven't shown you something amazing. We want to find a file with a particular name, and of course the directory.
This is where I shut downπ°.
What is grep, you ask. Well, I actually just went to google that upπ
. Global Regular Expression Print. Basically, it looks for files or text that match the particular pattern given. Say grep "hello" will look for texts that contain 'hello'
But that's not even the problem. What annoyed me was, yes it would list all files that match a pattern, but what I really needed was WHERE the file is. Grep didn't give me that, or at least I didn't know how to ask nicely.
FIND the savior
In walks FIND. I could never ask for moreππ€©.
This is the heart of our discourse today.
Suppose you want to find a FILE with size 100 bytes, and an owner silas, I could imagine your head spinning already.
But for our Swiss Army knife:
**find . -type f -size 100c -user silas**
Let me leave you marvel at the wonders of Bourne Again SHell!! I go away smiling... a happier man.
But before I go, check out the game I mentioned earlier.
Byeππ»
Top comments (0)