Can Any body gives the answer of these questions?
1. Make subdirectories called work and play.
2. Delete the subdirectory called work.
3. Copy the file /etc/passwd into your home directory.
4. Move it into the subdirectory play.
5. Change into subdirectory play and create a symbolic link called terminal that
points to your tty device. What happens if you try to make a hard link to the tty
device?
6. What is the difference between listing the contents of directory play with ls -l and ls -L?
7. Create a file called hello.txt that contains the words "hello world". Can you
use "cp" using "terminal" as the source file to achieve the same effect?
8. Copy hello.txt to terminal. What happens?

Dani AI

Generated

A concise walk-through that answers the numbered tasks, clarifies the confusion in posts by , and follows up on ’s suggestion with a safe, reproducible sequence and notes about what to expect.

Suggested sequence (run as your normal user; $HOME used so nothing touches system directories):

mkdir -p "$HOME"/work "$HOME"/play
rmdir "$HOME"/work        # only if empty; otherwise use `rm -r` with care
cp /etc/passwd "$HOME"/
mv "$HOME"/passwd "$HOME"/play/

To make the requested link to your controlling terminal: determine the device name with tty and create a symbolic link that points to that device (example uses the shell substitution so the link points to the actual tty for your shell). Creating a hard link from your home to a device node usually fails with an “Invalid cross-device link” on modern systems because /dev is normally a separate tmpfs/devtmpfs filesystem; hard links cannot span filesystems. If you really need another device node name, creating a device node with the same major/minor (eg. via mknod as root) is the supported alternative. (man7.org)

The difference between listing with long format and dereferencing links: long format without dereference shows the link itself (permissions, owner, and the arrow -> target). Using the dereference option makes ls show the target’s information instead. Use the dereference option when you want metadata for the file the link points at rather than for the link object. (gnu.org)

Behavior of cp and the tty link (questions 7–8): by default cp follows a symlink when reading a source (so copying from a symlink that points to a tty will attempt to read from that device and typically block waiting for input). Copying a regular file onto a symlink that points to a real device will open the device and write the file’s bytes to that terminal (so the text appears on that tty), subject to permissions. The cp manual also warns that copying special files or using options that read device contents can hang or have surprising effects. (gnu.org)

Quick examples you can try safely (do not run as root unless you know what you’re doing):

printf 'hello world\n' > "$HOME"/play/hello.txt
# copy the file to the device-link (this writes to the target tty)
cp "$HOME"/play/hello.txt "$HOME"/play/terminal
# try copying from the link as a source and observe that it will read from the tty device (it may block)
cp "$HOME"/play/terminal "$HOME"/play/from_terminal.txt

Notes and cautions: /dev is often managed by udev and mounted separately; creating hard links from $HOME into /dev will usually fail for that reason. Writing to another user’s tty requires appropriate permissions and may be denied or logged. (man7.org)

Recommended Answers

All 5 Replies

This sounds very much like homework. What have you tried and how have you failed?

actually the problem is in question 5 where i can't determine on what file or directory where i have to create symbolic link
And in ques. 7 how can i use cp command to put "hello world" in hello.txt using "terminal" as a source file?

You can change directory with the cd command. You can create links with ln command (look at the -s option).
As for 7, try to use cp on the symbolic link once you have it set up. Play around with it, try a few different things. You'll learn some things and get stuck on others. Once you are stuck, come back with more specific questions and we will help out some more.

what command should i use
ln -s play terminal
or
ln -s /dev/tty2 terminal

Try them. See what happens. A wonderful thing about computers is that you are free to manipulate them however you like. You will learn more by executing each of those commands then you ever will from me telling you which to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.