Wednesday, December 11, 2013

Linux Basic Command and Options with Example


1.Shell :
            Operating system to User intermediate

            #cat /etc/shells
                 /bin/sh         => Shell
                 /bin/bash     => Bourn Again Shell
                 /bin/tcsh      =>
                 /bin/csh        => C Shell
                 /bin/nologin   =>  NoLogin shell

2. Kernel :
            Hardware to Operating system monitoring

3. [Root@Server6 ~]#  or $ :

            Root        => Indicate to which User
            Server6   => Indicate to Hostname
            ~    => Indicate to Home Directory
            #    => Indicate to Root Privilege
            $     => Indicate to Normal User Privilege

4. F.S.H  ( File System Hierarchy ) :

            /root     => Root Home Directory
            /boot    => Only stored Boot files
            /home  => Normal users Home Directory
            /bin       => Stored in Binary files or Executions files
            /lib        => Library files or Documentations
            /etc       => All Configuration files stored in this directory
            /var       => Variable Directory. Used to share the contents ( FTP, HTTP…)
            /mnt     => Used to default mount point for Disk Partitions
            /media => Mount Point for External Devices ( CD/DVD, USB, Pendrive…)

5. Help and Information for Commands :

            MAN  =>  Format and Display online manual copy.
                 # man ls        
                 # man mkdir

            INFO  =>  Read full Documentations.
                 # info ls
                 # info cd

            PINFO  =>  Small Graphical Page.
                 # pinfo ls
                 # pinfo cd

            --HELP or  -?   =>  Small Information.
                 # ls –help
                 # ls -?

            WEBPAGE  =>  It display webpage Documentations.
                  File:///usr/share/doc

6.  LS Command :

            Options :       -l => Long List
    -a => Display All Files.
    -d => Display Present Directory Information
    -h => Human Readable.
    -f  => Display File Type.
    -R => Display sub directory to recurs.
            # ls –alh
            # ls –R
            # ls –d .

7.  PWD Command : ( Present Working Directory )

            # pwd
               /root.

8.  WHOAMI Command :  ( To identify which user login for Terminal)

            # whoami                   # whoami
               Root.                           Shyam.

9.  LOGNAME Command : (The real user who logs in initially)

            # logname                      # su - shyam
               Root.                             # logname
             # whoami                         Root.
                root                              $ whoami
                                                          shyam

10.  HOSTNAME Command : ( to check the computer name )

            # hostname
               Server6.


11.  UNAME Command : (to check  OS, Version, Architecture, Hostname etc..)

            Options  :  -a, -s, -n, -r, -v, -m, -p, -I, -o
           
            # uname
               Linux.
            #uname –a  ( all )
              Linux server6.example.com 2-6.32-131.0.15.el6.x86_64 ……………………
           
12.  CD Command : ( to use Change Directory )

            # cd       => go to home directory
            #cd ~     => go to home directory
            # cd /var/www/html/       => go to html directory
            #cd ..                         =>  back to one directory
            #cd -                          => forword to directory

13   ID Command : ( Identification, to check UID and GID )

            # id
               Uid=0(root) gid=0(root)  groups=0(root)
            # id shyam
               Uid=500(shyam) gid=500(shyam) groups=500(shyam)

14.   TTY Command : (Psuedo Terminal, to check the user login and terminal)

            Terminal 0 :
            # tty
              /dev/pts/0

            Terminal 1 :
            #tty
              /dev/pts/1

15.   CLEAR Command : ( to clear the terminal screen )

            # clear

16.   DATE Command : ( Display the Date and Time )

            # date     => to display date and time
            # date –s   2011-12-05  => change only date
            # date –s   5:30:20         =>  change only time

17. CAL Command : ( Display the Calendar )

            # cal    => to display current month
            # cal 2011  => to display 2011 an all month
            # cal 12 2011   => to display month 12, year2011


18.   WHICH Command : ( Show the full path of commands/shell)

            # which ls
               /bin/ls
            #which  chown
              /bin/chown

