This is a practice sheet for The following Video from Linux Command Line Journey Youtube Playlist. We would recommend you to watch the full video before doing this exercise.
1. Creating Directories
a. Make a directory called “playground” in your home directory.
Click for answer
cd ~
mkdir playground
b. Go-to the “playground” directory and create two more directories here – “dir1” and “dir2”
Click for answer
cd playground
mkdir dir1
mkdir dir2
c. Can you create the above directories using only 1 command ?
Click for answer
mkdir -p ~/playground/dir1 ~/playground/dir2
2. Copying Files
a. Copy the file /etc/passwd to the current working directory, i.e. ~/playground
Click for answer
cp /etc/passwd .
b. Repeat the above copy command with “-v” option
Click for answer
cp -v /etc/passwd .
c. Repeat the copy command with “-i” option this time. Notice any difference ?
Click for answer
cp -i /etc/passwd .
3. Moving and renaming files
a. Rename the “passwd” file you copied, to “fun”
Click for answer
mv passwd fun
b. Move the file “fun” to dir1
Click for answer
mv fun dir1
c. Move the file “fun” from dir1 to dir2
Click for answer
mv dir1/fun dir2
d. Move the file “fun” from dir2 back to “playground”
Click for answer
mv dir2/fun .
e. Move the file “fun” into dir1 again
Click for answer
mv fun dir1
f. Move dir1 into dir2 and confirm it with “ls” command
Click for answer
mv dir1 dir2
ls -l dir2
ls -l dir2/dir1
g. Put everything back
Click for answer
mv dir2/dir1 .
mv dir1/fun .
4. Creating Hard Links
a. Create 3 hard links of the file “fun”, and call it “fun-hard” and store in 3 places – 1. the same directory, 2. inside dir1 directory, 3. inside dir2 directory
Click for answer
ln fun fun-hard
ln fun dir1/fun-hard
ln fun dir2/fun-hard
5. Creating Symbolic Links
a. Create 3 symbolic links of the file “fun”, and call it “fun-sym” and store in 3 places – 1. the same directory, 2. inside dir1 directory, 3. inside dir2 directory
Click for answer
ln -s fun fun-sym
ln -s ../fun dir1/fun-sym
ln -s ../fun dir2/fun-sym
b. Create symlink of directory “dir1” and call it “dir1-sym”
Click for answer
ln -s dir1 dir1-sym
6. Removing Files and Directories
a. Delete the hard link “fun-hard” inside “playground” directory
Click for answer
rm fun-hard
b. Delete the original file “fun” from “playground” directory. Use the “-i” option while deleting
Click for answer
rm -i fun
c. See what happened to the “fun-sym” symbolic links we created. It is broken now ?
Before:
After:
Click for answer
ls -l
d. Delete the symbolic links we created “fun-sym” from all the 3 places. Try to do it with 1 command.
Click for answer
rm fun-sym ./dir1/fun-sym ./dir2/fun-sym
e. Remove your “playground” directory. Remember, “playground” is a directory. How would you remove it ? Do you get the following error ?
Click for answer
cd
rm -r playground
All Done ! Congratulations.