DEV Community

Cover image for a barely capable shell user
Michael Tharrington
Michael Tharrington Subscriber

Posted on • Updated on

a barely capable shell user

I started up my coding journey a little more than two weeks ago:

But, admittedly those baby steps into Python have yet to materialize into much. I suppose I'm more crawling than walking yet.

But hey, crawling at least implies I'm doing something, and I am!

I began reading Learn Python the Hard Way, which I've chosen as my first real coding resource, and at the recommendation of the author:

warning

...I spent the last couple of weeks familiarizing myself with Terminal via the book's Appendix A: Command Line Crash Course.

And, guess what?

🥁🥁🥁...

I can now say that I'm officially "a barely capable shell user."

🎉🎉🎉

how I got here

Avoiding the urge to plow ahead, I listened to the author and wrote out a stack of note cards with commands & their corresponding definitions. While I didn't understand every definition at the time, I quizzed myself on them until I could name them forward and backward.

picture of notecards


terminal terminology... xargs is flipped wrong-side up there! 😛

After I had my note cards down, I followed each lesson as closely as I could, typing in each individual command, double checking my inputs & outputs, and trying to figure out the quirks of the system. I paid close attention to those lessons and did my best to grasp what each command was doing before moving on to new material.

I'm actually willing to bet that in Exercise 6: List Directory (ls) there's a small typo by way of a missed output:

grape?

... I believe the word "grape" should be listed there.🍇

Haha, I don't mean to be one of those folks.😛 But still, something I'm learning is that the devil is in the details.😈

Mistyping a command means it doesn't work... or worse, it does something you don't want it to. Not knowing a command means you gotta look it up, and that slows you down. Taking the time to learn things "the hard way" (i.e. using focus and memorization) really does pay off.

Having said that, I don't mean to make the terminal sound so cryptic. In fact, that's another thing... now that I've typed a few commands in, the terminal really doesn't seem so scary or difficult anymore.

what I think the terminal is all about

The terminal offers a text-based way of controlling things on your computer which you might typically control through the UI.

For instance, I can create folders mkdir, change between them cd, see what's inside them ls, view files inside them less, and so forth. There have been a few relatively more advanced things I've done – pushd & popd – but I've not created any real logic yet, just found ways to dance in and out of folders without lifting my hands from the keyboard. Admittedly, I'm not very graceful yet – I've typed pwd & ls more than you can imagine – but hey, I'm learning.

Perhaps in time the terminal will become more to me, but this is all I'm seeing it as for the moment.

a few fun things I've done in the terminal

One of the first fun logic finds I stumbled upon was when I copied a folder called "test" into itself using the command copy -r test test. Here's what happened:

infinite test folders

So basically, the folder copied inside itself infinitely. Best thing about that was this is kinda of what I'd hoped what would happen. 😎 I had to go check it out!

infinite test 2

And while this didn't really have any use to me, it was amusing.

infinite mirrors

Another thing I enjoyed toying with was less. As soon as I realized I could preview a text file in the terminal, I was off to get me some ASCII art. And voilà!

yoda

Yep, definitely nerding out a bit...

One other cool thing I did at the suggestion of a fellow DEV-er was to calculate which commands I used the most.

Good luck!

I think that this post would be very helpful because it gives what commands other devs use the most:

dev.to/abhinav/which-is-the-most-u...

Good suggestion, Valentin! This was definitely a great post for checking out what commands real devs use the most. Plus, the command needed to calculate my own most used commands is right there in the post.

So, what commands have I been bashing in the most?

my most used commands

As I said, I've been leaning pretty heavily on ls & pwd right now. Maybe in the future I'll be a little less paranoid about where I am in the terminal, but right now I'll keep those two close by, haha.

Something else this last command revealed to me is that you can type formulas into the terminal... interesting.

slow and steady

I've been moving at a relatively slow pace here, but I do think I made the right decision to hang back and learn a little bit of bash first. After all, I hear slow and steady pays off.🐢🐢

Now that I've got a bit of terminal terminology under my belt, I feel confident that it's time to move on to some actual coding. Python, here we come!🐍🐍

Top comments (14)

Collapse
 
kenbellows profile image
Ken Bellows • Edited

Awesome stuff, I love reading about people's early journeys into the world of the terminal 😎

You should definitely learn about your ~/.bashrc file if you haven't yet, it's a special file that gets run each time you open the terminal and it lets you set up a bunch of environment stuff to make your life easier, things like short aliases for common long commands and, importantly, environment variables.

And speaking of environment variables, the real reason I'm writing is that you can customize what your prompt (the Michaels-MacBook-Pro:~ dev$ bit) looks like using a variable called PS1. Google around and you'll quickly find more examples that you could want, but the biggest thing is that you can set it up to always print your entire path, or your path relative to your home directory, so you always know where you are without having to type pwd ever again!

