Lab-03-Navigating_Instructions

pdf

School

University of Texas, Arlington *

*We aren’t endorsed by this school

Course

1003

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

13

Uploaded by Kuroshi

Report
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 1 Lab 03 – Navigating Objectives 1. Open a command line terminal in Bash and PowerShell. 2. Compare the terminal and GUI directory structures in Linux. 3. Compare the terminal and GUI directory structures in Windows. 4. Practice major terminal commands in Bash . 5. Practice major terminal commands in PowerShell . Overview Now that we’ve installed the Ubuntu operating system, you have a host (Windows/Mac) and a guest (Ubuntu) operating system. Our next step is to explore an important part of working as a security practitioner: navigating the command line terminal , or CLI . The terminal is a software program that acts as a connector to the operating system’s shell and allows users to enter commands to tell the computer how to process and perform tasks. The terminal is a text-based interface for users, providing users closer access than the graphical user interface (GUI) to interact with the computer system more efficiently. Step 01: Open a Command Line Terminal in Linux and Windows You are likely more comfortable using a graphical user interface (GUI) in Windows or Mac. However, cybersecurity folks also need to be familiar with the command-line interface (CLI) , or terminal . See here for the differences (Computer Hope). Working with the command line helps security practitioners and system administrators automate tasks and perform complex tasks rapidly in virtual machines and cloud platforms. Let’s look at how to access a terminal in both your host and guest machines. I N L INUX To reach the terminal, you can press CTRL + ALT + T . You can also access it from the Search bar in the Apps icon in the lefthand pane. Figure 1: The Ubuntu terminal
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 2 You will be working at the terminal quite a bit, so you may want to enlarge the font and set other preferences. Click on Preferences . Under the Unnamed profile, you can create a Custom font (increasing the font size to 14 font may be helpful.) Please free to customize other features as well, to ensure your terminal and screen are readable. Figure 2: The preferences tab in the Ubuntu terminal I N W INDOWS You can access the standard CLI in Windows by typing in “terminal” in the Windows search bar. For this lab, however, we will work with a PowerShell terminal instead. Open a PowerShell window by clicking on WIN + X and then select Terminal or select Terminal (Admin) for administrator privilege. Figure 3: The menu to access Windows PowerShell The command line window should open up.
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 3 Figure 4: The PowerShell terminal BREAKPOINT 1 Describe how you accessed the terminal at Linux and PowerShell with narrative text and screenshots. Include the date displayed at the top and your chosen application displayed. Include any customizations you made in Ubuntu. Step 02: Know Your Location in Linux! Now let’s work at the terminal to find our location in the system and the time. You will return to these commands over and over. Knowing your current location at the terminal will identify many errors in your terminal work. You can double-check against your graphical user interface (GUI) folder hierarchy if needed. For example, t he current directory is mostly likely your home directory. Use the pwd command (present working directory) to find the location of your home directory. pwd In addition to the desktop display of the date, you can display your current date in the terminal. date Figure 5: The pwd and date command in Ubuntu To find out more about what’s in your directory, you can always list the contents of your directory by using the ls (list) command. Unlike Windows command-line shells, Unix commands are case-sensitive , meaning that you cannot enter LS to execute the command, Without any arguments, ls will display the contents of the current directory without special formatting (except that it is sorted). Try it out and compare your commands to what is displayed in the desktop GUI version.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 4 ls Below, I have my desktop folders open to the Home directory. I have the terminal open and have listed the contents of the home directory. You can also look at the GUI equivalent by selecting the folder in the lefthand pane. Are they identical? Figure 6: Comparing output of the ls command with the GUI equivalent BREAKPOINT 2 What folders, or directories, are in your Linux home user folder? How do these compare to the folders in your GUI? Include a screenshot of your terminal and GUI view of your folders in Ubuntu. Step 03: Know Your Location in Windows! PowerShell has two types of terminal commands: cmdlets and aliases . Cmdlets are the native commands in PowerShell, and they are used to perform specific tasks. Aliases provide alternate, shorthand names, similar to Linux style commands. Aliases also allow users to configure their own names for different cmdlets or scripts, which make it more straightforward for a user to switch back and forth between different shells. In the PowerShell (PS) terminal, terminal commands you can print your working directory with pwd or Get- Location . The alias date and Get-Date prints the date.
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 5 Figure 7: Current directory and date commands as aliases and cmdlets in PowerShell The alias dir and Get-ChildItem command retrieves the folders In the current directory. Figure 8: The Powershell alias command, dir, to show your current directory contents To find the GUI version, you will need to navigate to your Users/ username directory in Windows.
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 6 Figure 9: The PowerShell cmdlet to show your current directory alongside the GUI equivalent You can find a text version of a full pathname of a Windows file or folder through the GUI as well. For example, let’s find the path of your I S 1003 Labs folder using the File Explorer view. Go to this folder, right click in the bar, and choose Copy Address as Text . Figure 10: Capturing a pathname in Windows File Explorer. Here is the copied pathname of my example (your pathname will be different): C:\Users\ritam\Dropbox\00_UTSA Cyber Curriculum\IS-1003-2024\IS-1003-Labs-Spring-2024 BREAKPOINT 3 What folders, or directories, are in your Windows home user folder? How do these compare to the default folders in your Windows computer? Include a screenshot of your terminal and GUI view of your folders in Windows. In addition, capture your pathname of your IS 1003 Labs folder using the method above and provide your specific pathname . Step 04: Practice Using Bash Commands Back to Bash, we will practice the following terminal commands for practice in this section! ls -a ls -al echo mkdir touch cat mv
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 7 cp rmdir rm history In addition to listing the standard directories, there are other files that are " hidden ". Hidden files are files that you don't necessarily want to see all the time. Therefore, unless specifically requested, they are not shown with a directory listing. Any file or directory that begins with a dot (.) is hidden and is referred to as a dot file . The home directory contains many user-level configuration files for modifying how your environment behaves, and they are almost always dot files or dot directories. The ".login" file (if it exists) controls things you always want done when you log in. The ".bashrc" file is used to configure the shell. If these do not exist, then system-wide configuration files are typically used. In addition, commands can be followed by “ options ” to specify certain kinds of output. Options typically include a dash (-) and one or more characters. List all objects, even the hidden files and directories, by using the –a (all) option, as shown below. Note that there must always be a space between the command and any options or arguments being passed to it. ls –a View a bigger picture of the contents of the current directory (such as owner and size) by using the -l (long) option, as shown below: ls –al Figure 11: Executing the ls commands with the -a and the -l options. Next, display t ext on the screen by using the echo command: echo "Hello, World!" The echo command may seem meaningless, but it comes in handy, such as when writing scripts. Now let’s make a directory with the mkdir command: mkdir IS-1003
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 8 Figure 12: Executing the echo and mkdir commands Change your working directory to this new directory: cd IS-1003 You can quickly make an empty file using the touch command. touch test.txt Place some text inside this file from the command line by using the echo command with a redirection from the command line to the test.txt file. echo “Hello, Again!” >> test.txt Test that the file with the string was created using the cat command. cat test.txt Figure 13: Executing the cd. touch, echo, and cat commands Use the dotdot directory to change your working directory to a parent directory, as shown below: cd .. Note that a nice feature of the cd command is that if it is entered with no arguments, it will always take you back to your home directory. Files or directories can be moved or simply renamed by using the mv (move) command. Move the text file in the IS-1003 directory to the home directory. mv IS-1003/test.txt test.txt ls
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 9 Figure 14: Executing and testing the mv command Copying files is done with the cp (copy) command. Copy one of your "hidden" files into the IS-1003 directory. You can copy the file as is without naming the file, or rename the file in the process. Here, we have copied .bashrc into the IS-1003 directory with the new filename .bashrc-test. List the contents of the IS-1003 to confirm the copy. cp .bashrc IS-1003/.bashrc-test ls -al IS-1003 Now, try to delete the IS-1003 directory using the rmdir (remove directory) command: rmdir IS-1003 Figure 15: Executing and testing the cp and rmdir commands It should have failed because files still exist in that directory. Delete the files in the IS-1003 directory by using the rm (remove) command: rm IS-1003/.bas* ls –al IS-1003 Notice the use of the wild card "*" symbol in the rm command. The command is interpreted as "delete all the files starting with ‘.bas’". There was only file in the directory, so now, the only files available are the hidden . and .. files. Figure 16: Executing and testing the rm command
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 10 Finally, you can list all the commands you’ve typed in a session by using the history command. This is helpful if you want to record the set of steps, or recall a prior step, or you want to troubleshoot an issue by seeing if you mistyped a command, etc. Your history will look different than mine below! Figure 17: Executing the history command BREAKPOINT 4 Execute the commands in this section with definitions and screenshots. Specifically, above the screenshot(s), describe the command and its function (meaning, what does it do?). Step 05: Practice Using PowerShell Commands Here are some PowerShell cmdlet equivalents of Bash commands. Please try them out and document your work similarly to Step 4. Bash PowerShell ls -a Get-ChildItem -Force ls -al Get-ChildItem -Directory -Force echo Write-Host “ string mkdir New-Item -ItemType -Name -ItemType Directory touch New-Item -ItemType File -Force “ filename cat Get-Content mv Move-Item source destination cp Copy-Item source destination rmdir Remove-Item -Recurse -Force rm Remove-Item -Force history Get-History You may use the following set of commands as a guide, acknowledging that your output may be different.
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 11 Retrieve the directory listing of the current folder with Get-ChildItem . Figure 18: Executing the Get-ChildItem in PowerShell Like the “echo” command, write a string to the command line. Figure 19: Executing the Write-Host PowerShell Create a new directory, for example, IS-1003 , change directories to IS-1003 , create an empty new file in the IS- 1003 directory, write some output to the file, and check that the text exits in the file by outputting it to the screen. Figure 20: Executing the New-Item, Set-Location, Write-Output, and Get-Content commands Move the text file to the parent directory.
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 12 Remove the IS-1003 directory. Figure 21: Execute the Copy-Item and Remove-Item commands Output the history of your PowerShell session. Figure 22: Execute the Get-History command
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
© Mitra, Department of Information Systems and Cyber Security, UTSA, 2024 13 BREAKPOINT 5 Execute the commands in this section with definitions and screenshots. Specifically, above the screenshot(s), describe the command and its function (meaning, what does it do?). Wrap It Up! Complete the Introduction , Limitations/Conclusion , References , and Collaboration section of your report, using the instructions in the template. Remember to check for the overall quality of your writeup . Submit it in the Canvas Lab 03 | Navigating | Submission assignment folder. Well done! References [1] “Command line crash course - Learn web development | MDN,” Aug. 11, 2023. Available: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client- side_tools/Command_line. [Accessed: Jan. 21, 2024] [2] D. Kumar, “How to Open Windows PowerShell as an Administrator in Windows 11,” MUO, Dec. 31, 2022. Available: https://www.makeuseof.com/windows-11-powershell-administrator/. [Accessed: Jan. 21, 2024] Appendix | Additional Tips! Here are some handy shortcuts and tips to keep in mind: You can reuse previous commands without retyping them. One way to do that is to use the up and down arrow keys . Once a command is found using this approach, the line can be modified before the Enter key is pressed to execute the command. The TAB key will also auto-fill a command you are typing or suggest options to you. Begin typing your command or filename and then press Tab . This is particularly useful for long commands or filenames. You can list all the commands you’ve typed in a session by using the history command. This is helpful if you want to record the set of steps, or recall a prior step, or you want to troubleshoot an issue by seeing if you mistyped a command, etc. The clear command clears the terminal window to a clean slate. You can type CTRL-C to force stop a command/process. You can quit the terminal by using the exit command. The command-line method for getting help is the man command (short for "manual"). Enter the following to get more information about the mkdir command: man mkdir “Lab-03-Navigating” by Rita Mitra (2024). This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.