Question

In: Computer Science

Task 1: Getting familiar with Unix commands Questions: How do you remove a directory and all...

Task 1: Getting familiar with Unix commands

Questions:

  1. How do you remove a directory and all of its contents, including any subdirectories and files, without using rmdir repeatedly?         [5 Points]
  2. Go to your home directory (i.e. /home/) and enter the following command: ls -ali
    Explain the output. You need to clearly what each column specifies, what are the values in each column means. Also explain how it is different from: ls -li    [5 Points]
  3. How will you copy directory (not an empty directory) from one location to another? [5 Points]
  4. Consider a file which consist of:

    12
    21
    113
    54
    213
    4
    23

    How do you sort the numbers in ascending order? [5 Points]
  5. Consider the contents of 3 files as:

file1

Cherries Jackfruit Apples
Fig
Honeydew
Blueberries

file2

Boysenberries Grapes
Pineapple
Eggfruit Cucumbers

file3

Dates Elderberry Apricots Entawak Cantaloupe Bananas

  1. You need to sort all the fruits from the 3 files in descending order and save the content in the file4. All these operations have to be done in a single line.                                           [5 Points]
  2. You need to sort all the fruits from the 3 files in descending order, sort them and then save all the occurrences of the word “Apple” along with their index in file4. All these operations have to be done in a single line.                                           [5 Points]

The contents of file4 for case(a) and (b) are as follows:

Pineapple
Jackfruit
Honeydew
Grapes
Fig
Entawak
Elderberry
Eggfruit
Dates
Cucumbers
Cherries
Cantaloupe
Boysenberries
Blueberries
Bananas
Apricots
Apples

1:Pineapple
17:Apples

Solutions

Expert Solution

1) rm -r
   Above command will remove all the contents of the directory recursively including all
   of its subdirectories and files.

2)  
   root@tryit-gorgeous:~# ls -ali                                                                                                                       
   total 0                                                                                                                                              
   1838 drwx------ 1 root root 24 Aug 30 07:04 .                                                                                                      
      261 drwxr-xr-x 1 root root 150 Aug 30 07:03 ..                                                                                                     
   19488 drwxr-x--- 1 root root   6 Aug 30 07:03 .config                                                                                                
   19492 drwxr-xr-x 1 root root   0 Aug 30 07:04 hello
                                                                                                  
   root@tryit-gorgeous:~# ls -li                                                                                                                        
   total 0                                                                                                                                              
   19492 drwxr-xr-x 1 root root 0 Aug 30 07:04 hello

   Output meaning of above line :

   19492 : inode number

   d : first character after inode number represents the type of file.
       'd' for directory.

   rwxr-xr-x   :   these nine characters represent permission of current item.
                   first three represent permission for file's owner, next three
                   permission for members of file group, and last three permission for others.
                   r : read permission ; w : write permission ; x : execute permission
                  
   1 : this number represents number of hard links to this item.

   root : this field represent the item's owner. in this case 'root'

   root : this field represnt the group this item belongs, in this case 'root'

   0 : size of item in blocks

   Aug 30 07:04 :   this field represent date and time when item was last modified

   hello : this field represent name of the item, in this case 'hello'


   The only difference in between 'ls-ali' and 'ls-li' is the use of 'a' option in first
   command. Which lists all the items including entries starting with '.' also.
   In this case items with name '.', '..' and '.config' are also listed when first command
   executed.


3)   cp -rp old_directory name new_directory_name
   This command will copy one directory to another location.
   -r command will copy recursively all contents of old directory.
   -p will preserve the old permision and timestamp.
  
4)   sort -n file.txt
   above command will sort the file in ascending order.
   -n is used in case the file consist of numerics.

5)  
   a)   sort -r file1 file2 file3 > file4
       -r option is for sorting in descending order
  
   b)   sort -r file1 file2 file3 | grep -in apple
       this command will give the desired output.
       grep command is for searching strings in files.
       -i : this option ignores the case.
       -n : this option will display line index number.
  


Related Solutions

UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
What are the UNIX commands for each of these steps? 1. Copy all of the files...
What are the UNIX commands for each of these steps? 1. Copy all of the files in your Files directory to the Backup directory. 2. Create an ITE130 directory in the Classes Directory 3. Move all the ITE 130 files from the backup directory to the ITE130 directory. 4. Redirect echo step 19 to mark this step in the lab3.txt file 5. Display all of the directories and sub-directories including files so I can verify you completed all the above...
What are the UNIX commands for each of these steps? 1. Delete all the files in...
What are the UNIX commands for each of these steps? 1. Delete all the files in the Classes and Backup directories only. 2. Redirect echo step 23 to mark this step in the lab3.txt file 3. Display all of the directories and sub-directories including files so I can verify you completed all the steps correctly. 4. Repeat the above step and redirect the output to the file lab3.txt without erasing what is already in it! 5. Redirect echo step 26...
Unix ramdom question. How do you display a list of files in your current directory, sorted...
Unix ramdom question. How do you display a list of files in your current directory, sorted by file size with the largest files at the top.
1. Compare the Unix directory and the windows directory and answer the following: a. Match 3...
1. Compare the Unix directory and the windows directory and answer the following: a. Match 3 Unix directories to a Windows directory that is similar in function. Briefly describe their similarities and differences. b. Find a directory in Unix that appears to have no equivalent in Windows. What does it do? c. Find a directory in Windows that appears to have no equivalent in Unix. What does it do?
QUESTION 1 Match the following LINUX/UNIX commands with what they do. du    whereis users who...
QUESTION 1 Match the following LINUX/UNIX commands with what they do. du    whereis users who am i A. display a compact list of users currently logged in B. locate the binary, source, and manual page files for a command C. summarize disk usage D. who am i currently logged in as on the Linux server. QUESTION 2 What rm command option (flag) would you use to remove a file that begins with a - (hyphen)? -f -p --   ...
Use Kali Linux Commands to show me the following: 1. Who are you? 2. Change directory...
Use Kali Linux Commands to show me the following: 1. Who are you? 2. Change directory to Downloads 3. Make a new directory 4. Make a new text file under your name (Ghada.txt) 5. Write a paragraph about Cyber security (4 to 5 sentences) >>simply open the file and write inside it 6. Change the permission to be 764 7. Open the file but with a cyber security match Show me each and every step with figure b. Enter into...
Unix/Linux Turn in the following commands and any output from the commands. 1) ll to show the original 3 files
Unix/LinuxTurn in the following commands and any output from the commands.1) ll to show the original 3 files2) run the tar command to stuff three files3) ll to show the 'tar archive'4) mkdir newdir to create a new directory to unstuff the 'tar archive'
Please answer all the questions Thank you 1. Why shouldn’t you use a screwdriver to remove...
Please answer all the questions Thank you 1. Why shouldn’t you use a screwdriver to remove a heat sink? 2. What is the minimum voltage of an electrostatic discharge (ESD) that you can feel? 3. What is the voltage range in which ESD can affect electronic components? 4. What was the operating temperature of the CPU? 5. Why is it important to double-check the bottom of the heat sink before attaching it to the CPU socket?
Task 1: Remove Number Complete the function remove number such that given a list of integers...
Task 1: Remove Number Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2: Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT