wiki:cypress/BasicLinuxComands/Exercise

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, make a new subdirectory in your home directory:

  • 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 ~]$ 
    
  • 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 ~]$ 
    

Next, let's move some files into our new directory

  • 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 "~/hpc-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 ~/hpc-project/workshop/TextFiles/
    alphabet.txt  numbers.txt
    [tuhpc002@cypress1 TextFiles]$ 
    
  • Copy the files to your current directory

Now, examine the contents of those files

  • Use the cat command to examine the content of the numbers.txt file
    [tuhpc002@cypress1 examples]$ cat numbers.txt 
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    [tuhpc002@cypress1 examples]$ 
    
  • Use the tail command to list the last 4 lines of the numbers.txt file
    [tuhpc002@cypress1 examples]$ tail -4 numbers.txt
    07
    08
    09
    10
    [tuhpc002@cypress1 examples]$
    
  • Invoke the head command to list the first 5 lines of the alphabet.txt file
    [tuhpc002@cypress1 examples]$ head -5 alphabet.txt
    a
    b
    c
    d
    e
    [tuhpc002@cypress1 examples]$ 
    

Lastly, let's practice copying, moving, and removing files

  • 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 ~/hpc-project/workshop/TextFiles/alphabet.txt alphabet.txt
    [tuhpc002@cypress1 examples]$ cp ~/hpc-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

  • Copy the file ~/hpc-project/workshop/TextFiles/animals to your home directory
  • 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

Last modified 5 years ago Last modified on 03/20/20 12:29:36
Note: See TracWiki for help on using the wiki.