In: Computer Science
Task 1: Getting familiar with Unix commands
Questions:
file1 Cherries Jackfruit
Apples |
file2 Boysenberries
Grapes |
file3 Dates Elderberry Apricots Entawak Cantaloupe Bananas |
The contents of file4 for case(a) and (b) are as follows:
Pineapple |
1:Pineapple |
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.