Wednesday 17 August 2011

Renaming files in Unix

Following are the commands used for renaming files in Unix,

1) $mv fileoriginal filerenamed

The above command is used to rename the file with name, 'fileoriginal' to the new name, 'filerenamed'.

2) $mv diroriginal dirrenamed

The above command is used to rename directory.

Creating files in Unix

There are 2 ways to create files in Unix. They are as follows,

1) touch
2) cat

1) touch

Syntax: $touch filecreated

The above command creates an empty file with the name 'filecreated'. This is mainly used when there is a need to create more empty files.

Eg: $touch filecreated1 filecreated2 filecreated3

In the above example, totally 3 empty files will be created in the given names.

2) cat

Syntax: $cat > filecreated

Press Enter, then type lines you want to be in the file 'filecreated'.
Press Ctrl+D for End of Line (EOF).
It saves the file and again it comes into $ mode.

Other usages of cat:

1) $cat filecreated

This command will display the contents of file, 'filecreated'.

2) $cat filecreated1 filecreated2 > filemerged3

The above command will store the contents of 'filecreated1' and 'filecreated2' in the file, 'filemerged3'. The contents of 'filemerged3' is overwritten.

To append the contents to the file, 'filemerged3', use the below command,

$cat filecreated1 filecreated2 >> filemerged3


Unix File System

Unix treats and understands everything as a file. For a beginner, lets consider unix is made of files and directories.

Here is Unix file structure,




















Each folder has its significance here.

unix -> Unix kernel is available here
bin -> Executable files for unix commands are found here. These files can be written in C program or Shell program.
lib -> Has all library functions provided by Unix for programmers.
dev -> Contains files that control various I/O devices like terminals, printers, disk drivers etc..
usr -> It has a directory for each user. Created by sys admin while creating an account.
tmp -> Stored temporary files created by users/Unix. These files are deleted at the time of restart and shutdown.