Saturday 21 October 2017

Basic Linux Commands


To check server uptime
[root@ducat Desktop]#uptime
To check which users has logged in on you server and there terminals
[root@ducat Desktop]#who
           Or
[root@ducat Desktop]#w
To check login details of the users
[root@ducat Desktop]#lastlog 
To check the linux operating system
[root@ducat Desktop]#cat /etc/redhat-release
To check the kernel of operating system
[root@ducat Desktop]#uname
                     uname –s    (only for kernel name)
                     uname –m    (machine architecture)
                                                  uname –a    (for complete details)
                     uname –n    (for computer name)
                     uname –v    (kernel version)
                                                  uname –r    (kernel release)
                     uname –i
                     uname –o    (OS name)
To check computer name
[root@ducat Desktop]#hostname
      Or
[root@ducat Desktop]#hostnamectl    (only for rhel 7 or centos 7)
To change computer name
[root@ducat Desktop]#hostnamectl set-hostname “redhatserver”
To check date and time of system
[root@ducat Desktop]#date
                  Or
[root@ducat Desktop]#timedatectl    (only for rhel7 or centos 7)
To change date and time of system
[root@ducat Desktop]#date 020114252014
                  Or
[root@ducat Desktop]#timedatectl set-time “2017-07-18 10:32:00”
To change timezone
[root@ducat Desktop]#timedatectl set-timezone “Asia/Kolkata”
To check available timezone
[root@ducat Desktop]#timedatectl list-timezones
To check the calendar of current month
[root@ducat Desktop]#cal
                        cal -3      (last, current and next month)
                        cal 2014    (year)
                        cal 5 2014  (specific month of the year)
To print hardware details
[root@ducat Desktop]#lspci
To print cpu details
[root@ducat Desktop]#lscpu
To check the directory structure
[root@ducat Desktop]#dir
      Or
[root@ducat Desktop]#ls
[root@ducat Desktop]#ls –l or ll (for complete details)
[root@ducat Desktop]#ls –lh   (size in human readable formate)
[root@ducat Desktop]#ls –la   (print hiden files and folders)
To check the working directory
[root@ducat Desktop]#pwd
To create a directory
[root@ducat Desktop]#mkdir
To create directory tree
[root@ducat Desktop]#mkdir –p /test/{a/{ab,ab1,ab2},b,c}
To change working directory
[root@ducat Desktop]#cd directory path
                     cd    (switch into home directory)
                                                  cd ..       (Execute parent directory)
To remove directour
[root@ducat Desktop]#rmdir directory name
To create empty file
[root@ducat Desktop]#touch file name
To check the contents of file
[root@ducat Desktop]#cat file name                     
To rename file
[root@ducat Desktop]#mv koko.txt koko1.txt
To copy file
[root@ducat Desktop]#cp koko1.txt /kuldeep/1/a
To show the directory tree
[root@ducat Desktop]#tree /kuldeep/
To move file
[root@ducat Desktop]#mv koko1.txt /kuldeep/2
To delete directory
[root@ducat Desktop]#rm -rf /kuldeep1?
To delete all directories starts with kul keyword
[root@ducat Desktop]#rm -rf /kul*
To show the history
[root@ducat Desktop]#history
To print last number of commands
[root@ducat Desktop]#history 5
To check the login user name
[root@ducat Desktop]#whoami


Saturday 16 September 2017

conditional execution of commands in linux

if the first command is executed successfully then execute the second command in linux
example
       if the kuldeep folder is present at your working directory then this will create test.txt file in this folder.
[root@localhost~]#ls -ld kuldeep && touch kuldeep/test.txt

if the first command does not execute successfully then execute the second command in linux
example
      if the kuldeep folder is not present at your working directory then this will create it
 [root@localhost~]#ls -ld kuldeep || mkdir kuldeep

pls put your comments and suggestion.

Friday 15 September 2017

how to search a keyword and replace in linux using vim text editor

[root@localhost ~]# vim testfile.txt
# go to the execution mode of vim
:%s/keyword/neword/ig
#option i is use for ignore case
#option g is use for global search
#only draw back is this will not match exact keywork you use this as
:%s/\<keywork\>/newword/ig
#this will match exact keyword and replace with new.

Thursday 14 September 2017

how to set login message in linux

[root@localhost~]#vim /home/msg.sh
#!/bin/bash
dialog --title "welcome message"\
           --infobox "welcome $USER. welcome to linux system.\
                            your login time is ( `date`)" 7 50; sleep 5
:wq
[root@localhost~]#chmod +x /home/msg.sh
[root@localhost~]#vim /etc/profile
#"at the end of file"
/home/msg.sh
:wq
now log out your user then relogin it


pls put your comment and suggestion.

how to set time for internet use

this will allow internet access for a particular time interval. R4(config)#int f0/0 R4(config-if)#ip nat inside R4(config-...