19.   WHATIS Command : ( Search the full database for complete words )

            # whatis w
              Who is logged on and what they are doing
            #whatis ls

20.   WHEREIS Command : ( Locate the Binary, Source, Manual page for all commands)

            # whereis ls
               Ls: /bin/ls   /usr/share/man/ma1/ls.1.gz   /usr/share/man/man1p/ls.lp.gz

21.   WALL Command : ( Broadcast on the message send to all logged in user on the system)

            # wall
               Hai Pls reboot.  => type the msg.

            CTRL + D   => Exit

22.   WC Command : ( Word Count, word counting cmd)

            Options  :   -l => line count ,    -w => word count,     -c => byte count,     -m => character count
            # wc –l /etc/passwd
            # ls | wc –l

23.  TOUCH Command :  ( to create Empty File or 0byte file )

            # touch file1
            # touch /home/shyam/shyam.txt
            # touch file{1..5}.txt
            # touch file1 file2 file3 file4 file5

24.   CAT Command :  ( Canonical system )

            # cat file1 => show the file1
            # cat > newfile1.txt             => create new file.
            # cat >> newfile1.txt          => overwrite new content

25.  HISTORY Command : ( to shows the all typed commands )

            # history
            # ! serv                     => to run service httpd restart
            # !55                          => to run 55 command

26.   MKDIR Command : ( Make Directory )
           
            # mkdir test            => create directory under the PWD
            # mkdir /var/www/html/pc1.linux.com/   => create to directory under the html.

27.   MORE Command : ( It shows small paragraph )

            # more /etc/httpd/conf/httpd
            #more /etc/passwd

28.   LESS Command : ( it display simple method, scrolling function available)

            # less /etc/httpd/conf/httpd
            # less /etc/passwd

29.   HEAD Command : ( it shows 1st few lines of the text, By default 10 line )

            # head /etc/passwd           => By default 1st 10 line
            # head -5 /etc/passwd      => to display 1st 5 lines
            # head -20 /etc/passwd => to display 1st 20 lines

30.    TAIL Command : ( it display last few lines of text, By default last 10 line )

            # tail /etc/passwd                => By default last 10 lines
            # tail -15 /etc/passwd        => to display last 15 lines
           
            # tailf /var/log/httpd/access_log   => view log files while it is being updates

31.    UNIQ Command : ( Identify any duplicate line entries in a file or input provider )
           
            Options  :  -d , -i
            # vim shyam.txt  => type any content
            # uniq shyam.txt =. To check

32.    STRING Command : (Find and Display legible information embedded within a non-text or binary file)

            # string /bin/cat
            # string /bin/mkdir

33.    CP Command : ( Copy File, Copy the file/Directory one location to another location as same copy )
           
            Options  :  -I, -r, -p
            # cp shyam.txt   shyam.txt.back  => take the copy and change the name
            # cp shyam.txt   /var/ftp/pub/shyam.txt  => copy to another location
            # cp /root/shyam.txt   /var/ftp/pub/shyam.txt  => same as above, it is another method
            # cp –I /root/abc.txt   /tmp/abc.txt  => copy time ask Yes or No
            # cp –p /root /abc.tcxt   /tmp/abc.txt  => permission, time, ownership copy to same
            # cp /root/*   /tmp/  =>  copy all
            # cp /root/.txt  /tmp/  => only copy .txt contents
            # cp –r /root/*   /tmp/  => copy at recursive  

34.   MV Command : ( Used to Move / Rename the file or directory )

            # mv /root/shyam.txt   /root/aaa.txt  => rename the file
            # mv /root/shyam.txt   /var/ftp/pub/shyam.txt  => move the file to another location

35.   RF Command : ( Remove the File / Directory )

            Option  :  -f => Force,    -r => Recursive
            # rm shyam.txt  => Remove the file
            # rm –f shyam.txt => Remove the file forcibly
            # rm –r shyam.txt => Remove the file and ask the Yes or No
            # rm –rf shyam.txt  => Forcibly removing

