Home » , , » Basic Linux commands cp mv rm mkdir cat cd command example

Basic Linux commands cp mv rm mkdir cat cd command example

Written By 1 on Saturday, February 5, 2011 | 1:04 PM

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.


cp
The cp (copy) command allows you to take the contents of one file and place a copy with the same or different name in the directory of your choice. For example, the cp file1 file2 command takes the contents of file1 and saves the contents in file2. One of the dangers of cp is that it can easily overwrite files in different directories, without prompting you to make sure that's what you really wanted to do.
basic linux commands

mv
While you can't rename a file in Linux, you can move it. The mv command essentially puts a different label on a file. For example, the mv file1 file2 command changes the name of file1 to file2. Unless you're moving the file to a different partition, everything about the file, including the inode number, remains the same.

rm
rm command is used to remove the regular files. It will ask before removing files.

rmdir
it will remove the empty directory. If directory is full then use rm –rf [directory name]
basic linux commands

0 Comment:

Post a Comment