Operating System : Programming Concepts
Young Man Asked A Rich
Old Man , How He Made
His Money
The Old Guy Said
Son, It was 1932, The depth
of the Great Depression
I Was Down To My Last Nickel
I Invested That In An Apple
And Spent The Entire Day
Polishing It & At The End Of The
Day, I Sold The Apple For 10 Cents
The Nxt Day ,I Invested Those
10 Cents In 2 Apples. I Spent The
Entire Day Polishing Them &
Sold Them For 20 Cents
I Continued This 4 A Month, By The
End Of Which I Had Accumulated
A Fortune Of $.1.37
Then My Wife's Father Died &
Left Us 2 Million Dollars
MORAL :
Hard Work Is Just Shit
Find A Chick Whose Father Is Rich
Lab 1 : FileSystem
Q?what are files
/>files are just the collection of
bytes
Q?what is filesystem hierarchy
/>
→ Oridinary
files : this are the files in which system imposes no
particular structure. They are used for text
documents(also program source code)
→Directory files : this are the container into which other files
and directories can be placed
→ Special files : this
are the files which communicate with running processes and also allow
other processes to communicate with hardware devices
Q?what are special filesystem commands
/>
“/” → root directory
“.” → current directory
“..” → parent directory
“/home/myfile/file.txt” → absolute path
“myfile/file.txt” → relative path
“name.extension” → files
Note *: hidden files name start with “.”
Q?what is the datastructure of the file
/>File are represented in a datastructure and it is called Inode
/>It consist of :
>unique
identification number type
of file : ordinary / directory / special file
>owner id (UID) and group id (GID)
>size and path
>times for last access/modification/status change
>permissions
>number of links to the Inode
Q?what are the types of link
/>there are two main types of links
/1>hard links : command → ln
/2>soft links : command → ln -s
Q?what are hard links
/>always pointes to the same Inode of the file
/>hard links only works for files and not directories
/>If the real copy is deleted the link
will work
Q?what are soft links
/>contains absolute or relative path to a file or directory
/>if real copy is deleted the link will not work
Q?what kind of permission exists for accessing the file
/>we have mostly three kinds of permissions
/1>Read(r) : file listing can be done
/2>Write(w) : we can create or delete a file here
/3>Exec(x) : we can run , directory scanning can be done here
this
permissions are grouped into Owner,
Group, Others
Commands :
shows the manual page of the linux commands
$ man man
print current working directory
$ pwd
change directory
$ cd <NewDirectoryName>
$ cd / → go to root directory
$ cd → go to your home directory
files
and directoires listing
$ ls
$ ls -a → list also the hidden files
create directories
$ mkdir <list of directories name>
copy files and directories
$ cp <source> <destination>
moving or rename files and directories
$ mv <source> <destination>
remove files and directories
$ rm <file name>
$ rm -r <directory name>
common options that can be used for rm, cp , mv are :
-r → recursive (delete the content of directory and subdirectory)
-i → interactive (ask conformation to delete each file)
-f → force (doesn't ask confirmation)
change
directory/file permission
There are two modes for this action :
Numeric mode :
r: 4
w: 2
x: 1
$ chmod 644 test.txt
644 → 1(r)1(w)0(x)(user)-1(r)0(w)0(x)(group)-1(r)0(w)0(x)(other)
Symbolic mode :
$ chmod u+x
//i.e. we add for user the executable permission
displaying
files
$ cat <files>
→ concatenate files and print on the standard output
$ head [-n <#rows>] <file>
→ output the first part of files
$ tail [-n <#rows>] <file>
→ output the last part of files
Editing softwares are :
gedit- emacs - vi
file statistics:
$ wc → print newline, word, and byte counts for each file
Q?What is gcc compiler
/>GNU compiler collection includes the front ends for C and C++
$ gcc [options] source_code -o executable_file_name
$ gcc -Wall myprogram.c -o mycommand
Lab 1 Exercise – Files, directories and permissions
try this out “Do You Like Me ... ?
Breathe For 'YES',
Lick Your Elbow For 'NO' ”
Learning goals: this laboratory activity is meant to
practice with the most common commands
for interacting with the file system. The commands are: ls, cd, mv, cp,
rm, chmod, less, mkdir, wc. Other commands introduced are gcc, man.
1.Create the following directory tree in your home directory (man
mkdir for details about how to create a directory).
Remarks:
•
Work on the local disk. Do not
use flash drives or similar storage devices;
• Use the TAB key to exploit the
auto completion feature of the shell;
2.Move inside the src directory and perform the following actions:
1.Create a simple C program, main.c, able to get the number of words of
a text file. Text file has to be passed as parameter in the command
line, and copy it in the src directory.
2.Copy the main.c file you have just created into test, script and
result directories staying in the current src directory. Once done,
verify the existence of the file
using the less command
(man less for details about the less command) and then delete them without
moving from the current directory. Then, move to the parent directory so_es1
and redo the same actions
(copy, verify existence and delete);
3.In point 2.2 you used the cp command for copying files. What’s the
difference with the mv command?
(type man mv for more details about the mv command)
4.Compile the main.c file using the following command line: gcc –Wall
main.c –o myWC .
What’s the purpose of the –Wall option?
5.Correct any compilation error and verify the existence of the myWC
executable file.
6.Verify also that the file execute permission is set for the owner of
the file. If the executable permission is not set, use the proper command
to make it executable (man chmod for details about changing file permissions).
Once done, move the binary file myWC into the bin directory;
3.Move inside the test directory and perform the following actions:
1.Download the test01.txt file. Save it inside the test directory and then edit
it adding your student details
2.Execute the myWC executable you generated through gcc in step 2.4, passing it
the test01.txt file you have just downloaded; The command for running
the myWC executable is the following: ../bin/myWC test01.txt
3.The output should be the number of words of the test01.txt file. Why do
you need to specify a full pathname (../bin/myWC) to the executable
file in order to execute it?
4.Execute the following command: wc test01.txt
5.Compare the output of this command with the output you obtained in step 3.2.
How we can only get the number of words using wc command?
Comments
Post a Comment