Introduction to Linux - Cowsay Mini-adventure
Attempt this miniadventure after going through the content of the “intro to linux” main tutorial.
< Introduction To Linux > ------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
This tutorial adopted from one written by Brianna Huynh, Class of 2019, in January 2019
Welcome to Linux! The Kali terminal is powerful and can be used for many things, including making the cow above. But before any of that happens, we need to learn some basic commands that’ll help us move around the terminal.
- Log in to Kali
Open up a terminal window
For this tutorial, get a shell running as user
rootby running this within your terminal:
This launches a shell (
-s) as root via the
Let’s see where we are right now. Enter the following command to show our current directory
pwd: print working directory
We see that we are in the
rootdirectory. This is the “home directory” for the
rootuser. There also exists a
rootuser on linux systems.
rootis the root admin for an operating system. In other words, it has the highest clearance in the system and is able to perform all commands.
Other users may not have permissions to run certain actions, but
rootcan do all.
Now that we know which directory we’re working in, what kind of files do we have in here? Type in the following command to list directory contents.
Sometimes, files can be hidden from the
lscommand. Like ninjas. We get around this by adding a flag to the command which tells it to do something specific.
-a: display all, including hidden files
Many commands have useful flags that tailor it to do exactly what you need it to do. Where do we find out all the options of the command? We can use
Well, specifically the
man <name of the command you want to check>to see all the documentation available.
There are a variety of different applications that can be installed into Linux. For example, the cow at the top of the lab can be made in the terminal and is, arguably, the most important function that can be performed in Linux.
Sudo apt install cowsay
sudo: allows the user to run commands as root
apt install: installs an application using kali’s
cowsay: the best application
After the installation is complete, try the command out.
cowsay <something you want the cow to say>
Oh dear, that didn’t work. When applications are installed via
apt, they often install themselves into a location that makes them discover-able and therefore run-able via just their standalone names. But this doesn’t work when using user
root(it does work for non-root users). We’ll have to do it ourselves.
First, find where the
cowsayapplication was installed on the filesystem.
find / -name 'cowsay'
Show off your navigational prowess by changing directories to where
cowsaysaid it was located.
You could do:
Or you could do:
cd .. cd usr cd games
pwdto see that where you are located matches the handy prompt info:
See what is in your current directory. Do you see
We’ve found cowsay! To run an application, you either (1) specify its full path (e.g.,
/usr/games/cowsay), or you put it on your $PATH environment variable, so that you do not have to specify its path.
Verify that you can run
cowsayvia its full path:
/usr/games/cowsay <thing to say>Warning: If you run
cowsaywithout any arguments, it will sit and wait, listening for standard input, for you to type what you want it to say. Finish your message with
ctrl+d, or kill the process with
But let’s update our PATH env variable to include
First, look at your current path:
Do you see
/usr/gamesthere? You do not. Update your
This will set
PATHto be the current (expanded) value of PATH, plus the
:delimits path for the $PATH variable.)
Now check your
Check that we can now run
cowsaywithout specifying the full path:
`cowsay <thing to say>`
This is nice, but we would have to run this every time we opened a new shell. Let’s make our updated
PATHpermanent. We can do that for our shell (terminal) by entering commands that will be run on each launch, in the
.bashrcfile located in our home directory.
Move back to the home folder
cdwithout any arguments will shortcut-navigate you to your home directory. You could also have run:
.bashrcfile is located here. Verify that this is so:
Open up a text editor with the .bashrc
Add this line to the bottom of the file:
exportwill make the variable stick outside of the process that is reading the
.bashrcfile (otherwise, the update would only persist within the scope of the shell initialization process).
Save the file
Exit the file
Tell your shell to
.bashrcso that the path for your current shell gets read.
alternatively, close this terminal and open a new one.
cowsay <something you want to say>
Did it work? If so, yay!
Proof of cowsay mastery
Submit a screenshot of a dead-appearing cow thinking your full name and username.
(Hint: read the
Figure out how how you can make budweiser frogs say something instead of a cow. Submit a screenshot of the bud-frogs saything your full name and username.
(Hint: read about the
cowfileoption in the cowsay manpage)