Sunday 16 June 2013

Basic Linux commands

Basic Linux commands

 

$ mkdir [ directory name ]

mkdir command is used to create new directory. Let’s create a example directory.

 
$mkdir example 
we can also use this command to make more then 1 directory at same time,
 
$mkdir -p a b c d e f g h i j k l
This command will create many directory at same time.

$mkdir -p a/b/c/d/e/f/g/h/i/j/k
This will create directory inside each other.

$mkdir -p a/{b,c,d,e,f,g,h,i,j,k}
This will create a directory "a" under many directory directory

$mkdir -p a/computer{b,c,d,e,f,g,h}networking
this command will create directory like this

 [root@localhost c]# mkdir -p a/computer{b,c,d,e,f,g,h}networking
[root@localhost c]# tree
.
`-- a
    |-- computerbnetworking
    |-- computercnetworking
    |-- computerdnetworking
    |-- computerenetworking
    |-- computerfnetworking
    |-- computergnetworking
    `-- computerhnetworking

8 directories, 0 files
[root@localhost c]#
 


 

$ cat [ file name ]


now create a file. Syntax for creating file is

$cat > [file name]
 
This command can be used in three way 
To see the contents of file
To create a new file
To append the contents of file.


$cat [file name] ------------------------ To see the contents of file


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

 

$ 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.


[root@localhost c]# cd /

 

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.

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.

 

mv

You can 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]

 

No comments:

Post a Comment