Lab01
Lab01
to CS
College of Engineering Lab. Section
Department of Computer Science & Engineering Fall 2024
To install the Ubuntu on Windows 10, follow the steps listed in the Install_ubuntu.pdf available on the
Blackboard, Course Contents.
Utility Installation
In Linux, the tree command is a utility that is used to display directory and file structures in a tree-like
format. It provides a clear and structured view of the directory hierarchy, making it easier to understand
the organization of files and directories.
To install tree utility, enter the following commands in ubuntu command window
Preparation
1. Run the mkdir (make directory) to create a new directory (or folder), name as lab01
Now, the prompt should indicate the current working directory (the label just before the $
character)
3. Run the pwd (print working directory) command to check that you are in lab01 directory.
4. Run the tree command. The lab01 directory should be empty. You will get:
0 directories, 0 files
Page 1 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Exercise 1
1. Run the echo command to print out the text arguments to the display. After the command, you
can put any text. Try this;
echo Hello, World should be in double quotation
2. Run the date command to display the current time and date. The output may look as this
3. To format the date command’s output, you can use control characters preceded by a + sign.
Format controls begin with the % symbol and are substituted by their current values where the
%Y character is replaced with the current year, %m with month, and %d with the day. Try this:
4. Try this reformatting the date output using this command. The %n inserts a new line so the time is
printed on the following line
wrong here should be + then "
date "+DATE: %D%nTIME: %T" %n means new line
Output:
DATE: 08/24/24
TIME: 10:27:01
These are the most common formatting characters for the date command:
• %D – Display date as mm/dd/yy
• %Y – Year (e.g., 2020)
• %m – Month (01-12)
• %B – Long month name (e.g., November)
• %b – Short month name (e.g., Nov)
• %d – Day of month (e.g., 01)
• %j – Day of year (001-366)
• %u – Day of week (1-7)
• %A – Full weekday name (e.g., Friday)
• %a – Short weekday name (e.g., Fri)
• %H – Hour (00-23)
• %I – Hour (01-12)
• %M – Minute (00-59)
• %S – Second (00-60)
Page 2 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
ctrl C to break
^C : to write what i wrote earlier
clear to clean
Your Turn
Find the correct format to display the output similar to the following;
Note: To get the complete list of date formatting, ask for help; date --help
Directory Tree
At the end of Exercise-2, you should have the following file structure where lab01 is our working
directory
home
dir3 file4
dir4 file5
dir5
file6
1. Inside lab01 directory, how many files and directories are there?
2. Inside lab01 directory, how many directories (folders) are there?
3. Inside dir1 directory, how many directories (folders) are there? white is a file and the blue is
directory
4. What is there inside dir2 directory?
5. What is there inside dir3 directory?
6. What is there inside dir5 directory?
Page 3 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
General
• Enter the clear command to clear the screen
• Use the arrow-up to display the line you want to repeat.
• To copy a code from Linux window, high-light then hit the Enter (New Line) key
• Most commands have many useful options, to get more information, use the help command.
WARNING!
• Linux command line does not have an undo feature. Perform destructive actions carefully.
• Be cautious when using the remove (rm) command, as it will permanently delete the specified
file, and there is no straightforward way to recover it once deleted.
• Be careful with move (mv) command as you may end up, in some cases, completely
overwriting/deleting your files.
The touch command is used to create, change and modify the timestamps of a file. It does not delete an
existing file. Its primary purpose is to update the timestamps (access and modification times) of a file. If
the file does not exist, touch will create an empty (without any content) file with the specified name.
Exercise 2
Step-1: In lab01 directory create all the directories and files. Enter the tree command to display the
contents of the lab01 directory
Design Steps
1. Enter the tree command to list the contents of the lab01 directory
2. With the touch command, create six empty files, file1 to file6 (all names in lower-case).
Note:- If you do not want to re-type the same command, hit the up arrow key to show the last
command and then modify it.
3. Enter the tree command to list the contents of the lab01 directory
4. With the mkdir (make directory) command, create five directories; dir1 to dir5 (all names in
lower-case).
5. Enter the tree command to list the contents of the lab01 directory
6. Take a snapshot of the screen and paste it in your document file. Use the Snipping Tool which
will be useful to add images in the document.
Page 4 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Fig.1: After creating directories and files
1. With the mv (move) command, move files dir4 into dir3. Use the given syntax;
mv <folder_name> <destination>
2. Enter the tree command to list the contents of the lab01 directory
3. Take a snapshot of the screen and paste it in your document. mv file1 dir1
Page 5 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Step-3: Place the file1, file2, file3 and file4 files as indicated on the chart.
1. With the mv (move) command, move file1 file into dir1 directory. Use the given syntax:
mv <file_name> <destination>
2. With the mv (move) command, move file2 file into dir1 directory.
3. Enter the tree command to list the contents of the lab01 directory.
4. With the mv (move) command, move file3 file into dir2 directory.
5. Enter the tree command to list the contents of the lab01 directory.
6. With the mv (move) command, move file4 file into dir3 directory.
7. Enter the tree command to list the contents of the lab01 directory.
Read this carefully: since dir4 is inside dir3 directory and the pwd location is lab01, then, linux will
need the exact path from lab01 to dir4
1. With the mv (move) command, move file5 file into dir4 directory. Indicate the path. Use the
given syntax:
mv <file_name> <path/destination>
2. Enter the tree command to list the contents of the lab01 directory.
Do NOT change the working directory. For these activities, it should always be lab01. Use the pwd
command to check.
1. Since the mv (move) command removes the file to put it in its new location, then it can be used to
rename a file. Use the following syntax:
mv <old_file_name> <new_file_name>
Fig.5: An error message because file1 is not in the working directory, lab01
3. Why? Because file1 is in dir1 directory and not in the lab01 directory.
Page 7 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Exercise 5
Exercise 6
Finally, delete all files and directories you have created today, including lab01.
Design Steps:
1. Use the rmdir (remove directory) command to delete the dir5 directory.
Page 8 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Note:- Don’t use the rm command to delete a directory. Linux will generate an error message
2. Use the rm (remove file) command to delete the file01 directory. Don’t forget to add the path.
rm dir01/file01
3. To delete lab01 directory, you will have to move up to the home directory using the cd command
4. After completing all operations, enter the exit command to close the Ubuntu window
Page 9 of 9
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair