Friday 7 October 2011

Basic Linux commands cp mv rm mkdir cat cd command example

In this assignment I will demonstrate some basic commands which are required to perform day to day task by user. In our last assignment we created a normal user named Vinita. Now login from Vinita, and try to find out what are the difference you noticed when you login from normal user.
normal user login linux
In bracket right most side is showing user name Vinita and beside @Server is the hostname of computer and further ~ sign is showing that user is presently logged in her home directory. But first, every Linux user has a home directory. You can use the tilde (~) to represent the home directory of any currently active user. For example, if your username is Vinita, your home directory is /home/Vinita. If you have logged in as the root user, your home directory is /root. Thus, the effect of the cd ~ command depends on your username. For example, if you have logged in as user Vickey, the cd ~ command brings you to the /home/Vickey directory. If you have logged in as the root user, this command brings you to the /root directory. You can list the contents of your home directory from anywhere in the directory tree with the ls ~ command. After bracket you can see the command prompt of normal user is $ sign.
Command Syntax

$mkdir  [ directory name ]
mkdir command is used to create new directory. Let’s create a example directory.

$mkdir example
$ls
example
now create a file. Syntax for creating file is

$cat > [file name]
This command can be used in three way to see the matter of file, to create a new file or to append the matter of file.

$cat [file name] ------------------------ To see the matter of file
$cat > [file name]---------------------- To create a file
$cat >> [file name ]-------------------- To append the matter of file
Be little bit careful while using cat > command to create new files. If you accidently used this command with existing file it will overwrite the matter of file. Use CTRL+D to save the matter of file.
Different use of cat command

$cat > test
This is test of file
$cat test
This is test of file
$cat >> test
This is second line
$cat example
This is test of file
This is second line in test file
$cat > test
Now file will over write
$cat test
Now file will overwrite
basic  linux commands

$cd [ destination directory path]
It is easy to change directories in Linux. Just use cd and name the absolute path of the desired directory. If you use the relative path, just remember that your final destination depends on the present working directory.
basic linux commands
as you can see in the output of ls command file is in white color and directory is in blue color.
There are two path concepts associated with Linux directories: absolute paths and relative paths.
An absolute path describes the complete directory structure based on the top level directory, root (/).
A relative path is based on the current directory. Relative paths do not include the slash in front.
The difference between an absolute path and a relative one is important To know more about path and directory structure

pwd
In many configurations, you may not know where you are relative to the root (/) directory. The pwd command, which is short for print working directory, can tell you, relative to root (/). Once you know where you are, you can determine whether you need to move to a different directory.

$cd ..
this command is used to exit from current directory.

0 comments:

Post a Comment