36.   STAT Command : ( File/Directory Statistics or Properties)

            # stat /root
            # stat/root/shyam.txt

37.   File / Directory Attribute Settings :

            lsattr  => Listing ,     chattr  => Modifying    ( + set the value,   - Unset the value )

            Options  :  -a, -i,….
            # lsattr /root/shyam.txt
               -----------e- shyam.txt

            #chattr +ia shyam.txt
               ------ia----e- shyam.txt

#chattr -ia shyam.txt
               ------ia----e- shyam.txt

38.   Pattern Matching : GREP  ( Global Regular Expression Print )

            # grep “shyam” /etc/passwd
               Shyam:X:500:500: :/home/shyam:/bin/bash

            # grep “shyam” - -color /etc/passwd            
           

            # grep “root” /etc/passwd  /etc/shadow
               /etc/passwd => root:X:0:0:root:/bin/bash
              /etc/shadow => root: :15253:0:9999:7: : :

            # grep ^root /etc/passwd  => ( to display startins word for root all entries )

            # grep bash$ /etc/passwd  => ( to display last word or sentence )

            # grep ^root$ /etc/passwd

            # grep –i shyam /etc/passwd  => ( to ignore all letters)

            # cut –f2 –d “ : “ /etc/shadow       
            # grep “shyam” /etc/shadow
            # grep “shyam” /etc/shadow | cut –f2 –d “ : “

39.   Symbols :

Ø     => Overwrite the file’s
>>      => Appending the file’s
|        => Pipe
&&    => AND Option 1st is true then go to 2nd option
||      => OR any one condition is true

40.    USER Administration :

            UID :  0 => root,     1 to 499 => System Services,      500 above => Normal Users
           
           User Account file and Directory :
            /etc/passwd,    /etc/shadow,    /etc/groups,    /etc/gshadow,    /home/users,    /var/mail

1.       /etc/passwd :  user1: X: 500: 500: Regular Comments: /home/user1: /bin/bash
User 1                  => User name
X                            => Password place holder
500:500               => UID and GID
Comments        =>  Use any Comments, Hai welcome etc…
/home/user1   => User Home Directory
/bin/bahs           => User Shell
        
2.       /etc/shadow :  user1: $6$BY$JKJJ9789N…: 15265: 0: 99999: 7:  :  :
User1                   => User name
$6$jhvjh….         => Encrypted Password
15265                   => Last changes day ( Epoch time Jan 01 1970 )
0                                           => Minimum days
99999                   => Maximum days
7                            => Warning days
:                             => Inactive days
:                             => Disabled day
:                             => Feature use

3.       /etc/group  :   user1: X: 500:  :
User                     => User name
X                            => Password place holder ( /etc/gshadow)
500                        => GID (Privet GID )
:                             => Group members


42.   USERADD Command :  ( Add a new user )

         Option :      -c => Comments
                                -o => non-unique (  to use duplicate UID in normal user )
                                -u => UID ( we have to prefer UID )
                                -s => Shell ( to change shell )
                                - r => system account ( to use system service accounts )
                                -g => GID ( to use duplicate GID in normal users )
                                -e => Expire date ( given to the account expire date )
                                -p => Password ( given to the Encrypted password )
                                -d => Home Directory ( change to home directory)          
         # useradd user1  => Normal creation
         # userad  –c Hai  –o  –u 605  –s /bin/csh user2  => Add Comments, UID, Shell
         # useradd –r user3  => Encrypted Password
         # useradd  –g 700   -e 2011-11-01  -d  /var/www/html/user4  user4  => Add GID, Expir date, Home                                                                                                                         directory
         # useradd  -s /sbin/nologin   user5  => Use nologin

         # passwd user1

1.       User Login Information :
# vim /etc/login.defs
2.       Default Useradd Functions :
# vim /etc/default/useradd


No comments:

Post a Comment