Search This Blog

Tuesday 15 September 2015

Basic Linux Commands used daily


Navigation :
  1. To print working directory :  pwd
  2. To change directory            :  cd
  3. To list files and contents of directories :  ls
  4. To list files/direc in long format : ls –l
  5. To list the hidden files/direc : ls –a
  6. To view text files : less  text_file
  7. To know what kind of a file it is : file name_of_file
Manipulating Files:
  1. To Copy files and directories :   cp file1 filenew
  2. To move or rename the files/directories : mv  file1  filenew
  3. To remove the file/directories :   rm file
  4. To make directory : mkdir

Working with commands:
  1. Display Information about command type: type  command(ls,cp..etc)
  2.  To locate the command : which command (ls…etc)
  3. To display the reference page: help –m  command(cd..etc)
  4. To display on-line command interface : man ls
I/O Redirection :
  1. To redirect standard output to a file   : “ > “    ( ls  >  file_list.txt )
  2. To redirect standard output to a file   : “ < ”    (sort <  file_list.txt > sorted_file.txt)
  3. With pipeline the output of one command is fed into input of another :
             ls –l | less   
  rpm –qa| grep –i filename :   Rpm –qa  list  for all rpm files installed on system and  Grep Accweb  it  find any containing the string “accweb” and output them.

  1. Filters:
sort : Sorts standard input then outputs the sorted result on standard output.
grep : Examines each line of data it receives from standard input and outputs every line that contains a specified pattern of characters.
tail : Outputs the last few lines of its input. (Ex : tail –f logs.txt)
Permissions:
  1. to change the permissions of folders/files : Chmod  XXX filename
  2. Temporarily become super user : su & sudo
  3. Change file ownership of user :  chown  user filename
  4. Change file ownership of group : chgrp  group filename
  5. Change file ownership of user & group : chown  user:group filename

Job Control:

  1. To know the process running  : ps  or jobs
  2. to know the processes running on system   : Ps  aux
  3. to find process with user  :           Ps  –u  name of User
  4. to kill the process   : Kill -9  process name
 -9   Kill signal
-1   hang-up signal
-2 interrupt signal
-15 termination signal


Wildcards:
  1. Matches any characters  :  *
  2. Matches ant single character:  ?
  3. All filenames  :  *
  4. All filenames that begin with the character "g" :  g*
  5. All filenames that begin with the character "b" and end with the characters ".txt" : b*.txt


Txt Editor:

  1.  to edit the configuration/txt  file (command line)  : vi/vim 
  2.  gedit is the editor supplied  (GUI)  : gedit
Searching:
  1. Search  file by name  : Find -name "query"
  2. Search file by type   : Find  -type  type_descriptor_query
                 Type decriptor :
F -  regular file
d- directory
I -symbolic link
  1. Search  :  locate filename
  2. We can use  locate/grep for searching :
grep  "codes"  install.log   : searh for word/string/line  in a file   (grep –n ,display with line number, grep –I it search for case sensitive )
grep -i  "codes"(Search string)   /root/install.log (path of file)
[root@localhost ~]# grep "codes" install.log
Installing iso-codes-3.16-2.el6.noarch

Remote Administration :
  1. Can use ssh with a full hostname to connect to a remote machine : ssh hostname
  2. Connect to a remote system with your current username :ssh username@hostname
  3. Allows you to copy files from one computer/server to another computer/server : scp

Other Commands:
  1. To know which user is logged : whoami
  2. To know who recently  logged : users
  3.  
  4. history : for monitoring commands executed by user.
  5.    Service :  for  start/stop/restart/status (Service httpd start,service red5 stop,…etc)
  6. Top : to monitor system activities
  7. df    - to know disk file space on machine (df –h  size in GB,df –m  sizein MB )
  8. fdisk –l  - to  display with partitions
  9. Netstat : give information about network connections (nestat –tcp  display all tcp connections)
  10. Mount – for mounting formatted partitions

Basic Network Commands :   

  1. Netstat :   to look up the various active connections within a computer
  2. Traceroute : to know the number hop it travelled to reach destination.
  3. Nslookup:   It is use for DNS quiery.
  1. Dig : It is use for DNS quiery.It display full info.
  1. Ifconfig  :  It is very useful in determining what could be wrong with a network.to know IP address.
  2. Ifup:  enable interface
  3. Ifdown : disable interface.
  4. Ping :  PING is used to check for a response from another computer on the network.
  5. Ping  -c  hostadress :
  6.  



What command used to check Disk Space ?

1 Command to know disk space  :  df                
2 Command to know size in GB  :  df -h
3 Command to know size in MB  : df -m

How to change the Ownership of file/Group?

ls -lart tmpfile
-rw-r--r-- 1 himanshu family 0 2012-05-22 20:03 tmpfile

Before using command :

Command to change Ownership of file:  chown  root  tmpfile

Command to change Ownership of group : chgrp  friends tmpfile


After using command above:
ls -l tmpfile
-rw-r--r-- 1 root friends 0 2012-05-22 20:03 tmpfile



What command used for finding the process running?

Command to see processes running   :  ps
Command to find the process run by user :  ps -u  Sukesh

What  Command to kill a process ?
                            Kill -9    process name

-9   Kill signal
-1   hangup signal
-2  interrupt signal
-15  termination signal

Search for a file by name ?

Find -name "query"

Search the file by type?

Find -type type_descriptor query

Type decriptor :
F -  regular file
d- directory
I -symbolic link


How  to know which user is logged?

Command :   whoami

Who recently  logged in?

Command  : users

How do we transfer file from one server to another?

          Command used  to establish ssh connection :   ssh  username@ IP

How we move file from one folder to another?

                            Command :       Mv   file name   remote folder path

How do we copy file from one folder to another folder?

                            Command:      cp  filename  remote folder path

What command use for add interface?

                  Command :            ifup
What command used fo remove interface?

                  Command :      ifdown

To know Current working Directory ?

Command used  : Pwd

Command to give permissions?

Chmod XXX  filename

permissions diagram



777   rwx rwx rwx

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4

Chmod 777 filename

REST API

  API  is an application programming interface. It is a set of rules that allow programs to talk to each other. The developer creates the AP...