Linux Exercise: Logging in and out, using the system

Logging in and out, changing your password

  1. Login to the lab system. Your instructor will tell you the hostname, username and password to use.
    • On a Windows system, start the PuTTy program. In the Host Name text box, type the name or IP address of the system. You may also want to type the name of the system in the Saved Session box and then click on Save. This saves the session data for the next time. Next, click Open. Login with the username and password that the instructor gave you.
    • On a Linux system, open the Terminal applicaton. Use the ssh <username>@<hostname> command to logon. Type the password when asked.
  2. Change your password.
    • $ passwd
      You will first be asked for your old password, then for the new password twice.
  3. Log out and login again, to verify your password has indeed changed.
    • $ logout
    • Login again using the instructions from the earlier step.

Looking at files and directories

  1. Print the name of your current working directory.
    • $ pwd
  2. Create a list of files in your current working directory.
    • $ ls
      It is likely that no files are present yet, so this list may be empty.
  3. Create a list of all files, including the hidden files, in your current working directory.
    • $ ls -a
  4. Create a long listing of all files, including the hidden files, in your current working directory.
    • $ ls -la
  5. Change your working directory to /tmp. Make a long list of all files in /tmp.
    • $ cd /tmp
    • $ ls -la
  6. Change back to your home directory. Again, make a long list of all files in /tmp.
    • $ cd
    • $ ls -la /tmp

Working with the shell

  1. Clear your screen.
    • $ clear
  2. Write "Hello, World" to your screen.
    • $ echo "Hello, World"
  3. Use the arrow up/down key to retrieve and execute previous commands.
  4. Use the shell search function (Ctrl-R) to search for previous commands.
  5. Use the tab key to perform command and file name completion.

Communicating with other users

  1. Make a list of all users that are active on the system. Use both the w and who commands.
    • $ w
    • $ who
  2. Send a message to another user using the write command. End your input with Ctrl-D.
    • $ write suzanne
      Hello Suzanne!
      <.Ctrl-D>.
  3. Write a message to all users on the system.
    • $ wall "Hello, Everybody!"
  4. Wait for other users to write messages to you in a similar fasion. Note that messages from others will be written to your console (output) but will not influence the input that you're typing to the system. So if a message arrives while you are typing a command or message, simply continue typing as if nothing happened.
  5. Block incoming messages. Verify with a fellow student that he or she is indeed not able to write messages to you.
    • $ mesg n
  6. Enable messages again and verify that it's again possible for others to send messages to you.
    • $ mesg y

Listing Processes

  1. Make a short list of all your own processes.
    • $ ps
      You should be seeing two process: the bash command (which is your shell) and the ps command itself.
  2. Make a long list of all processes on the system
    • $ ps aux
      You should be seeing well over 100 processes now. If your terminal allows scrolling, you can scroll back and forth to see what your fellow students are doing.
  3. Start top to have a continuous view of the most important processes on the system. Within top, explore the built-in help, and see if you can sort the processes based on both CPU time and on memory consumption.
    • $ top
      Within top, press h for the help page. Press P to sort by processor usage, press M to sort by memory usage.

System customization

  1. Execute the date command. Was the time setup correctly? What timezone was used?
    • $ date
  2. Create an empty file called "now". Look at the date and time associated with that file. What timezone was used?
    • $ touch now
    • $ ls -l
      The time displayed as last modification time, is the time in the local time zone.
  3. Change your timezone into something else, such as Europe/Amsterdam or America/New_York. Run the date and ls -l command again. What time is now displayed?
    • $ export TZ=America/New_York
    • $ date
    • $ ls -l
      On a UNIX system, all times are internally recorded in UTC. They are then mapped to the users timezone, based on the TZ shell variable, when any program needs to display a time to the user.

Using screen (optional)

  1. Start the screen command. Did you notice anything? Use the pstree command to verify that screen started successfully.
    • screen
      The command starts, but it doesn't show anything.
    • $ pstree
      If you look carefully at the hierarchy, you should now see that screen was started as a process underneath your login shell, and a new subshell was started underneath screen.
  2. In the current (and only) screen window, start the top command.
    • $ top
  3. Use the Ctrl-a " to get a list of all currently opened windows. Hit Enter to select the current window and return to it.
    • Ctrl-a "
    • Enter
  4. Open an additional window with Ctrl-a c
    • Ctrl-a c
  5. Start the pstree command again to view your current hierarchy.
    • $ pstree
  6. Use the Ctrl-a " command again to get a list of all currently opened windows. Select the first window and hit Enter to select this window.
    • Ctrl-a "
      Use the arrow-up and arrow-down keys to select the first window and hit Enter.
  7. Use the Ctrl-a n and Ctrl-a p command to go to the next and previous windows.
    • Ctrl-a n
    • Ctrl-a p
  8. Switch to the second window, then use the Ctrl-a k command to kill this window.
    • Ctrl-a k
      Confirm that you want to kill this window.
  9. End the top command, then exit screen. Verify screen has stopped running.
    • Make sure you are in the window where top is running.
    • q
    • Ctrl-a \
      Confirm you want to close all windows and screen.
    • $ pstree
      You should now see that screen has ended.

Using tmux (optional)

  1. Start the tmux command. Did you notice anything? Use the pstree command to verify that tmux started successfully.
    • $ tmux
      You should now see a status bar, usually green, at the bottom of your screen.
    • $
      pstree
      Again, look carefully at the hierarchy to see what's happening.
  2. In the current (and only) screen window, start the top command.
    • $ top
  3. Open an additional window with the Ctrl-b c command. Do you see the status bar change?
    • Ctrl-b c
  4. Start the pstree command again to view your current hierarchy.
    • $ pstree
  5. Use the Ctrl-b n and Ctrl-b p command to go to the next and previous windows.
    • Ctrl-b n
    • Ctrl-b p
  6. Use the Ctrl-b " command to split the current pane horizontally. How many windows and panes do you have open now?
    • Ctrl-b "
    • $ pstree
  7. Use the Ctrl-b o command to go to the next pane.
    • Ctrl-b o
  8. Use the Ctrl-b x command to kill the current pane.
    • Ctrl-b x
      Confirm you want to kill the current pane.
  9. Now use the Ctrl-b % command to split the current pane vertically. Toggle between the panes and close the pane again.
    • Ctrl-b %
    • Ctrl-b o
    • Ctrl-b x
      Confirm you want to kill the current pane.
  10. Use the Ctrl-b & command to kill the current window.
    • Ctrl-b &
  11. Use the Ctrl-b :kill-session command to quit tmux.
    • Ctrl-b :kill-session
End of exercise