Exercise #1
-
Re-make for yourself up to 3 Unix commands, one (or more if you wish) from each group from the given list below. The system calls you will likely need to use are listed after the command you may re-make. "
open(2)
" means to read the online manual for open in section 2, i.e. use the command "man 2 open
" at your prompt. Your commands may be relatively simple (i.e. cp only needs to copy a single file for example,) but the more complete the better. With no options, your program should print a usage message and terminate. Your programs should also print a more detailed help/manual if--help
is given on the command line.Note that you will need to check for error conditions and print appropriate status messages. You may use
perror(3)
for this. -
Create a
Makefile
that can compile all your programs.
Group one:
cp
/ cat
/ more
:
open(2)
- open and possibly create a file
close(2)
- close a file descriptor
read(2)
- read from a file descriptor
write(2)
- write to a file descriptor
Group two:
ls
/ tree
/ du
:
-
stat(2)
,lstat(2)
- get file status
-
statx(2)
- get file status (extended)
-
Note there is no C wrapper to the
readdir(2)
system call, so if you want to read a directory of files, use:opendir(3)
/readdir(3)
orscandir(3)
scandir(3)
is probably easiest to use.
Group three:
mv
:
rename(2)
- change the name or location of a file
link
/ ln
:
link(2)
- make a new name for a file (hard link)
symlink(2)
- make a new name for a file (symbolic link)
rm
/ unlink
:
unlink(2)
- delete a name and possibly the file it refers to
mkdir
:
mkdir(2)
- create a directory
rmdir
:
rmdir(2)
- delete a directory
chmod
:
chmod(2)
- change permissions of a file
readlink
:
readlink(2)
- read value of a symbolic link
kill
:
kill(2)
- send signal to a process
touch
:
utime(2)
- change file last access and modification times
creat(2)
/open(2)
- open and possibly create a file
Group four:
stat
:
stat(2)
,lstat(2)
- get file status
statx(2)
- get file status (extended)
uname
:
uname(2)
- get name and information about current kernel
uptime
/ free
:
sysinfo(2)
- return system information
df
:
statfs(2)
- get filesystem statistics