The goal of these exercises is to get you thinking about the kinds of things you can do with basic shell commands and to give some practice using them. Ideally, you will use these simple exercises to help you understand the basic operation of the shell, and to ask more questions about how to do various kinds of operations. Don't be afraid to ask the TAs or instructors for pointers on what to try next.
Are you running the bash shell? You should be for these exercises, and since most versions of Linux come with bash as the default shell, it makes sense to learn that one.
TASK: Find out which shell you are running.
echo $SHELL
grep reid /etc/passwd
TASK: If it isn't bash, then here is how to change it.
When you run a shell (or any program really), there are a bunch of environment variables that the program can access. These are similar to global variables in a programming language. You have already seen one example of an environment variable above (SHELL).
TASK: Run the env command to see a list of all of the environment variables. Three are interesting for us today: SHELL, PWD, and PATH.
TASK: set a new environment variable
export MYVAR="some value"
echo $MYVAR
env
TASK: Print your current working directory. There are two ways to do it.
echo $PWD
pwd
File system structure
Libraries stored in lib directories
TASK: Use ls and cd to explore. Try the following sequence. Think about absolute versus relative paths.
ls /
cd /
ls
cd
ls /bin
ls /usr/bin
TASK: Get comfortable with the current and parent directories.
cd
ls .
ls
ls ..
cd ..
ls
QUESTION: How many different ways can you list your home directory? (Remember the environment variables.)
TASK: Create some directories and files
temptemp create a directory called adirtemp create a file called file1
TASK: Try out some of the options to ls
ls -F /usr/bin ls -l /usr/bin
ls -F /usr/bin/python What does the @ mean? Where is the actual executable? ls -l /usr/bin/python
catheadtailmvwcRemember that the goal of these exercises is to give you practice with various shell commands. Try experimenting with all of the commands and approaches mentioned in the lecture.
The wget program downloads a web page.
wget to download http://friendfeed.com/softwarecarpentryjuly2009.ps -ef into a file called snapshot.txt.For this exercise you will be creating lots of files and directories. You can create an empty file using the command touch.
testpermissionstestpermissionsadir.which date to find out where the date program is located.date program into adir../date or adir/date (depending on your current working directory)cat it either.testpermissions, and then try changing the permissions on adir. What are the minimum permissions necessary for you to be able to execute adir/date? What permissions need to be set so that you cannot remove the text file you created?xterm or firefox.jobs to see that both processes are running.ps to find out it's process idkill to terminate the process.The best way to learn the shell is to try things out and read the man pages. Your TAs and instructors will be happy to show you their favourite tricks.