Friday, June 27, 2014

Basic commands

The Commands which are basically use to operate an Operating System(O/S) is called Basic Commands.  

1) pwd :  present working directory ---> used to know the path of present user.

2) ls : list ------>It gives the list of files & Directories present in the path


3) ls -l or ll --------> Listing of all files along with attributes


4) ls -a ------> Lists all hidden files & directories


5) ls -r -------> lists all files & directories in reverse mode


6) ls -il---------> lists all files & directories along with inode numbers


7) ls -ld < directory name> ------> to view attributes of a particular directory


8) ls -R <directory.name> -------> to view tree structure of a directory


9) ls -a* ----------> to view all files & directories starts with a


10) man < command> ---------> to view entire options of a command


To create a file we have 3 methods :

1) touch

2) cat

3) vi(vim)

1) touch : With the help of touch command we can create an empty file.
    
      syntax: touch < filename>
        
             ex: touch f1

   with this command we can create n number of files at a time.
       
           syntax: touch  <file1> <file2> <file3>
           ex: touch mahesh raju naveen

2)cat:  By using cat we can create data-files
   
     syntax: cat > <filename>
         ex: cat  >mahesh
             
              (edit data)
             ( ctrl+d)(to save)

 To view content of a file

    
           cat < filename>

To add data in existing file


           cat >> <existing filename>
       
            (enter-data)
            (ctrl+d)

we cannot edit the written text through cat command. we can only add data to modify existing data we have to use editors. we have number of editors in linux

      
             ex: gedit ,nano, kedit, kate, emacs ,vim ,etc...
  
   Note : but we always use the best editor "vim" editor .

we can transfer an output as input for another file
        
           ex: to view output of file1 file2 we use 

                    cat file1 file2
 In the same way, we can transfer output of that command as input for another file 
    
           ex: cat file1 file2 > file3
here we are giving file1 file2's data as input for file3 , by this data of file1&file2 will copied into file3.

Linux Basic Commands

Linux Basic Commands 



                   Command
Description
1. logname
Current user name
2. pwd
Present working directory
3. uname
Display kernel name
4. uname -n
Print network hostname
5. uname -r
Display kernel version
6. uname -v
Display kernel release date
7. uname -i
Print hardware platform
8. uname -o
Print the operating system
9. uname -p
Print the processser name
10. uname -a
Print all information
11. date
Display system date and time
12. clear
To clear the screen
13. cal
Display current month calendar
14. cal 2014
Display 2014 calendar
15. cal 9 1987
Displays the September 1987 calendar
16. bc
Open calculator
17. bc -v
Version of calculator
18. hostname
Display server name
19. hostname -i
Display server IP address
20. tty
Display terminal name
21. who
To display how many users connected to server
22. whoami
Display current username
23. uptime
Display how long server is “up &running”, no. Of users connected &avg load on the server.
24. which <command name>
Show the full path of command
25. whereis  <command name>
Display the binary, source, and manual page files for a command
26. find
Search for files in a directory hierarchy
 
       27.   set system date and time
            # date -s “yyyy-mm-dd hh:mm:ss”
      28.   To view help for a command (manual pages)
 
           # man <command>
 29. Viewing list of Files & Directories:
          Syntax : # ls  <options>   <file>
                   Options:     
                                    -a    --> To check the hidden object


                                    -l    --> To list the properties of an object

           

                                    -s    --> To check the size in block


                                    -r    --> To check reverse order


                        -R   --> List Sub directories Recursively


                                    -Q   --> To see files in double quotes


                                    -m   --> List of entries with comma separated

                   Eg :- 
                                                # ls -a


                                                # ls -la


                                                # ls -lr
Working with Files:-
   
                      A collection of data is called file. In linux – platform, CAT, Touch, vi are some at the default commands. To create a file, but there are some differences between these three commands.

30. Cat (concatenation):
                     This command is used to create single file with data and also to check the data of exiting file, but we cannot modify the data.
Create a file :
                        # cat > file


                           -------------


                           -------------


                        ctrl+d (save & quit)
31. Open the file:
                # cat < filename


                             or


               # cat filename
