Sunday, November 11, 2012

Useful Linux Commands

1. Copy Files
    cp -r [copy location] [to location] 
    ex. cp -r /home/myDocuments/* /mysystem/sharedFolder

2. Remove directory
     rm -r [folder Name]

3. Check the folder size
    du -hs /mysystem/myfile/server/default/deploy/anyfile.ear

4. zip the file1.
     Go to the directory
        zip -r [requiredName].zip [FolderName]

5. move folder
    mv [folderName] [DestinationLocation]

6. Check java memory
    ps -eO size,pcpu|grep java

7. Check the free momory

8. Check the CPU processors

9. Find a file
    find [Location] -name [FileName]
    ex. find /mySystem/ -name run.sql

10. give rights to a FIle
     chown [user] [FileName]
     chgrp [user] [FileName]
     chmod 775 [FileName]
     Note : You might need to login as root

11. Give rights to the folder
      chown rezuser /[folderName]/ -R
      chgrp rezuser /[folderName]/ -R
      chmod 775 /[folderName]/ -R
12. Chcek hidden files
        cd /[file name ] -a

13. Edit file
     vi [file name]
     press insert button
     Edit the file
     press ctrl + c
     type colon(:) and wq
     press enter

     vi - edit the file
     cat - view the file
     esc : wq - with saving
     esc : q - withou saving

14. Check java process
     ps -ax|grep java
     ps -e|grep java

15. Read first 10 lines in a file
     head -n 10 [fileName]

16. Read last 10 lines in a file
     tail -n 10 [fileName]

17. Monotor java process
     watch "ps -ax |grep java"

18. Tar file
     tar -cjf [DesiredfileName].tar [Source File Name]

19. Untar file
     tar -xjf [fileName]

20. Trasnfer file from one server to another
     scp -r [fileName] [userName]@[serverIp]:[destinationFolder]

21. Download a file from the net
     lwp-download [full url]

22.Execeute a shell script with the arguments
    [shellFileName].sh [arg1]  [arg2]  [arg3]

23. Replace the text in a file
      find [Foldername] -name "*.[fileExtenstion]" -type f -exec sed -i 's/[findText]/[replaceText]/' {} \;

      ex. find /mySystem/MyDocyment -name "*.log" -type f -exec sed -i 's/localhost/' {} \;

24. Ubuntu - how to set customized ssh in the terminal
       Open a terminal
       Create a New Profile : File -> New Profile
        and set the following.
        In the Custom Command type
           ssh -p22 [user]@[serverIp]

25. How to enable root
     sudo -i

26. Disable root
     sudo usermod -p '!' root

27. How to map Network drives
     smbmount [network Folder Name] [localFolderName] -o username=[userName],password=[pw]

28. How to unmount Network drives
     sudo umount -f [network Folder name] [Local Folder Name]

28. How to check what process is opening the ports : Similer to cports in windows
        sudo netstat -lntp

29. modifty the rights
        chmod a+rwx [folder Name]

30. split large
     split -b 20000k my_large_file

31. Find a text in a directory and provide the files names which has the given text
grep -Rl --include=*.txt "text to search"

32. find the package inside the jar file. Go to the path and then run the below command

grep 'org.hibernate.cfg.Configuration' `find . \-name '*.jar'`

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.