A very simple, no-frills PS1 that will accomplish this is:

PS1='\u@\h:\w \$ '
Enter fullscreen mode Exit fullscreen mode

Try typing that into your terminal, and you should start to see this prompt (assuming your username is michael and your pwd is ~/code/dev):

michael@Michaels-MacBook-Pro:~/code/dev $
Enter fullscreen mode Exit fullscreen mode

If you like what it gives you, edit (or create) ~/.bashrc and paste it at the bottom. Then it will work in all future shell sessions, and you can say goodbye to pwd!

Here's a good overview of what the variables up there mean, and all the other ones you can use in your PS1: ss64.com/bash/syntax-prompt.html

Collapse
 
michaeltharrington profile image
Michael Tharrington

WOW! This is all amazing!! You just made my night, thanks so much. 😃

Collapse
 
kenbellows profile image
Ken Bellows • Edited

Btw, forgot to say this in the above comment: full paths can get pretty long, so what a lot of people (myself included) like to do is add a line break \n right before the $ to drop it onto a new line:

PS1='\u@\h:\w\n\$ '

michael@Michaels-MacBook-Pro:~/code/projects/some-repo-with-a-really-long-name
$ echo "Commands fit here no problem!"
Enter fullscreen mode Exit fullscreen mode

And if you want a little splash of color, there's a bunch of color codes in the link in my last comment, but to start off, I like to make my user@hostname part a different color from my path, maybe light blue for the former and yellow for the latter. And always remember to reset your color to the default with \e[0m at the end, unless you want all the text you type to be colored as well, if that's your thing.

PS1='\e[0;36m\u@\h \e[0;33m\w\n\e[0m\$ '
Enter fullscreen mode Exit fullscreen mode

your shell

Give that a try and see what you think!

Collapse
 
gavinfernandes2012 profile image
Gavin Fernandes

Thats great work with the terminal!
When I started out with C++ I was already a bit familiar with it since I used Ubuntu at the time, and we have command line package managers (instead of the app store). That being said, I still don't know some of the commands in your picture there 😂, but I do know quite a few languages (although I'm still learning).

Collapse
 
michaeltharrington profile image
Michael Tharrington

Thanks for the kind words, Gavin! And, I've actually been thinking about installing Ubuntu on my Lenovo - kinda wanna see what's outside the Mac/Windows box. I've yet to explore...

Collapse
 
gavinfernandes2012 profile image
Gavin Fernandes

Ohh I challenge you to a standard Arch Linux install. That's probably the quickest way to learn quite a bit about the command line and Linux at the same time. (We even have command line web browsers if you need to refer to the arch wiki, yeah that's a thing)

If you're really feeling daring, try Gentoo. Although your hair'll probably grow white before Chrome compiles 😂

Collapse
 
goyo profile image
Grzegorz Ziemonski

Congrats on getting over the terminal fear! Now your family and friends will think you're a super-hacker even if all you do is cd around and cat stuff.

Btw. I tried to cp -r test test and it gives me cp: cannot copy a directory, 'test', into itself, 'test/test' :(

Collapse
 
michaeltharrington profile image
Michael Tharrington

Hmmm... that is weird! I actually had to recreate this issue by memory because I kinda forgot how I did it the first time. Anyway, initially when I tried to recreate it I just went to type in cp test test and go the message:

cp: test is a directory (not copied).

But then I remembered to involve the -r and the infinite folder situation played out as expected. In fact, I just tested it again to make sure I'm not going crazy.

Could it be because I'm working with Terminal on Mac? Or possibly that I have no extra frills installed.

I'm on version 2.9.1:

my terminal version

Collapse
 
rpalo profile image
Ryan Palo

Nice! It's cool to see your journey and observations. If you want more examples, exercises, and introductions for the command line, Small, Sharp Software Tools by @bphogan.

is a really great resource to work through. Takes things slow, but explains things with real-world examples that make the lessons stick. :)

Collapse
 
michaeltharrington profile image
Michael Tharrington

Appreciate the kind words and thanks for sharing the resource! I'll definitely take a look!

Collapse
 
jacksonelfers profile image
Jackson Elfers

Nice work. I think most people learn commands on a need to know basis. If you can navigate the filesystem you're set to do whatever.

Collapse
 
michaeltharrington profile image
Michael Tharrington

Thanks! Good stuff! I feel pretty confident with these basic commands now and can get around pretty well. Glad to know the rest is really more of a need to know basis.

Collapse
 
jess profile image
Jess Lee

Awesome, Michael! I definitely had the same set of notecards a few years ago :)

Collapse
 
michaeltharrington profile image
Michael Tharrington

But were yours hand cut from loose leaf notebook paper? Haha, appreciate the encouragement! 😀