Tuesday 16 October 2012

Some Useful commands In Linux/Unix



There are few commands which are frequently used and we stuck for those command.
I have listed some of the basic commands used frequently.


1) Search string or word in a file in a specified directory:


find /path/to/dir -type f -exec grep -l yourstring {} \; 


2)

Find files by name

a) locate -i filename :This command searches in database.here -i is ignorecase.(This is Fast)
b) find filename        : It searches the file system.(This is slow)

3) Find process and kill particular process.

a) ps -ef | grep tomcat :
Shows running tomcat process details.
command explanation : -e stands for list all process and f formats output view.Output of ps -ef
is given to grep command which search given string in the given output.

b) kill pid : This command will kill the process. If process still not stopped then use kill -9 pid

command.

4) Check the available space on disk:


  df -h : Outputs total space utilized and free space available. -h stands for human readable 
format e.g. mb,gb etc.

5) Check the size of file or directory in linux


  du -ah path : Display the size of directory. “-a” stands for show file along with size and “h”  

for human readable format like mb,gc etc.

6) How to send mail in Linux


mailx -s "Subject line" me@you.com <message.txt : Before firing this command check  

sendmail  is running with command service sendmail status.

7) Installing software in linux is based on different linux flavours


a)RedHat,Fedora,CentOs : yum install software name  e.g yum install sendmail. yum 

command is for rpm packages
b)Ubuntu : apt -get software name  e.g apt -get sendmail. apt command is used for debian 

packages.

8) How start service in linux


  service start servicename :Starts the tomcat service e.g service start tomcat
 service status servicename : Check status of service.
 service stop servicename : Stops the service.

9) Change permission of file or directory in linux:


Below is good link for understanding file permission. Tead it once so concept will be clear 

forever.
http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilesp.html

10) Cut paste file from one location to other (move file from one dir to other)


     a) mv file.txt directorypath/  : Move file.txt  to given directory path
        b) mv file1.txt directorypath/file1.txt  : Move file.txt to directory path and rename it to

file1.txt

11) Renaming file in linux : same mv command is used for renaming file.


mv file.txt file1.txt : As path file.txt and file1.txt is in the same directory mv utility will 

understand it’s a renaming file not moving.

12) Deleting file and folder in linux:

    rm -f filename : Delete file . -f option tell that don’t prompt message like “are you sure you 
want to delete this file?”.
   rm -rf directorypath : This command delete directory. -r will delete subdirectories as well 
-f is explain above.
  rm -f ./*.log : This command will delete all the files in current directory with extension .log.


Also check below links :


No comments:

Post a Comment