WS1.1-OS Intro

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Preparation

1. What will happen if you type man man in Linux?

Answer: This command displays the manual page for the MAN program

2. How can you use the command ls to find out about the size of the file /etc/lilo.con?
Answer: The command ls -l/etc/lilo.con will list in long format, giving mode, number of
links, owner, group, size in bytes…
3. What happens to the files in the command mv file1 file2 ? Which option of mv
issues a warning?
Answer:If I just enter "mv file1 file2" when both files are present in the current
directory, file1 will overwrite file2. Only one file, file2, which contains the contents of
preceding file1 will remain after this process. When a move will overwrite an existing
target, the command "mv -i file1 file2" will ask for confirmation. "mv: overwrite file2
(yes/no)?" is what it appears to be. If the response is yes, the action should be taken.
Any more responses halt mv's attempt to overwrite the target.

4. What is the command that you issue if you are in directory / and want to copy the file
/mydata to directory /labdata?
Answer: cp -r mydata labdata

5. What is the command that you issue if you are in directory / and want to copy all files
and directories under /mydirectory to directory /newdirectory?
Answer: The task may be completed with the commands cp -r mydirectory
newdirectory or cp -avr mydirectory newdirectory. When using the "cp -r" option, the
directory and all of its contents, including any subdirectories and their files, are copied
recursively to the destination. The "cp -R" option is identical to "cp -r," except pipes are
duplicated rather being read from.

6. What happens when you type rm * in a directory?


Answer: All files in the current directory will be deleted with the command "rm *,"
which will also list all of the current directory's subdirectories. It looks like" Rm: subfolder
is a directory". You won't be removing the subdirectories.

7. What is the command used to delete all files and directories under the directory
/mydirectory?
Answer: The command "rm -Rf /mydirectory/*" or "rm -rf /mydirectory/*" will be used.
The "-r" or "-R" options recursively delete directories and subdirectories in the argument
list. These commands remove directories and subdirectories under /mydirectory. Without
asking the user first, the "-f" option deletes all files in a directory, whether they are write-
protected or not.

This question covers basic file manipulation. To begin this question use the first button to set
up a small file and directory tree in /home/caine. The resulting tree looks like:
/
+--- home
|
+--- caine
|
+--- test1
| +--- file1
| +--- file2
| +--- file3
| +--- file4
|
+--- mydir1
| +--- info1
| +--- info2
|
+--- data
| +--- data1
| +--- data2
|
+--- lines
+--- words
+--- info
8. Bottom of Form
9. COPY file1 from test1 to data. Keep the name as file1.
10. COPY file2 from test1 to data. Change the name as you copy the file to the new
name of filecopy1
11. Rename info1 to newinfo1. Do not move it out of mydir1 ?
12. Change directory into mydir1, and then copy "lines" into the current directory.
13. Still in mydir1, concatinate info2 and lines, saving the output as "joined".?
14. Still in mydir1, concatinate info2 and lines and file1 from test1, saving the output as
"joined2".?

Classwork

Exercise 1:
In the console or terminal window, type the following LINUX commands on the command
line.
Note and write down the results
$ ls
$ pwd
$ps
$ cd ..
$ pwd
$ cd /usr/local
$ ls
Exercise 2:
Execute the following command and explain the meaning of each of them.
• ifconfig
Ifconfig (interface configuration) is a network management tool. It is used to configure and
view the status of the network interfaces in Linux operating systems. With ifconfig, you can
assign IP addresses, enable or disable interfaces, manage ARP cache, routes, and more.
• route –n
Route command in Linux is used when you want to work with the IP/kernel routing table. It is
mainly used to set up static routes to specific hosts or networks via an interface. It is used to
show or update the IP/kernel routing table and Route -n to display the routing table in full
numeric form.
• hostname
Hostname command in Linux is used to obtain the DNS(Domain Name System) name and
set the system's hostname or NIS(Network Information System) domain name. A hostname
is a name which is given to a computer and it attached to the network.
• cat /proc/cpuinfo
This command is used to show information about the CPU.
• free –m or top
free displays the unused memory and -m, – -mega : It displays the amount of memory in
megabytes. top command is used to show the Linux processes. It provides a dynamic real-
time view of the running system. Usually, this command shows the summary information of
the system and the list of processes or threads which are currently managed by the Linux
Kernel.
• dpkg ‐l
The dpkg command acts as a front-end for the following two tools:

1. The dpkg-deb command, which shows information about .deb packages.

2. The dpkg-query command, which shows the information from the dpkg
database.

The action -l is a dpkg-query action that lists all packages from the dpkg
database. The dpkg command detects the foreign options and runs dpkg-query
automatically.
• uname –r
Unix Name is abbreviated as uname. In Linux, uname is a helpful tool that displays hardware
and software information about the current system and -r using to display the Linux kernel
release info
Exercise 3:
In your home folder, create a folder tree as following. Note that, the rectangular describes a
folder and the circle represent for a file. You can add any information into your created files.
- Create file Hello.java in folder Java and add whatever you want into that file.
- Copy file Hello.java to folder OS and rename it to newHello.txt

Exercise 4:
- Create a file named user.txt. Then, you add n usernames (each in one line, n>=5).
(cat >)
- Display the content of file user.txt (cat )
- Display list of n sorted usernames in your file and store that sorted list into a new file
named suser.txt (sort)
- Count the number of users in your file and display it.

You might also like