Uncategorized

Linux Commands

Spread the love

LINUX COMMANDS

  1. df –h: It is showing filesystems,size,used,available,use%,mounted

(which file we want see we need to be in that path and execute this command )

  • -T :  display the type of file system
  • -t ext3: it will display the only ext3 filesystems
  1. cd : change of directory
  •  /  : go to root
  1. dmesg : hardware information
  2. uptime : display the load average
  3. pwd  : present working directory
  4.  who : it display the how many numbers login
  • ami : current user working
  • am i(#tty) : current terminal with user
  • -b : last reboot time
  • -r : it display the run level
  1. ls : list of directories&files
  • -l : to find out which is directory and which is file “D” it indicate the directory, “-“ which indicate the file
  1. Touch filename : To create empty file
  2. Mkdir directoryname : to create directory
  • dir1 dir2 dir3 : successive directories
  • -p directoryname : create directories progressively
  1. cat filename : open the file
  • >filename : create text in file
  • >>filename: upend the text
  • f1 f2 f3 >f4: copy the text from previous file to the new file
  • f1 f2 f3.. : open the file in progressively
  1. cd.. :  go to one step back
  2. find /var –xdev –type f –ls |sort –rn –key=7 |head -10: 

       find command

  1. wc –l : word count
  2. cp sourcepath targetpath : copy from root
  • filename targetpath : copy from source
  • sourcepath  : copy from target
  • -r sourcepath targetpath : copy the directory from root
  • -r sourcepath/* targetpath : copy the all files&sub directories from directory
  • Filename filename.bkp(Date) : backup the file
  1. Move(mv) sourcepath(file) targetpath(directory) : to move the file                                            or directory
  2. du –sh : it shows the size of the file
  3. rm filename  : it is used to remove the file
  • -r file or directoryname : it is used to remove the multiple files and directories recursively
  • -rf file or directory name : : it is used to remove the multiple files and directories force bully
  • -rf file or directory name* : it is used to remove all the files and directories from the directory
  1. rmdir directoryname : it is used to remove the empty directories only
  2. head file name : number of pages from top of the file
  3. tail filename : number of pages from down of the file
  4. last : it shows the activity of the users
  5. ls –l |grep –l file or directoryname : it brings the specific file or directory for indentific either file or directory
  6. more filename : it shows the file content by line by line
  7. move(mv) oldfile or directoryname new file or directoryname : change the filename or directoryname
  8. cp –p filename targetpath : copy the same time stamp
  9. cpio source destination : this command copies only content of the file except inode and datablocks..By using this command avoid the unallocated space of the file it stores same size of the destination file 
  10. > /path of the file(ex:>/var/log/message): null the file

              Vi Editor

 Command mode

  1. Vi filename :  to create and edit the file
  • yy : number of lines copy
  • cc : number of lines cut
  • p  :past 
  • x  : delete a character
  • dw: delete the word
  • dd : delete the entire row
  • yw : copy the word
  • r  : we can replace the character
  • R : overwrite
  • cw :change the word
  • o :create new line below the curssor
  • O :create new line above the cursor
  1. Edit or insert mode
  • I or a  : before the cursor after the cursor for go to edit mode
  • Esc : go to command mode
  1. Excute mode :
  • :q! : without saving quit
  • :wq! : quit with save
  • Esc :go to command mode

Permissions for file or directory

  1. Chmod 755 directoryname : change the permissions(read write execute)
  2. Default file and directory permissions : file=664(umask 022, 666-022=644)directory=755(umask022,777-022=755)
  • Chown user:group directoryname
  1. Chmod –R 777 /tmo/pune/room/raja :change the permissions progressively
  • Permissions : read=4, write=2, execute=1
  1. Default permissions for file and directory : directory(755=drwxr-xr-x) file(644=-rw-r—r–)

      User Management

  1. useradd username : create user
  2. user default configuration file :  /etc/default/useradd
  3. groupadd groupname : create group
  4. useradd –u uid –g gid or gname –d /export/home/directoryname –s /bin/bash username : creating user and assaigning group
  5. lid –g groupname : open with group members
  6. groupmod –g newgid groupname : change the group id
  7. groupmod –g new groupname old groupname : change the group name
  8. cat/etc/passwd :it’s having user related information
  9. passwd username :  create and change password for user
  10. cat/etc/shadow : it’s having users password related information
  11. useradd –u uid –g gid or gname –m  –d /export/home/directoryname –s /bin/bash(shell)  username: creating user with user’s home directory and ownership
  12. usermod –G primarygroup ,secondarygroup(12,13…)username: creating secondary groups of the particular user
  13. chmod –g target gid username: it is used for change the primary group
  14. id –a username :it is used for check the use information
  15. passwd –S username: to know the particular user password status
  •  –l username: it is used for lock the user
  •  –u username: to unlock the user
  • -x no of days username : to set the password validity period
  • -x -1 username :it is used for unexpaired user
  • -d user name : it is used for delete the user password
  1. Userdel  username:it is to delete the user
  • -r username :it is to delete user with home directory
  1. groupdel groupname: delete empty group
  2. su username: change over from one user to another user
  3. putyy login: to log into another user
  4. telnet 0: change over from one user to another user
  5. useradd –D: it display the default user details
  6. cat /etc/default/useradd: user configuration file
  7. change –l username:to see particular user password, expire, warning etc status
  • -E username: to set expire date
  • -M username: to set max days
  • -m username: to set minimum dats of expire
  • -w username: to set warn days
  •  -d 0 username: user change passwd his self

  DISK & FILE SYSTEM MANAGEMENT

  1. #echo   ‘- – -‘  > /sys/class/scsi_host/host0/scan: it is used to intiate the disk partician to the kernal(update the luns form os level)
  2. fdisk  -l: it is used to know the disk information
  3. fdisk    /dev/sda(device name): enter in to the disk patrician
  4. mkfs.ext3(filesystemtype)    /dev/sdb1(devise name): create file system
  • mkfs   -t filesystem type(ext3)   device name(/dev/sdb1) : create file system
  1. mkdir    /fs1 (directoryname): create directory for mount
  2. #mount   -t ext3   /dev/sdb1 (devise to mount)    /fs1(mountpoint): mount the file system
  3. vi /etc/fstab: to permanent the mounted file system
  4. cat /etc/mtab: to check the mounted file system information
  • /proc/mount : to check the mounted file system information
  1. Unmount –a: unmount all file systems(it reads the /etc/mtab or  /proc/mount files)
  2. Mount –a: mount all file systems (it reads the /etc/fstab file)
  3. df –h: mounted file system information(it reads the /etc/mtab)
  4. blkid : mounted and un-mounted information

swap management

  1. mkswap  /dev/sdb1(device name): create swap devise 
  2. swapon   /dev/sdb1(device name) : create swap devis
  3. swapon   -s : to know the swap device information
  4. top  : to view the swap free space,used,total or check the system information
  5. free  -m or    #free -g     or #cat /proc/meminfo   or #top: to check the free space of swap
  6. dd   if=/dev/zero  of=/tmp/f1 bs=1M  count=1: create sized file
  7. swapoff   /dev/sdb1(device to mount)   : stop the swap device
  8. fdisk  /dev/sdb     and then command(m for help) t: change for swap id(82)
  9. monitoring Commands: #swapon –s, #free -m, #top

  PACKAGE & PATCH MANAGEMENT(package extension   .rpm)

rpm  -qa: check the all package

  •  -qi  package name: particular package installed
  • -ivh package name: package description after installation
  • -e package name: install a particular package
  • -uvh package name: remove the package
  • -ivh package name –force: upgrade the package
  •  -qi command path(/bin/ls): forcely install package
  •  -ivh package name –force –nodeps: to know which package  installed on particular command

PROCESS MANAGEMENT

  1. Jobs –l: forcely install the package without dependency(list of jobs)
  2. fg  job id: fore ground process(Restart the background stoped jobs)
  3. ps –elf: it display the running process information
  4. kill -9 pid no or pkil -9 processname: kill the process
  5. kill –l: list of signals
  6. nohup  cp source path  target path: this command breaks parent and child relationship

      service management

  1. service –status-all: it shows the total services information
  2. chkconfig –list: check modified services list
  3. service servicename(sshd) start or stop or restart: start or stop or restart the server
  4.  /etc/init.id/ service name(sshd) start or stop or restart: start or stop or restart the server
  5. chconfig service name (sshd) –level 0123456 on or off: on or off the server at certain level
  6. /etc/init.d/service status: to know the status of service
  7. Service service name(sshd) status: to know the status of service

Job management

  1. Date: it display the week date month year and time
  2. Tty: display the terminal name
  3. Which command name: it shows that command where it is located
  4. atrm job id: remove the atjobs
  5. at time: by using this command one time schedule the function of job
  6. atq or at –l: list of one time schedule time
  7. crontab –e: by using this command create repeated schedule the function of job
  8. crontab –l: list of repeated schedule the function of job
  9. /var/cron/logs: we can observe all executed cronjobs here
  • /var/log/cron(in linux): we can observe all executed cronjobs here
  1. cat /etc/crontab: it is configuration file of cron tab jobs

LOGICAL  VOLUME MANAGER (LVM)

  1. pvcreate   diskname(/dev/sdb): create physical volume
  2. pvdisplay  #pvscan: it will display the physical volumes
  3. vgcreate  name of vg   diskname(/dev/sdb): create volume group
  4. vgextend  vg /dev/sdc(diskname): extend the volume group
  5. vgdisplay: it will display the volume group information
  6. vgs: it will display the volume groups
  7. lvcreate  -L +200M (size)  vg -n lv: create logical volume
  8. lvdisplay: it will display the logical volumes
  9. lvdisplay  /dev/vgname/lvname    -m:it will display either it is stripted or lenear volume(cocandination)
  10. lvextend    -L +100M(size)  /dev/vg/lv: extended the logical volume size
  11. resize2fs  /dev/vg/lv: update the file system size
  12. lvcreate  -L +200M(size)  -I 2 (no of striped bit 1,2,3,4,6…)  vg -n lv striping: create striped logical volume
  13. remove   lvname: remove the logical volume
  • vgname: remove volume group
  • pvname: remove physical volume

                 mirror lvcreate

  1. lvcreate   -L +2G -m1   –corelog -n lvname    vgname for mirror lenearvolume: create logical volume in mirror lenear volume
  2. lvcreate   -L +2G -I2  -m1 –corelog  -n lvname vgname     for mirror striping: : create logical volume in mirror striped volume

 FILE SYSTEM ARCHITECTURE

  1. ls    -la: list of hidden files
  2. ls -a <folder name>: list of hidden files
  3. touch    .filename: create the hidden file
  4. ls   -li: list of inodes
  5. stat filename: it shows the ,size ,inodes , ioblocks ,links ,access  ,modify ,change of the file

    LINKS

  1. ln  (within the fs) backup the file: to create hard link
  • -s (across the fs) create shortcut: to create soft link

                 NETWORKING

  1. Ipconfig /all             note: it’s working in windows
  2. ping 127.0.0.1: to get ipaddress and related information
  • ping  ipaddress(192.168.1.19):   to check ip is working or not
  1. ifconfig   -a: to check the nic cards
  • ifconfig     eth0 or 1 2…: to check the specific nic cards
  1. ifup     eth: up the nic cards 
  2. ifdown  eth: down the nice cards
  3. ifconfig   eth 192.168.1.160(ip)    netmask 255.255.255.0 up: configure the ip
  4. vi  /etc/sysconfig/network-scripts/ifcfg –eth: permanent the configured ip
  5. cat   /etc/sysconfig/network-scripts/ifcfg – eth: open the configured ip info
  •  /etc/redhat-release: to see the current linux version
  •  /etc/issues: to see the current linux version 
  •  /etc/services: it display the all port numbers
  •  /etc/hosts: to see the ip address with its assigned hostname
  • cat /etc/services: it display the all port numbers
  1. service   service name  start ,stop or restart (syntax: service   network start,stop,restart): restart the server
  2. vi  /etc/hosts: to assign hostname to ip address
  3. uname –a: to assign the current linux version with hardware details too
  4. hostname: to see the current using host name
  • hostname  new hostname: to assign new hostname
  • -i : to see the ip address with which we logged in

           NETWORKING CONFIGARATION FILES

  1.  /etc/sysconfig/network-scripts/ifcfg-eth0
  2.  /etc/sysconfig/network
  3.  /etc/hosts

        NFS (Network File System)(it is used for centralised file system)

  1. Server
  • mkfs.ext3  /dev/sdb1 
  • mkdir  /nfs
  • mount -t ext3 /dev/sdb1 /nfs :to put fs details in /nfs
  • vi  /etc/exports           /nfs *(rw,async): it reads andshare the export fs
  • exportfs : it re-reads and share the export fs( it sharing more than one files)   
  • exportfs    -arv: list of export files
  • showmount –e:it showing yo had shared from how many hosts
  • showmount -e   server hostname: to perminant
  • vi /etc/fstab: nfs configuration file
  • /etc/sysconfignfs: nfs configuration file 
  •  /etc/exports
  1. nfs demons

  • nfsd (request&response for nfs clints):
  • mountd(give the authentication for client request)
  • statd(it works with lockd it provides the crass and recovery functions for the lock manager) 
  • lockd(it sends the locking request from client to nfs server)
  1. CLIENT 
  • mkdir   /arr : to create mount point
  • mount -t nfs  reddy-sys3:/nfs  /arr : mount shared fs
  • vi /etc/fstab    (/nfs /arr nfs     defaults 0 0 ): to  perminant
  1. to create centralised file system
  • we have to create ,mount point ,password,user,group, with the same gid,uid,password, and mount point of server

          AUTO FS  (it is used for centralised             home directory)

  1. CLIENT    direct map:
  • service autofs restart : it will restart the service
  • vi /etc/auto.master (/-      /etc/auto.direct –timeout=60)
  • vi /etc/auto.direct  (/mountpoint -rw,intr  raja-sys1:/mountpoint)
  • vi /etc/auto.direc (/mountpoint   -rw,intr raja-sys1:/mountpoint)
  1. CLIENT    indirect map
  • service autofs restart
  • vi /etc/auto.master (/mountpoint    /etc/auto.indirect –timeout=60)
  • vi /etc/auto.indirect(*-rw,intr   raja-sys1:/mountpoint)
  • automount   -v
  1. AUTO FS CONFIGARATION FILES
  •  /etc/auto. master
  •  /etc/auto. direct
  •  /etc/auto.indirect
  1. autofs demon
  • automountd

        NIS SERVER   (it is used for centralized login)

  • service ypbind start: configure the nis server
  • /usr/lib64/yp/ypinit  -m: to know the server bind with clint or not 
  • Ypwhich: it display the all remote users
  • ypcat  passwd
  1. NIS CLIENT
  • service    ip tables stop
  • setup (for authentication configaration ,here given the domain name & server name): to know the client bind with server or not 
  • Ypwhich: it display the all remote users
  • ypcat  passwd
  1. NIS CONFIGARATION FILES
  •  /etc/nsswitch.conf
  •  /etc/yp.conf
  1. NIS DEMONS
  • ypserv           (it have original source asky file by using those sky files create  maps) 
  • yppasswd     (Lets users change their passwords on the NIS server from NIS clients)
  • ypbind     (it will always bind with nis server when the nis server is demonism the ypbind automatically bind with another nis server)
  • ypxfrd       (Used to speed up the transfer of very large NIS maps)

            SCP (SECURE COPY)

  • DEF: secure copy is to copy files from one host to another host or simply across the systems of same platform
  • #scp source path  of sender hostname of receiver or ipaddr:/target path of receiving system: to copy files when we are in source path
  • #scp hostname or ipaddr:/source path            target path of receiving system : to copy files when we are in target path\

CONVERSION OF FILES TO ZIP AND VICEVERS

  • ******  to convert any file into zip or to compress first the file should be converted into .tar file to copy files when we are in target path
  •  tar -cvf  raja.tar (name of file)  f1 f2 f3 f4 f5 f6 (files to be zipped ): to create a .tar file   (raja.tar)
  •  tar -tvf         raja.tar (name of .tar file ): to view the .tar file
  •  tar -uvf    raja.tar f1  (file name to upend ): to upend a file or files
  • tar -xvf    raja.tar (tar filename): to extract a tar file
  • gzip  raja.tar: : to create gz file
  •  gunzip  raja.tar.zp: to extract the gz file
  • bzip  raja.tar: to create the bz file
  • bunzip    raja.tar.bz: to extract the bz file
  •  compress  raja.tar :to create the z file
  •  uncompress  raja.tar.z: to extract the z file

SUDO

  • vi /etc/sudoers      (%raja ALL=(ALL) ALL)   ex: sudo mkdir arr: all permissions are applied
  • /etc/sudoers (%india  ALL=(ALL) ALL) : group permission (sachin ,sehwag,dhoni,kohli,raina,rohith)   
  • /etc/sudoers  (%india ALL=(ALL)  NOPASSWD=ALL): now it’s never ask password befpre excuting new command  
  • /etc/sudoers      (%raja ALL=(ALL) mkdir,cat):he can excute those two commands only

    VARTUAL   IP’S

  1. ifconfig eth0:1 192.168.1.160/24 up (note:  class c netmask=/24): TO assign more than one ip to a single nic card is calle vartual ip      
  2. ifconfig eth0:2 192.168.1.161/24 up: to assign the vartual ip to a eth0
  3. cd /etc/sysconfig/netwrk-cripts cp ifcfg-eth0    eth0:1 vi ifcfg-eth0:1: create eth0:1 file and copy the content of eth0

     BONDING

  1. cd /etc/sysconfig/netwrk-scripts: create master file
  2. vi /etc/sysconfig/netwrk-scripts/ifcfg-bond1  (device=bond1,master=yes,onboot=yes,netmask,ipaddr,gateway,type): create slave1  
  3. vi /etc/sysconfig/netwrk-scripts/ifcfg-eth1   (device=eth1,slave=yes,master=bond1,onboot=yes,hwaddr): create slav2
  4. vi /etc/sysconfig/netwrk-scripts/ifcfg-eth2   (device=eth2,slave=yes, master=bond1,onboot=yes,hwaddr): it’s configuration file for bonding
  5. vi  /etc/modprobe.conf         (alias bond1 bonding nextline  options bond1 mode=balance-alb minimum=100): it’s update to the kernel
  6. modprobe   bonding
  7. service  network reload: it display how many nics having bond1
  8. cat  /proc/net/bonding/bond1

DEFAULT GATEWAY

  1. route add -net ipseris netmask gw : add gate way to the specific ipseris 
  • route dell gw : delete  gate way   
  • route add default gw : add default gate way 
  • route dell default gw : add default gate way  
  1. vi /etc/sysconfig/network-scripts/route-eth0         (ip series via gateway Ex 172.16.0.0 via 172.16.1.120): by using ssh authentication we can login in to another host without password in secure way.

SSH AUTHENTICATION(

  1. ssh-keygen  -t rsa: it will create .ssh,public and private keys
  2. touch   authorized_keys: the file create the our target host of from user home directory

ssh  username@target host: login in to host after complete of the above process 

Call us for Free Demo on AWS,Vmware,Citrix,Azure,Devops,Python,Realtime Projects
Calls will be forwarded to Our Trainers for demo

Leave a Reply

Your email address will not be published. Required fields are marked *