/Core-Unix-Utilities

Core session on Unix utilities & command line tools

Core: Unix Utilities

More powerful than the spiky blue shell

Working with this GitHub repository

Follow these steps to set up your own repository:

  1. Fork this repository on GitHub to create your own version of this repo on your GitHub account, which should also be named Core-Unix-Utilities

  2. Visit your fork and clone that repository onto your computer: git clone https://github.com/<your-username>/Core-Unix-Utilities.git

  3. Push your commits and link the local repo to your remote GitHub repo: git push -u origin master

  4. When you've completed a challenge and want to share it for code review, commit your work and push it to your own remote repo with: git push

  5. Add this GitHub repository as a remote to the local one on your computer: git remote add core https://github.com/Product-College-Labs/Core-Unix-Utilities.git

  6. When you want to access new course materials, just pull from the origin remote repo: git pull core master

Challenges, Part 1

Challenges within each section are meant to be solved in order.

Navigation

  1. Print the path of your working directory
    • pwd
  2. List the files in your working directory
    • ls
    • ls -a
  3. List the files with a particular extension, like .txt
    • ls *.txt
  4. List the files in a subdirectory, like project
    • ls -l $(find /project -type f )
    • ls directory
  5. Navigate to a subdirectory, like project
    • cd /project
  6. Navigate to the parent directory of your working directory
    • cd ..
  7. Navigate to a nested subdirectory, like path/to/project
    • cd path/to/project
  8. Navigate to your home directory
    • cd /home
    • cd ~
  9. Navigate back to the previous directory
    • cd -
    • cd ../../../ control a and control e to jump from begging and end of line control k and y cut and yank

Variables

  1. Print a sentence, like Hello world

    • echo hi
  2. Print a variable value, like $USER or $PATH

    • echo "$USER"
  3. Set a variable NAME equal to your first name, then print its value

    • NAME=Elmer
    • echo "$NAME"
  4. Set a variable FULL_NAME equal to your full name, then print its value

    • FULL_NAME=ELMER_ASTUDILLO
    • echo "$FULL_NAME"
  5. Print all environment variables (names and values)

    • printenv
  6. Make an alias named hello that prints Hello world

    • alias hello='echo hello world'
  7. Make an alias named gocode that navigates to your code directory

    • alias hello='echo cd /Users/elmerastudillo/desktop/Core-Unix-Utilities'
  8. Print all aliases (names and values)

    • alias

Getting Help

  1. Print what options a command accepts, like bash or python
  • --help
  1. Read the manual for a command, like echo or ls
  • man
  1. Print the file path to a command, like bash or python
  • which

Files

  1. Navigate to the directory Animals

  2. Print the contents of the file Cats.txt

  • cat Cats.txt
  1. Print the contents of both files Cats.txt and Dogs.txt
  • more Cats.txt
  1. Count the words in the file Cats.txt
  • wc -w cats.txt
  • wc -l cats.txt
  • wc -c cats.txt
  1. Count the words in all files with the extension .txt
  • wc *.txt
  1. Copy the file Dogs.txt to a new file BabyDogs.txt
  • cp Dogs.txt BabyDogs.txt
  1. Rename the file BabyDogs.txt to Puppies.txt
  • mv
  1. Make a new directory named Shelter inside Animals
  2. Move the file Puppies.txt into the directory Shelter
  • mv Puppies.txt Shelter/
  1. Copy the file Cats.txt to Kittens.txt inside Shelter
  • cat Cats.txt >> Folder
  1. List the files within the directory Shelter
  • ls directory/
  1. Count the words in all .txt files inside Shelter
  • wc Shelter/*.txt
  1. Try to remove the directory Shelter (this should fail)
  • mdir
  1. Remove all .txt files inside Shelter
  • rm Shelter/*.txt
  1. Remove the directory Shelter (this should succeed)
  • rmdir Shelter/
  1. Now cry because you just deleted those poor tiny animals
  • rm -r /
  • rm -r ~

Permissions

  1. Print out your user name
  2. List the permissions (and metadata) of all .txt files
  3. Give all users write permission on the file Cats.txt
  4. List the permissions (and metadata) of the file Cats.txt
  5. Change the owner of the file Cats.txt to another user
  6. Now list the permissions (and owner) of the file Cats.txt
  7. Try to change the owner of the file Cats.txt back to yourself
  8. Invoke the super-user to make the previous command succeed
  9. List the permissions (and owner) of the file Cats.txt again