Concepts we covered
- Hidden files and directories:
- Add a "." to the filename or directoy to make it hidden
- use "ls -a" to show all the hidden files and directories
- The "ls -a" command always shows a "." and a ".." file in each
- "." is the current directory
- ".." is the directory above. Try "cd .."
- Get ssh login to work without a password:
- Use "ssh-keygen" to generate a keypair on your local machine
- Copy your public key to server (on Linux use this command on
your local machine: "ssh-copy-id ssh-copy-id -i .ssh/id_rsa.pub email@example.com"
- Does the ssh connection die after a certain time of inactivity?
- The ".bashrc" file
- This is a script that is executed each time the user logs in
- Add "echo hello" to the end of your .bashrc file to see what
happens when you login
- TIP: if you want to persist a variable, add it to this file.
- Setting a variable: "FOOD=sausage"
- Reading a variable: "echo $FOOD"
- To set an environment variable, you have to use "export variableName=Value"
- To see all environment variables, enter "printenv"
- Environment variables determine how your command-line
functions. For example: the PS1 variable. Try entering "PS1=aargh"
- A very very very important environment variable is PATH.
- See here for some more information on environment variables: https://help.ubuntu.com/community/EnvironmentVariables
- The PATH environment variable
- This determines which directories UNIX looks in when you tell
it to run a command.
- To find out which directory a command came from, use "which".
For example: "which ls"
- Some commands are built-in, like "cd", therefore "which cd"
returns no result.
- You can edit your PATH variable (and should know how to do
- Try temporarily breaking your command line by entering
"PATH=woop" and seeing what happens
- Further information:
First of all, make it so that every time you login to the server, you
are greeted by
Create a directory called "homework102" in your home directory. Copy
your "info" script from last time into this directory. Rename it to "info.sh". Now change it
- A cow saying a fortune
- Ensure the fortune is always a short one (read the man page)
- NOTE: if you make a mistake, you could break your login so that
it no longer works. In this case, write me a mail.
This should be the output:
- it only uses variables (i.e. no commands other than echo)
- the output contains less linebreaks than last time (compare the
output below to last time)
- it outputs the contents of the FOOD variable which you set before running the script.
Now write a script called "moreInfo.sh" that asks you for your name and then outputs the
I am a script located in the following location: <working directory here>
I am being run by the following user: <username>
I like to eat: <content of FOOD variable>
This should be the output
- To make the script ask your for input, use "read VARIABLE". Test it on the
- To output the date, use this command: "date +%F". Test it on the command line.
- HINT: you can put the output of a command in a variable by doing this: "VARIABLE=$(fortune)".
What is your name?
Create a directory called "scripts" in your home directory. Add the
scripts directory to your PATH variable (yes, you can do it!) and make
sure it is persistent (in other words, still there after you log in and
out again). Create a script called "howMany.sh" which counts the number
of normal and hidden files in the current directory.
<enter name here>
Hello, <your name>. Today's date is 2012-04-04.
The output should be:
- HINT: to count the number of normal files in a directly use "ls |
wc -l". Read the manpage of "wc" again to remind yourself how it
- This script should be executable in whatever directory you are in by simply entering "howMany.sh"
The number of normal files in this directory is <number of files>
The number of normal plus hidden files is <number of files>