Command Line Tuesdays
Command Line Tuesdays
The Introductory
Hi Geekos!
Today weâre introducing a new series, called âCommand Line Tuesdaysâ. Why command line Tuesdays? Because in this series, everyday computer enthusiasts like yours truly, will try to step a little out of bounds of the Graphical User Interface (GUI) Culture, which is today synonymous to âmaking stuff easier for the massesâ.
Of course, if you visited any of the GNU/Linux related community forums, youâve probably read, and this is an assumption, a very fiery debate over which is actually easier. Using GUI for everything, or simply learning and enjoying the Command-line Interface (CLI).
There are many arguments for or against the use of GUI tools. One of the most commonly referred pros is that weâve been brought up in the point-and-click computing paradigm, so itâs basically a form of a language, or culture if you may, in which we interact with our machine. The patterns are mostly recurring, with big button clicking doing everything we need it to do.
On the other side, one of the most interesting comments Iâve read about the pros of command-line was: you can simply do more via the command-line much quicker, easier and faster than when using GUI tools. But thereâs a catch: you have to learn the commands. Yes, learn them, as if learning a poem. Now, since to us, the semi-indoctrinated clueless users, it all sounds like some useless geek overreaching and overdoing, let me humanize it with a fable:
The Fable
Iâve been using Linux for more then 3 years now. Iâm a 27 year old literature major, who never held much of an interest in technology of any sort. I didnât even own a computer until I was in high-school, so letâs say somewhere around 17. Thatâs barely ten years of computer usage. The only three programs I ever ran were BS Player, Winamp and Football Manager, with occasional usage of MS Word. Three and bit years ago, a colleague at a precarious job I was performing at the time was talking to another coworker, saying thereâs a new edition of something which immediately occupied my attention, as it looked different. It was Ubuntuâs Natty Narwhal, I think. After discussing it with him, he pointed out the usual pros we gospel to the newcomers, no antivirus necessary, faster boot, better security, software center blah blah blah, and the peak of it: Free and Open Source (FOSS) philosophy behind it. And he did it in a very non-invasive, non fanboyish manner.
I decided to give it a go, and I never turned back since then. How I got into openSUSE around the 11.4 release, shortly after trying out Ubuntu for the first time is going to have to fit in another time, and how I find it to be the perfect sweet spot is a whole different story. The point is, I finally entered the Linux realm. It was fun, it was different, it made my computer run better, it was more stable. I barely had issues with it (seems I not-knowingly purchased fairly orthodox hardware). It seems that Linux came really far regarding the desktop, so I barely had to use the terminal. But letâs just say it was one of the most dreadful, terrifying and horrific tools to use in Linux. If there wasnât a GUI for a specific operation, I immediately became nervous as I didnât know what I was getting into when copy/pasting commands from the forums. After time, things changed. As opposed to other consumer-oriented systems, what happened to me was maybe somewhat of a human reverse-engineering. Instead of me consuming the system, I feel that in three years, the system consumed me. I learned how to search for basic issues, file bug reports, properly ask questions on forums. With every issue I had, I learned how to be better at providing the information needed for someone more competent to help me with my problem.
A short while ago, my girlfriend commented how she canât believe Iâm using my computer mostly for the sake of using the computer, rather than doing anything else. âYou use it only for your music collection and Linux thingies, Nenad. Gaawd.â It made me think, and think hard. Linux, specifically the openSUSE distro has become a hobby of mine. Not at an expert level, by any means, which is reasonable since it isnât my area of expertise. But I know enough to get around, fix minor issues, play around with some configuration files etc. But what I came to know, is that with my increasing playing and tinkering around the system, I really need to get familiar with CLI. I learned that Iâm playing around without knowing of the basics under the hood. What for crying out loud is ETC?!?!? Whatâs BIN? Why is there .sh at the end? Why is this file here, and this file there? Why do I have to click through gazillion of folders to find the right file to modify? Then I read you can easily list all the files somewhere with a single command. It became interesting. I suddenly felt an urge to try it out.
So Letâs Do It!
âŚand here we are. As a new openSUSE news contributor, Iâll try to contribute in a way I see productive for what I suppose is a large portion of the community. Itâs time to plant the banner and start learning the command-line together. If philosophy is what attracted you to Linux and openSUSE, like me, it got you this far. Now itâs time to take a step further. Pinky And The Brain Look, I know thereâs a bunch of you like me out there. I know you maybe donât see the point in all that 90â˛s geeky black-screen-green-letters-quick-typing-make-everything-go-boom thing. But itâs useful in many aspects. Weâll learn in a fun and communal way which directories are for what, what files are located where, most commonly used terminal commands. It will make our lives easier when we learn to perform tasks through the console, make it even more rewarding when we run into issues. It will also make the lives of bug-squashers easier when they receive proper information from our end, and it will make our hobby infinitely more fun. I mean, for crying out loud, youâve already made a transition to a phase where Dilbert and xkcd are actually funny. Itâs time for the terminal!
P.S.:
Reference material that will be used: William Shotts â The Linux Command Line and a short tutorial on most commonly used commands by a Croatian hacker Velimir Baksa aka Lutherus. Requirements on your part: - An hour or two of spare time weekly â A pint of cold beer or any other beverage â Someone already pointed out that using Gedit, or a manual notepad (you know, pen and paper hehe) would be good for easier learning.
The book by Mr Shotts is exquisite. But thereâs probably an issue of time/will-power etc. This way, Iâll try to humanize the lessons a bit more, take some time off your hands, and whatâs most important â I count on us learning together, helping each other together (Comments and Forums, people!!) and tying a close-knit openSUSE community! This time next week (it will be June already!), weâll learn our first commands. And rememberâŚ
âŚhave a lot of fun!
Part One
Here we are geekos, back in action! Sorry itâs been a while, but let me just assure you weâre back on track, raging to meet the deadlines and to, well, have some fun :)
Now, the whole idea was pretty much completely summed up in the introductory text posted a fortnight ago, so we may get down to business. As the book by Mr. Shotts instructs, we need to know what a shell is, as weâll be operating withing it, and what a terminal emulator is.
A shell, Mr Shotts states, is actually what weâre talking about when weâre talking about command-line. The shell is basically a program that passes the strokes of your keyboard to your computer, a translator of some sort, so your computer knows what youâre saying. There are many shells in existence, but the most widespread shell used in GNU/Linux distributions is called bash, or Bourne Again Shell. Itâs a clever wordplay, as Mr Bourne created the bashâs predecessor, sh, and Brian Fox wrote it as a free alternative for sh. Ahhh, GNU people and their humor, very clever :)
Next thing we need so we can interact with the shell is a terminal emulator. Every Linux distribution comes with one, depending on the desktop environment you use, so it should be Konsole from KDE, Gnome terminal in Gnome etc. Mr. Shotts says you probably develop a preference for one, but I use what the desktop environment provides me, most of the time.
Now, fire up your terminal. You get a line, stating your user name and the machineâs host name. This is called the shell prompt. It means itâs ready for you to enter a command. Letâs try something random. Type in anything, and press enter.
Hehe, remember the introductory saying we need to learn the commands as a poem? There we go, random doesnât work.
Now, press the up arrow, and youâll see the command reappear. Whatâs this sorcery? The up arrow key on your keyboard is for accessing the command history. The terminal saves up to 500 commands you entered, so to not type them over and over, you can look for them with the up/down arrow. The left and right arrows are for moving the cursor within a specific line, so you can edit the text in between. Now thereâs another thing â ctrl+v for pasting text doesnât work. You can set it up as a shortcut somewhere, but itâs usually something else. Check your terminal emulatorâs shortcuts! (in Konsole, itâs Settings > Configure shortcuts)
Now, for us not to get the âcommand not foundâ slap to the face, letâs try something simple. Type date. (Yes, I didnât know thereâs a command for this, so itâs exciting for me also) :)
There you go. Why bother looking at your built in calendar in the clock, when you can fire up your terminal and type date, and see what day it is :) Just kidding, as Mr Shotts states, itâs a simple command, the more useful/difficult ones are coming next time. The related command to date is cal â it will display the current monthâs calendar.
You may also try df, and it will list free space on your drives.
Or free, to display the amount of free memory:
If youâre already in the type-only mood, you can enter the command exit to get out of the terminal emulator instead of pressing the x button.
âŚand weâll stop to a halt for this week so it wonât be too much to ingest on your already tight schedule. To sum it up (you can write this conclusion down, for repetition), in part one, we learned:
what is a shell what do we need to communicate with the shell (terminal emulator) navigating the terminal commands with cursor buttons and exiting the terminal
Four simple commands:
date â displays the current date cal â displays the current monthâs calendar df â shows the amount of free space on your hard drives free â amount of free memory
What will we do next Tuesday?
We will learn navigation through the file system (what are all those bin etc etc. folders, what are they used for, how to navigate through them via the terminal). Until then⌠âŚhave a lot of fun!
Part Two
Heya geekos!
Letâs refresh our memories. Last week, we skimmed through some basic commands, learned what a shell is actually, and made a steady introduction into our CLI Tuesdays series.
Todayâs menu offers something else: navigation through the file system.
Now, the best picture I managed to find on the www is from a site called devopsbootcamp. You can find their tutorials and the rest here. But anyway, hereâs a very nice diagram of what a linux root filesystem looks like.
For example, as stated in the above picture, your user directory (where you usually store your movies, music, documents etc.) is located in the /home folder. /home folder is located under /. Then you have the /etc folder, where most of the files for configuration are located. Anyway, you can find the detailed description here, as weâll not be getting into which folder is for what, until we start using and configuring them. Today is reserved for navigation only. And on that note, letâs get down to the first command of the dayâŚ
pwd
pwd, or âprint working directoryâ is a very useful command if you think you are lost navigating through the folders. At any given moment, type pwd, and voila! What appears is a complete pathway you took to arrive to this folder. Those guys in The Cube could sure use it, losers.
Imagine yourselves walking from room to room inside a massive apartment, loosing your way. pwd is like the breadcrumb trail leading you to your starting point, so you donât loose your way inside the folder maze! cd
Now you know in which directory youâre situated thanks to your usage of the pwd command. Now you want to take the next step and move to another directory. Letâs say you have a folder/directory inside your home folder you want to relocate your top secret terminal operation to. For this, you use the âcdâ command. cd, or âchange directoryâ, will change the location of wanted directory. How do you use it? Simple, type cd and the path to your folder. Letâs say, for example, you want to enter your Hello Kitty picture collection in your home folder. You type âcd /home/username/Hello\ Kittyâ.
As you see, we didnât only use the space bar in the folder name. Thatâs because the terminal wonât recognize it. Whenever you want to navigate to a folder containing a space in itâs name, you replace it with the backslash character, followed by space. You can also, without using the backslash+space option, just put the whole folder name into quotes, f.ex. cd /home/username/âHello Kittyâ.
Try it out yourself. Navigate to a different directory using cd, and when there, type pwd to see if everything worked as itâs supposed to. Mr. Shottsâ Shottcuts
Mr. Shotts reminds us there are also some shortcuts available.
If you type only cd, without the path following it, your terminal will change your working directory (whatever it may be) to your /home folder.
The same, if you type cd ~user_name it will lead you to the home folder of the specific user you stated.
Next Week
Next week, weâll head over to the next chapter â weâll learn how to list files and directories, view text files and classify fileâs contents so it will be a bit more work than weâre used to, but I hope youâll have enough time. Command by command, and if you havenât the time to do it yourself, weâll learn the basics together in a matter of months!
and rememberâŚ
âŚhave a lot of fun!
P.S.: Thanks to bwlâs comment, we fixed an error in the text regarding the space bar in directory names.
P.P.S.: GreatEmerald also added some fresh information about file hierarchy. You can read it in the comments.
Thanks for your input/corrections.