Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Absolute and Relative Names You can specify a file or directory by its path name. There are two ways of expressing the path name: Full
Absolute and Relative Names You can specify a file or directory by its path name. There are two ways of expressing the path name: Full (absolute) path name or relative path name. The full path name starts with the root. /, and follows the branches of the file system, each separated by /, until you reach the desired file. However, a relative path name specifies the path relative to your current working directory. Relative path name are more convenient because they are shorter, but must be used with care. They never begin with / (slash). Now, we have to introduce two special directory entries: - the current directory .. the parent directory Examples: User the above diagram and assume that your current working directory (your current position in the file system) is ugics: 1. A file named "salam.txt" is placed inside the directory "st111111". The absolute (full) name is: /home/ugics/st111111/salam.txt The relative name is: st111111/salam.txt OR ./st111111/salam,txt 2. A directory named "ahmed" is placed inside the directory "gradics". The absolute (full) name is: /home/gradics/ahmed The relative name is: . /gradics/ahmed 3. A file named "esh" is placed inside the directory "bin". The absolute (full) name is: /bin/csh The relative name is: ..//bin/csh 4. A directory named "st123456" is placed inside the directory "ugics". The absolute (full) name is: / home/ugics/st123456 The relative name is: st123456 OR ./st123456 Accessing Linux Bash Shell Throughout this course, we will access Linux bash shell on Windows 10. Learn How to install Windows Subsystem for Linux (WSL) on Windows 10. Linux Commands: 1. Listing files and directories Is (list) When you first login to any Unix machine, your current working directory is your HOME directory. Your home directory has the same name as your username. Example 1: To find out what is in your home directory, type: \% 1s There may be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created. Is does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.). Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with Linux!!! Example 2: To list all files in your home directory including those whose names begin with a dot, type: ls a The -a indicates an option to show all files in your home directory. Is is an example of a command which can take options: - a is an example of an option. The options change the behavior of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behavior of the command. (See later in this Lab) Example 3: Type the following command: o ls / The / character is the directory name for the root directory. What you should see are the subdirectories and any files that are located in the root directory. Exercises (1a): 1. Try putting the a option and the 1 option together (-al). Does the order of the parameters affect the output? 2. Write a command to display all files in the directory /etc ? 2. Making Directories mkdir (make directory) We will now make a subdirectory in your home directory to hold the files you will be creating and using in this course. Example: To make a subdirectory called cccs225 in your current working directory type \% mkdir cccs225 Now to see the directory you have just created, type oo ls Please note that creating a subdirectory will not change your current position in the file system tree. Thus, after creating cccs225, your current directory stills remain you HOME directory. 3. Changing to a different directory cd (change directory) If you just logged into your Unix account, you are placed in your home directory. ' in ' means your current position in the file system tree. The cd (change directory) command is used to change your current directory (your current position) to another directory. Example: To change to the directory you have just made, type ; cdcccs225 Type ls to see the contents (which should be empty) Exercises (1b): 1. Make another directory inside the cccs225 directory called "LaboS" then make "LaboS" your current working directory. 2. Now type the command: o cd followed by: oo ls In which directory you are located now? 3. Type the following command o cd/etc/fs followed by: o 1s In which directory you are located now? 4. Now enter the command: of cd In which directory you are located now? 5. Write a single Unix command to make "Labos" your current working directory. 4. Pathnames pwd (print working directory) The pwd command is very useful to know your current position in the file system. It displays the full path name of your current working directory. Example: Now, type o pwd What is your current working directory? Be sure your current working directory is Labos before moving to next section 5. Pico: Text Editor program While using Linux you will often want to create a text file and then change its content in some way. A text editor is a program that has been designed especially for this purpose. The easiest of all editors is the pico editor. Example: Creating a new file named hello.txt 1. At your Linux prompt, type pico filename, replacing fi lename with the name of the file you want to create or edit. For example, to create a file and name it hello.txt, type: \& pico hello.txt Pico displays a menu bar of commonly-used commands at the bottom of the screen. 2. Type the following lines: Hello world, I'm a student in UJ. I'm learning Linux OS So this is my first lab 3. To exit Pico, press [Ctr]+[x]. Since you have mode some changes, Pico asks whether to same them. Type y (yes) or n (no). If you type y, Pico displays the filename. (To save the edited file under a different name, delete the filename and type a new one.) Press [Return]. Exercise (1c): Modify the above file such that the content will be as follow: Hello world, My name is Ahmed Abdullah I'm a student in UJ. I'm learning Linux OS So this is my first lab 6. Displaying the contents of a file on the screen clear (clear screen) Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood. At the prompt, type: o clear This will clear all text and leave you with the \% prompt at the top of the window. cat (concatenate) The command cat can be used to display the contents of a file on the screen. Example: To verify your wok in previous section, you can view the content of hello.txt by typing: o cat hello.txt The cat command is useful for displaying short files of a few lines. To display longer files use less or more commands. 7. Copying Files cp (copy) The cp command allows you to copy a file from one location to another location. There are different syntaxes to use cp command as shown below: Syntax 1: ( copy a file to another file) o cp file1 file2 where file1 is the name of an existing file and file2 is the name for the new copy of that file. The original file will remain unchanged and a copy will be placed in file2. If file1 and file2 are not in current directory, then you have to specify its pathname. Syntax 2: (copy a file to another directory) o cp file directory where file is the name of an existing file and directory is the name for the destination directory. The original file will remain unchanged and a copy will be placed in that directory. Be sure your current working directory is Labos before moving to examples Create a new directory named "backup" inside your current directory Example1: To create a backup of hello.txt by copying it to a file called salam.txt, type: o cp hello.txt salam.txt Now to see the file you have just created, type: oo ls Observe that you have two files in your current directory; hello.txt and salam.txt. Example2: To copy the file named "salam. txt" to the directory names "cccs225", type: of cp salam,txt .. Why!!? Now to see the file you have just copied, type: of ls .. Example3: To copy the file named "salam . txt" from directory "cccs 225 " to your current directory named as "salam.txt", type o cp../salam.txt salam,txt Why!!? Now to see the file you have just copied, type: ls Exercise (1d): Copy the file named "Hello.txt" to your home directory? Verify your work. 8. Moving Files mv (move) To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two. It can also be used to rename a file, by moving the file to the same directory, but giving it a different name. Example: We are going to move the file "salam. bak" to your backup directory, type \% mv salam.txt directory Now what is the content of your current directory? What is the content of your backup directory? 9. Removing Files and Directories rm (remove) rmdir (remove directory) To delete (remove) a file, use the rm command. However, to delete a directory use the rmdir command. There is one constraint to delete a directory; the directory must be empty. Example 1: We know that your backup directory contains two files named "salam.txt" and "salam.bak". We are going to delete the file "salam.txt" and, as an exercise, delete the second file. of rm salam.txt Example 2: If you successfully delete the two files, you can delete the backup directory. To delete the backup directory, type: o rmdir backup Exercises (1e): 1. Delete the file named "salam. txt" from directory "cccs225" 2. create a directory named "tempdir" by using mkdir then remove it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started