Paths
Question 3: Create and Navigate Directories
What is your current working directory?
$ pwd
/home/demo
Make three directories in your HOME directory. Name these directories "mydir", "data", and "images".
$ mkdir mydir data images
Change your working directory into "data". Create two more directories in /home/demo/data called "dir1" and "dir2". If you create them in the wrong place delete them using "rmdir".
$ cd data
$ mkdir dir1 dir2
Change directory into dir2.
$ cd dir2
$ pwd
/home/demo/data/dir2
Change your current working directory to /home/demo. You can either "cd /home/demo" or "cd ..", as ".." means the directory above the current directory in your directory tree. Check with pwd to make sure you are in the right directory. Then try to delete the data directory using "rmdir data". What message to you get back?
$ cd /home/demo
rmdir data
Directory not empty
This deletes all files and directories in the data directory, including the data directory itself. Obviously getting the parameter wrong means you can lose a lot of stuff in one go!
$ cd /home/demo
$ rm -rf data
Question 4: The ls command
What is the first file (in alphabetical order) which appears when you use "-a" in your HOME directory, other than "." and "..".:
$ ls -al
.bash_logout
Use the "-l" option to see a long listing of a file. Get a long listing of "/etc/passwd" and identify its size in bytes.:
$ ls -al
2512
Question 5: Relative and Absolute
What is the current directory:
$ cd /usr/share/doc
$ cd ..
$ pwd
/usr/share
What is the current directory:
$ cd /usr
$ cd lib
$ cd kernel
$ pwd
/usr/lib/kernel
What is the current directory:
$ cd
$ cd ../..
$ pwd
$ /
What is the current directory:
$ cd
$ cd ../demo
$ pwd
$ /home/demo
What is the current directory:
$ cd /usr/share
$ cd vim/../../lib/kernel
$ pwd
$ /usr/lib/kernel
What is the current directory:
$ cd /usr/share
$ cd /etc/sysconfig
$ cd ..
$ pwd
$ /etc
What is the current directory:
$ cd
$ cd ../../usr/share/doc
$ pwd
$ /usr/share/doc
Consider these commands and fill in the blank:
$ cd
$ cd ../../usr/local/lib
$ pwd
Consider these commands and fill in the blank:
$ cd /usr/share/doc
$ cd /home
$ cd demo
$ pwd
Where the "pwd" command prints "/usr/share/perl5/Encode".
$ cd /usr/share/man
$ cd ../perl5/Encode
$ pwd
Where the "pwd" command prints "/etc"
$ cd /usr/share/perl
$ cd ../../../etc
$ pwd
Where the "pwd" command prints "/etc"
cd /etc
cd .
pwd
Last updated
Was this helpful?