Sunday 15 April 2012

Understanding Basic Linux Commands





Mode of Login 



There are two mode of login
    1. Text Mode  (Alt+ctrl+F1)
    2. Graphical Mode (Alt+Ctrl+F7)
In case of Text Mode
Station2 Login : root
Password : redhat
[root@station2~]#
to switch from one text mode to another
Alt+Ctrl+F1 to Alt+Ctrl+F6
In case of Graphical Mode
Ctrl+Alt+F7

Common Commands

Some of the Common system command are as follow:


1. Date : to display date and time
2. Cal : to display the calendar
3. Cal 11 2006 : display the calendar of Month 11 and year 2006
4. Clear : To clear the screen
5. ls : to list directory contents
color identification
blue : Directories
White : Files
Green : Executable files
Red : Zip files, rpm, tar file
Different switches used with “ls” command

ls –l or ll : used for long listing including file and directory permission
            (-) : file
            (d) : Directory
            (l) : Symbolic link

ls –a  : shows all hidden files and directory. Any file followed by (.) is hidden file

ls –al : show all hidden files and directory with long listing or whole description

ls –d : shows all the directory

6. pwd: Print  working directory

7. who am I : display the information of current terminal  

8. who : display all the terminal in a network

9. history : it shows all the command your have used.
By default history stores last 1000 command which u have run. If u want to change
# vi /etc/profile
HIST SIZE =10
Save and exit
# history –c ( to clear all the previous command reside in history)

Creating file and Directory:
  1. Creating file:
The ‘cat’ command is used to create a file
Syntax:
# cat > filename
example:
# cat > abc.txt
(Ctrl +D) is used to save the file.

  1. View the content of file
Syntax:
# cat  filename
Example:
#cat abc.txt
#cat –b abc.txt

  1. Creating Directory
The ‘mkdir’ command is used to create directory
Syntax:
Mkdir [directory_name]
Example:
# mkdir jeet
Option used:
cd : To change directory
cd .. : To come out from directory
cd : to jump to root directory
cd - : to jump to previous directory

Deleting Files and directory:
Syntax:
For file:
rm <filename>
example:
rm abc.txt
for directory
syntax:
rmdir <directory_name>
Note: Only empty directory will be deleted)
If we want to delete the tree structure of directory then we need to use the following command
Syntax:
rm –rf  <directory_name>

where
r = recursively
f= force

In order to remove non empty directory
Syntax:
rm –r <directory>

example;
rm –r jeet
this will remove directory step by step ,first remove  sub directory and then finally main directory.

Another method of creating file :

Touch : this command is used to create a blank file with size zero.
# touch <filename>
Example:
#touch abc

Copying File and Directory:


  1. Copy file:
Syntax:
# cp [source]filename [destination]

  1. Copy directory
#cp –r [source]directory [destination]
to copy a directory into another directory recursively

  1. cp –rf [source]directory [destination]
to copy a directory forcely

syntax used for copy file or directory:
cp [option] file destination
option:
-I : interactive : ask before overwriting file
-r : Recursive
-p : Preserve
-f : forcely

More than one file can be copied at a time if the destination is directory
Syntax:
cp [option] file1 file2 file 3 Destination

Moving and Renaming File and Directory:

Syntax:
# mv : move /rename files and directory

Example:
# mv [option] file destination

example:
# mv t.txt /home/jeet/
more than one file can be moved at a time if the destination is a directory

# mv [option] file1 file2 file3 destination

Thanks ,

2 comments: