Sunday, 14 October 2012

Practical no-1:Execute various file/directory handling commands


Practical no-1:Execute various file/directory handling commands

To list the files in a directory
$ ls

Here's a sample directory listing:

bin           hosts         lib           res.03
ch07          hw1           pub           test_results
ch07.bak      hw2           res.01        users
docs          hw3           res.02        work

To view the content of a file
$ cat hosts

prints out the contents of a file called hosts:
127.0.0.1       localhost          loopback
10.8.11.2       kanchi.bosland.us  kanchi
10.8.11.9       kashi.bosland.us   kashi
128.32.43.52    soda.berkeley.edu  soda

You can specify more than one file as follows:
$ cat hosts users

If the users file contains a list of users, this produces the following output:
127.0.0.1       localhost          loopback
10.8.11.2       kanchi.bosland.us  kanchi
10.8.11.9       kashi.bosland.us   kashi
128.32.43.52    soda.berkeley.edu  soda

ranga
sveerara
vathsa
amma

To get a count of the total number of lines, words, and characters
contained in a file
$ wc .rhosts

produces the following output for my .rhosts file:

7 14 179 .rhosts

To make a copy of a file use the cp command.
$ cp test_results test_results.orig

To change the name of a file use the mv
$ mv test_result test_result.orig

changes the name of the file test_result to test_result.orig.

To remove files use the rm command
$ rm res.01 res.02

removes the files res.01 and res.02.

To find out what the current directory is, use the pwd
$ pwd

/home/ranga/pub

tells me that I am located in the directory /home/ranga/pub.

You can use the cd command to do more than change to a home directory:
$ cd /usr/local/bin

changes to the directory /usr/local/bin. Here, you used an absolute path.

You can create directories with the mkdir command
 $ mkdir hw1

creates the directory hw1 in the current directory. Here is another example:
$ mkdir /tmp/test-dir

This command creates the directory test-dir in the /tmp directory. The mkdir command produces no
output if it successfully creates the requested directory.

To copy a directory, you specify the -r option to cp.
$ cp -r docs/book /mnt/zip

copies the directory book located in the docs directory to the directory /mnt/zip. It creates a new
directory called book under /mnt/zip.

to move files and directories
$ mv /home/ranga/names /tmp

moves the file names located in the directory /home/ranga to the directory /tmp.

You can use rmdir to remove directories:
$ rmdir ch01 ch02 ch03

removes the directories ch01, ch02, and ch03 if they are empty. The rmdir command produces no output
if it is successful.

No comments:

Post a Comment