More powerful than the spiky blue shell
Follow these steps to set up your own repository:
-
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
-
Visit your fork and clone that repository onto your computer:
git clone https://github.com/<your-username>/Core-Unix-Utilities.git
-
Push your commits and link the local repo to your remote GitHub repo:
git push -u origin master
-
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
-
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
-
When you want to access new course materials, just pull from the origin remote repo:
git pull core master
Challenges within each section are meant to be solved in order.
cd/: go to root
- Print the path of your working directory
pwd
- List the files in your working directory
-
ls
- List the files with a particular extension, like
.txt
-ls *.txt
- List the files in a subdirectory, like
project
-ls ./project
- Navigate to a subdirectory, like
project
-cd ./project
- Navigate to the parent directory of your working directory
-
pwd; cd ../
- Navigate to a nested subdirectory, like
path/to/project
-cd path/to/project
- Navigate to your home directory
-
cd
- Navigate back to the previous directory
-
cd -
- Print a sentence, like
Hello world
-echo "Hello World"
- Print a variable value, like
$USER
or$PATH
-echo $USER
- Set a variable
NAME
equal to your first name, then print its value -NAME="sky"; echo $NAME
- Set a variable
FULL_NAME
equal to your full name, then print its value -FULL_NAME="skyxu"; echo $FULL_NAME
- Print all environment variables (names and values)
-
printenv
orenv
- Make an alias named
hello
that printsHello world
-greeting = 'hello'; alias hello = "echo $greeting"
- Make an alias named
gocode
that navigates to your code directory -bashrc ~/code
- Print all aliases (names and values)
alias
- Print what options a command accepts, like
bash
orpython
-man options
- Read the manual for a command, like
echo
orls
-man echo
-man ls
- Print the file path to a command, like
bash
orpython
-python -c "import sys; print(sys.path)
this prints out the dir in an arr -python -c "import sys; print(':'.join(x for x in sys.path if x))
ls -a
: show all files including hidden files
ls *
: show all folders and files within them
- Navigate to the directory
Animals
-cd A
- Print the contents of the file
Cats.txt
-cat Cats.txt
-less Cats.txt
- Print the contents of both files
Cats.txt
andDogs.txt
-cat Cats.txt ; echo "++++++++"; cat Dogs.txt
-head -n2 cats.txt Dogs.txt
- Count the words in the file
Cats.txt
wc Cats.txt
ls | wc
- Count the words in all files with the extension
.txt
wc *.txt
- Copy the file
Dogs.txt
to a new fileBabyDogs.txt
cat Dogs.txt >> BabyDogs.txt
cp Dogs.txt BabyDogs2.txt
cat Dogs.txt > BabyDogs.txt
mv Dogs.txt BabyDogs3.txt
- Rename the file
BabyDogs.txt
toPuppies.txt
mv BabyDogs.txt Puppies.txt
- Make a new directory named
Shelter
insideAnimals
mkdir Shelter
- Move the file
Puppies.txt
into the directoryShelter
mv Puppies.txt Shelter/
- Copy the file
Cats.txt
toKittens.txt
insideShelter
cp Cats.txt Shelter/kittens.txt
- List the files within the directory
Shelter
ls /Shelter
- Count the words in all
.txt
files insideShelter
wc Shelter/*.txt
- Try to remove the directory
Shelter
(this should fail)rmdir Shelter/
- Remove all
.txt
files insideShelter
-r is recursively remove
rm -i -r Shelter/*.txt
- Remove the directory
Shelter
(this should succeed) - Now cry because you just deleted those poor tiny animals
give write permission to group
-chmod g+w filename
-chomd go-rwx
- Print out your user name
- List the permissions (and metadata) of all
.txt
files - Give all users write permission on the file
Cats.txt
- List the permissions (and metadata) of the file
Cats.txt
- Change the owner of the file
Cats.txt
to another user - Now list the permissions (and owner) of the file
Cats.txt
- Try to change the owner of the file
Cats.txt
back to yourself - Invoke the super-user to make the previous command succeed
- List the permissions (and owner) of the file
Cats.txt
again
These challenges utilize more sophisticated Unix utilities. Challenges within each section are meant to be solved in order.
- Print a sentence like
Hello world
into a file namedtest.txt
- Append another sentence
Hola Mundo
on a new line oftest.txt
- Print the contents of the file
test.txt
- Print the contents of the file
numbers.txt
- Print the first 10 lines in the file
numbers.txt
- Print the first 5 lines in the file
numbers.txt
- Print the last 10 lines in the file
numbers.txt
- Print the last 5 lines in the file
numbers.txt
- Print lines 6 through 10 in the file
numbers.txt
- Sort all lines in the file
numbers.txt
- Print the first 2 characters of each line in
numbers.txt
- Print only characters 9-16 of each line in
numbers.txt
- Sort the first 2 characters of each line in
numbers.txt
- Print only the unique first 2 characters of each line in
numbers.txt
- Replace all
o
s with0
s in filetest.txt
- Capitalize all letters in the file
test.txt
- Capitalize all letters in the string
Hello world
- Find the file named
Cats.txt
in the directoryAnimals
- Find all files ending with
.py
in your code directory - Find all files larger than 100 MB in your movies directory
- Find all lines containing the word
one
in the filenumbers.txt
- Find all lines containing the letter
e
at least 3 times in the filenumbers.txt
- Find the
search
function definition in a source code file - Find the
search
function definition in all source code files - Count the lines and words in all source code files
- Find all U.S. zip codes in a file containing addresses
- Find all U.S. zip codes in a file containing addresses