Unix Tips

60
rate or flag this page

By Brownaryan


How to know the path of your current woking directory.

You can know the path of your current working directory by typing the 'pwd' command i.e. present woking directory. This will give you the full path from home directory till the user's curent working directory.

How to remove a file in Unix.

You can remove a file by using the 'rm' command. It can be used with different options or switches e.g.

$ rm -i filename

This command removes the file interactively i.e. before deleting the file system asks for the user's confirmation.

'rm' when used with -f option removes the file forcibly.

For removing a directory following command can be used:

$ rm -r directoryName

All contents of directoryName are recursively removed and finally directoryName also gets removed.

How to compile a single source file

You can use the -c option to compile the C source file. e.g

% gcc -c filename.c

In the above command 'gcc' is the C compiler. As an output to the above command an object file named filename.o will be formed.For C++, instead of gcc you should use g++.

Program Exit Codes

When a program ends, it indicates its status with an exit code. The exit code is a small integer; by convention, an exit code of zero denotes successful execution, while nonzero exit codes indicate that an error occured.

With most shells, it is possible to obtain the exit code of the most recently executed proggram using the special $? variable. In the following example 'ls' command is invoked twice and its exit code is printed after each invocation. In the first case ls executes correctly and returns the exit code zero. In the second case, ls encounters an error ( because the file name specified on the command line does not exist) and thus returns a non- zero exit code.

% ls

filename.c filename.o

% echo $?

0

% ls invalidFilename.c

ls: bogusfile: No such file or directory

% echo $?

1

How to use calculator in Unix for calculations

You can invoke calculator om Unix by typing 'bc' at the shell prompt. Once you type 'bc' at the prompt you are in the calculator mode and the $ prompt disappers. Calculator takes the input line by line. e.g.

$bc

2*5

10

quit

You need to type quit so as to come out of the calculator mode.

How to check the disk free space

To know how much of the disk is being used and what part of it lies free you can use 'df' command (for disk free). This command reports the free as well as used disk space for all the file systems installed on your machine.

$df

/ (/dev/root ): 12950 blocks 27877 i-nodes

As an output to the above command you can see that it shows only one file system i.e. the root file system is installed on the machine. df shows the number of free disk blocks and free inodes for this file system also.

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working