|
We will learn how to do this right now...
cd NEW-Current-DIRECTORY-PATH |
cd is an abbreviation of the words change directory
The New-Current-DIRECTORY-PATH can be an absolute directory path or a relative directory path
|
cd /home/cheung/cs170 |
The first word cd is the name of the command (is also the name of the computer application that will be run)
The second "word" /home/cheung/cs170 is the argument of the command
|
|
Command (application) | Default argument |
---|---|
ls | the current directory |
cd | the home directory |
When ls is not given any argument, it will list the content of the current directory
When cd is not given any argument, it will change the working directory of the home directory
Symbol | Directory represented by the symbol |
---|---|
/ | The root directory |
~ | The home directory of the user |
. | The current (working) directory |
.. | The parent directory of the current directory |
The parent directory is the directory that is immediately above the current directory in the directory tree.
The parent directory of the root directory / is itself (/)
then:
Command | The directory used as argument of the command |
---|---|
ls / | root directory |
ls ~ | /home/cheung (= home directory of the user) |
ls . | /home/cheung/cs170 (= current (working) directory) |
ls .. | /home/cheung (= the parent directory of the /home/cheung/cs170) |
ls ../.. | /home |
ls ../../.. | / |
ls ../../../.. | / (because the parent directory of the root directory / is itself |
|
|
Answers:
(Type in these commands in the "command input" box and hit "ENTER")
|
|
Answers:
(Type in these commands in the "command input" box and hit "ENTER")
|
mkdir PATH-of-a-NEW-DIRECTORY |
You can use an absolute or a relative directory path in the mkdir command.
Output of the ls command | Browsing the directory with a File Explorer |
---|---|
Before the mkdir command, the cs170 directory contains: myFile1 and myFiles2
After the mkdir command, the cs170 directory also contains: hw1
|
|
command -a -b -c arg1 arg2 arg3 arg4 |
The options of the command
are: "-a -b -c"
(3 options)
The arguments of the command
are: "arg1 arg2 arg3 arg4"
(4 arguments)
Option | Effect of the option |
---|---|
-t | List files ordered by the time of creation (latest first) |
-r | List files in the reverse order |
-l | Long listing - give detailed information on files and directories |
-F | Append "/" to a directory name and "*" to the name of an executable application |
Example:
Output of different ls commands | Browsing the directory with a File Explorer |
---|---|
You can see that the output format is changed by the various options specified to the ls command
|
man ls |
You will see:
User Commands ls(1) NAME ls - list contents of directory SYNOPSIS /usr/bin/ls [-aAbcCdeEfFghHilLmnopqrRstuvVx1@] [file]... DESCRIPTION For each file that is a directory, ls lists the contents of the directory. For each file that is an ordinary file, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argument is given, the current directory (.) is listed. When several arguments are given, the arguments are first sorted appropriately, but file arguments appear before directories and their contents. |
You need to remember that the format of every UNIX command is:
command-name -options arguments |
Now let's read the synopsis:
/usr/bin/ls [-aAbcCdeEfFghHilLmnopqrRstuvVx1@] [file]... meaning: 1. The absolute path of the ls application is /usr/bin/ls 2. The list -aAbcCdeEfFghHilLmnopqrRstuvVx1@ are the options The [] around [-aAbcC...] means that you may specify the options (and you may leave it out) For the meaning of each option, you must look (search) in the manual page... 3. The word file is the argument. The [] around [file] means that you may specify the "file" as an argument (and you may leave it out) The ... after "[file]" means that you may repeat the argument again (with another name for file) or you may stop. Some possible forms that you can run ls as: ls or: ls A or: ls -l A or: ls -l -t A or: ls A B or: ls -l A B |
rmdir DIRECTORY-PATH |
You can use an absolute or a relative directory path.
(I made a mistake in the first attempt, I tried to remove the directory /home/cheung/hw1 which did not exists. I forgot the cs170 part)
Mistakes are less likely by using a relative path:
|
|
mv Old-Name New-Name |
mv is the acronym for move
|
It is advisable to use a relative directory path to rename a directory (you will know why very soon)
(I used the −F option to let you see which names are files and which are directories)
|
But instead, you created the directory inside /home/cheung/cs170 (inside a wrong folder (directory))
Graphically:
Solution:
|
mv X D |
(This has the same effect by using a file browser and do this:
|
|
But it takes a long time go to one place and drag the thing into another folder.
|