32. To append the file:
                 # cat >> filename


                        ---------------------

           

                        --------------------


                     ctrl+d (save & quit)
33. To open multiple files:
               # cat file1 file2 file3

 Disadvantages:
               Using this command we can't create multiple files and we can't edit the text at the file.
 Touch:
                This command is used to create multiple files, but are empty files and also it use to change date and time of an existing files and directories.
34. To create multiple files:
             # touch  f1 f2 f3
Disadvantages:
                Using  this command we can't modify the text of the database files.
       35.   change current Date and Time: 
             
                               # touch f1
       36.  Change Time stamp of a file or directory
Syntax
 
              # touch <option> <argument>  <file/directory>


              # touch –t  YYYYMMDDHHMM  <file/directory-name>

Deleting the files :
  37.          “rm” command is used for remove files
 38.           # rm <filename>
 39.          # rm -i <filename>   -->  asking confirmation
 40.          # rm -f <filename>   -->  delete file forcibility.
 41.        Remove multiple files at once
           # rm <file 1> <file 2> <file 3>
Working with Directories:
        “mkdir” (Make Directory) command is used for creating Directories.
      Syntex:   # mkdir  <option>  <Directory name>
  
  42.         To create a Directory
                            # mkdir <dir name>
  43                   Creating multiple directories
                                    # mkdir dir1 dir2 dir3
  
 44.                Creating nested tree structure (sub directories inside directories)
                                    # mkdir -p world/asia/india/ap/hyd/kphb
45.              To check nested directories
                                    # ls -R world  
                                        (or)
                                 # tree world
Removing Directories:
46.                           “rmdir” (remove directory) command is used to delete an empty directory.
                                 # rmdir <dirname>
47.             “rm -r” command is used to delete recursively entire directory.
                                # rm -r <dirname>
48.                           # rm -ri <dirname>   --> asking confirmation message
49.                           # rm -rf   <dirname>   --> remove forcefully.
Navigation Commands:
  50.                      # cd         --> To change a directory
  51.                     # cd  ..   --> To move one level back
  52.                    # cd ../.. -->  To move two levels back
  53.                    # cd -          --> To go to the previous working directory
   54.                   # cd   <space-bar>    --> To go to the users home directory
   55.                   # cd <dir-name>       -->  To move to the particular directory.
Copying files and directories :

            “cp” command is used to copy file or directory from one place to another.

 56.                                           To copy a file
                                    # cp file1 file2  
57.                                        To copy a file into directory
                                    # cp file1  dir1
58.                                   To copy multiple files into a directory
                                    # cp file1 file2 file3  dir1
59.                                       To copy a directory
                                    # cp -R <source directory>  <destination dir>
                                    # cp -R dir1  dir2
Move and Rename – Files and Directories :
                        “mv” (move) command is used to move files and directories from one place to another, and also this command is used to rename the file and directories.
            Syntex:   # mv <option>  <source>  <destination>
  
60.                                                 To move a file
                                    # mv file1 dir1
61.                                               To move a directory
                                    # mv dir1 dir2
62.                                                 Renaming file and directory
                                    # mv  <old name>  <new name>
Creating hidden files and directories :
  To hide a file start file name with “.” character
   63.                       # cat  > .filename
   64.                      # mv  file1  .file1  (To hide existing file)
   65.                      # mv  .file1  file1  (To unhide a file)
   66.                      # mkdir  .dir1   (To create hidden directory)
   67.                     # mv .dir1 dir1    (To unhide a directory)
                                   
 68.          # ls  -l (or ll )     (Display longlist format, i.e, with 9 fields)
(i) File type,  where '-' is a file  and  'd' is a directory.
(ii) permissions of file or directory
(iii) Number of links  (l)  --> link file
(iv) owner  of the file
(v) Group of file
(vi) File size in bytes
(vii) Creation data of file
(viii) Creation time of file
(ix) Name of file
 Identify Files & Directories with colors:
         
                        # ls  -l
                                     Files          -     Black
                                    Directories  -    Blue
                                    Links           -     Skyblue
                                    Zip              -     Red