wiki:cypress/BasicLinuxComands/Exercise

Version 2 (modified by cmaggio, 6 years ago) (diff)

Basic Linux Commands Exercise

Let's put some of our new knowledge into practice by creating a new directory to house some files we'll be using throughout the day.

Goal: Create a subdirectory in your home directory

While logged into Cypress:

  • Navigate to your home directory by using the cd ~ command.
  • Check that you are in your home directory by using the pwd command.
[tuhpc002@cypress1 ~]$ cd ~
[tuhpc002@cypress1 ~]$ pwd
/home/workshop/tuhpc002
[tuhpc002@cypress1 ~]$ 

Next:

  • Make a new subdirectory called "examples" using the mkdir command.
  • Check that the directory was created by using the ls command.
    [tuhpc002@cypress1 ~]$ mkdir examples
    [tuhpc002@cypress1 ~]$ ls
    examples
    [tuhpc002@cypress1 ~]$ 
    
  • Move into the examples subdirectory using the cd command and the relative path directory examples
    [tuhpc002@cypress1 ~]$ cd examples/
    [tuhpc002@cypress1 examples]$ 
    
  • Now, check the contents of the directory "/lustre/project/workshop/textfiles" using the ls command and the absolute path directory (Hint, you can use the tab key to autocomplete partially typed commands)
[tuhpc002@cypress1 textfiles]$ ls /lustre/project/workshop/textfiles/
alphabet.txt  numbers.txt
[tuhpc002@cypress1 textfiles]$ 
  • Copy the contents of the textfiles directory to your examples directory using the cp command
  • Use the ls command to ensure that you've transferred the correct files to the correct directory
    [tuhpc002@cypress1 examples]$ cp /lustre/project/workshop/textfiles/alphabet.txt alphabet.txt
    [tuhpc002@cypress1 examples]$ cp /lustre/project/workshop/textfiles/numbers.txt numbers.txt
    [tuhpc002@cypress1 examples]$ ls
    alphabet.txt  numbers.txt
    [tuhpc002@cypress1 examples]$ 
    
  • Create a backup of the "numbers.txt" file named "numbers_backup.txt" using the cp command.
[tuhpc002@cypress1 examples]$ cp numbers.txt numbers_backup.txt
[tuhpc002@cypress1 examples]$ ls
alphabet.txt  numbers_backup.txt  numbers.txt
[tuhpc002@cypress1 examples]$ 
  • Remove the original "numbers.txt" file using the rm command
    [tuhpc002@cypress1 examples]$ ls 
    alphabet.txt  numbers_backup.txt  numbers.txt
    [tuhpc002@cypress1 examples]$ rm numbers.txt
    [tuhpc002@cypress1 examples]$ ls
    alphabet.txt  numbers_backup.txt
    [tuhpc002@cypress1 examples]$ 
    
  • rename the backup file "numbers.txt" using the mv command
    [tuhpc002@cypress1 examples]$ ls
    alphabet.txt  numbers_backup.txt
    [tuhpc002@cypress1 examples]$ mv numbers_backup.txt numbers.txt
    [tuhpc002@cypress1 examples]$ ls
    alphabet.txt  numbers.txt
    [tuhpc002@cypress1 examples]$ 
    

Challenge

  • Create two new subdirectories in your home directory called "letters" and "digits".
  • Move the alphabet.txt file to the letters directory and the numbers.txt file to the digits directory.
  • Lastly remove the examples directory from your home directory.

return to basic linux commands page