Useful Linux Commands

1. find command used to searches files or directories in entire file system or in current directory 

find . -name *.java  //searches all files with extension .java in current directory
find / -name Sample -type f  // "-type f" option used to return only files
find / -name Sample -type d // "-type d" option used to return only directories
find /usr -name "Sample*" -type f // searches through the /usr directory for all files that begin with the letters Sample, followed by anything else
find . -type d -name build // to find all directories named build under the current directory
find . -type f -name "Foo*" -exec rm {} \; // find all files in the current directory that begin with the letters 'Foo' and delete them
find . -iname foo // Search for all files and directories named foo, FOO, or any other combination of uppercase and lowercase characters in the current directory
find . -mtime -7 // To find all files and directories that have been modified in the last seven days
find . -mtime -7 -type f // To find all files that have been modified in the last seven days
find . -mtime -7 -type d // To find all directories that have been modified in the last seven days
find /opt /usr /var -name sample.sh -type f // Searches "samples.sh" file in multiple directories

2. locate command is used for search files and directories

locate tomcat.sh // search the entire file system for 'tomcat.sh' (uses the locate database)
locate -i spring.jar // case-insensitive search

3. grep command is used for search strings

grep 'joe' * // Search for string in multiple files
grep -i score sample.txt // case-insensitive file searching
grep -n we 
sample.txt // To show the line numbers of the files that match your grep command, just add the -n option
grep -inR "text" .  // 
case-insensitive file searching in current directory
grep 'fred' /etc/passwd // search for lines containing 'fred' in /etc/passwd
grep fred /etc/passwd // quotes usually not when you don't use regex patterns
grep -B5 "the living" sample.txt  //show all matches, and five lines before each match
grep -A10 "the living" sample.txt  // show all matches, and ten lines after each match
grep -B5 -A5 "the living" 
sample.txt  //five lines before and ten lines after
grep -n we 
sample.txt  // show line numbers as well as the matching lines 
grep '^fred' /etc/passwd  //find 'fred', but only at the start of a line
grep '[FG]oo' *  // find Foo or Goo in all files in the current dirgrep '[0-9][0-9][0-9]' *  // find all lines in all files in the current dir with three numbers in a row
egrep 'apple|banana|orange' *  // search for multiple patterns, all files in current dir
egrep -i 'apple|banana|orange' * // same thing, case-insensitive
egrep 'score|nation|liberty|equal' sample.txt  // all lines matching multiple patterns
egrep 'score|nation|liberty|equal' gettysburg-address.txt // This Unix egrep command searches the file named gettysburg-address.txt for the four strings shown (score, nation, liberty, and equal). It returns any lines from the file that contain any of those words.

4. cat command is used to view text files

cat -n myfile.txt // Showing line numbers
cat /etc/passwd // to view the contents of the /etc/passwd file on your Unix/Linux system
cat sample.txt // display the content of the file

5. wc command is used for count

$ wc /etc/passwd // to count the number of lines, words, and characters in a file
        65 185 3667 /etc/passwd

$ wc -l /etc/passwd // If you just want to know the number of lines in a file just add the -l argument
       65 /etc/passwd

$ wc -w MyStory.txt // if you want to know the number of words in a file, add the -w argument, like this
      185 MyStory.txt

ps -e | wc -l // shows the number of processes currently running on your Linux system


6. rm command is used for removing files or directories

rm oldfile.txt // to remove one file
rm file1 file2 file3  // to delete multiple Linux files at one time
rm -i files file2 file3 // The -i stands for "inquire", so when you use this option the rm command prompts you with a yes/no prompt before actually deletingrm -r OldDirectory // To delete Linux directories with the rm command, you have to specify the -r optionrm -r Directory1 Directory2 Directory3 // delete multiple directories at one timerm *.html // to delete all HTML files in the current directoryrm index* // where I'm deleting all files in the current directory that begin with the string "index"


7. mv command to rename or move Linux files and directories

mv Chapter1 Chapter1.old
mv MyStuff /tmp
// if you have a directory named MyStuff, you can move it to the /tmp directory
mv file1 file2 file3 /tmp // where three files are moved to the /tmp directory
mv file1 .. // if you want to move it up one level in the directory hierarchy

8. pwd to get current directory path

  $ pwd
    /home/techchai/

9. mkdir command is used for creating directories

mkdir tmp // creates a new directory named tmp in your current directory
mkdir memos letters e-mail // create multiple directories at one time
mkdir -p /home/joe/customer/acme/foo/bar // to create several sub directories at one time

10. ls command is used to list files and directories
 
ls -al // show all the files in cyrrent directory

11. tar command is used to create tar files

tar cvf MyProject.20090816.tar MyProject // tar command is to create an archive of a subdirectory.

c means “create archive.”
v means “verbose,” which tells tar to print all the filenames as they are added to the archive.
f tells tar that the name of the archive appears next (right after these options).


tar tvf my-archive.tar // List the contents of a tar archivetar tzvf my-archive.tgz //To list all the files in a compressed archive, add the z flag
tar xvf my-archive.tar // Extracting a tar archive
tar xzvf my-archive.tar.gz // For compressed archives the tar extract command

tar czvf MyProject.20090816.tgz MyProject // You can compress a tar archive with the gzip command after you create it

12. top command is an interactive utility that displays a character-based screen of all processes running on the current system

13. who command lets you display the users that are currently logged into your Unix computer system
     $ who

14. ps command by itself, it only shows very basic information about the processes you are currently running
     $ps

15. df command stands for "disk free". It is meant to show Linux disk space information, including disk space that is used, disk space remaining, and how filesystems are mounted on your Linux (or Unix) system
     $ df
       Filesystem 1K-blocks Used Available Use% Mounted on
       /dev/vzfs 10485760 5713424 4772336 55% /


16. du command shows disk usage information about only the files and directories you specify

17. lsof command lists information about files that are open by processes running on the system. (The lsof command itself stands for “list of open files.”)

18. chmod command name stands for "change mode", and as that name implies, the chmod command is used to change the mode of Unix/Linux files.

chmod +x myShellScript.sh // is commonly used to make a file "executable"
chmod +r myfile.txt // use of the chmod command is to make a file "readable". If a file doesn't have read permission, you can add read permission to that file
chmod +w myfile.txt // In the same way, you can also give a file write permission

19. cp command to copy files and directories on Linux systems

cp source destination
 // This cp command copies the original file named source to the new file named destination. After issuing this command both your original file and the new file will be in the current directory.
cp -r Foo /tmp // You can also copy directories with the Linux cp command, and when you do this, you just need to remember to use the -r option

20. uname // Stands for Unix name - print detailed information about the machine name, Operating System and Kernel.

root@techchai:~# uname -a
Linux techchai 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux


21. history command is used to prints the history of long list of executed commands in terminal.

Android Interview Questions

Java Interview Questions

1) Explain OOP Concepts
2) Differences between abstract classes and interfaces?
3) What is the difference between iterator and enumeration in java?
4) Composition vs Inheritance
5) Difference between method overloading and overriding
6) What are the access modifiers you know? What does each one do?
7) Can an Interface implement another Interface?
8) What is Polymorphism? What is Inheritance?
9) Explain Generics in Java?
10) Stack vs Queue
11) HashMap vs Set
12) HashSet vs TreeSet
13) What is Java PriorityQueue?
14) How is String class implemented? Why was it made immutable?
15) What does it means to say that a String is immutable?
16) What is String.intern()? When and why should it be used?
17) Can you list primitive types in Java?
18) What is the difference between an Integer and int?
19) What is Autoboxing and Unboxing?
20) Typecast in Java?
21) Do objects get passed by reference or value in Java? Elaborate on that.
22) What is the difference between instantiation and initialization of an object?
23) What the difference between local, instance and class variables?
24) What is garbage collector? How does it work?
25) What is memory leak and how does Java handle it?
26) What are strong, soft, weak and phantom references in Java?
27) What does the keyword synchronized mean?
28) What is a ThreadPoolExecutor?
29) What is volatile modifier?
30) How does the try{} catch{} finally{} works?
31) What is the difference between a Checked Exception and an Un-Checked Exception?
32) What is serialization? How do you implement it?
33) What is transient modifier?
34) What are anonymous classes?
35) What is the difference between using == and .equals on an object?
36) What is the hashCode() and equals() used for?
37) Why would you not call abstract method in constructor?
38) When would you make an object value final?
39) What are these final, finally and finalize keywords?
40) What does the static word mean in Java?
41) Can a static method be overridden in Java?
42) When is a static block run?
43) What is reflection?
44) How is a StringBuilder implemented to avoid the immutable string allocation problem?
45) Difference between StringBuffer and StringBuilder?
46) What’s the difference between an Enumeration and an Iterator?
47) What is the difference between fail-fast and fail-safe iterators in Java?
48) What do you mean by platform independence of Java?
49) What is the difference between JDK and JVM?
50) Which class is the superclass of all classes?
51) Why Java doesn’t support multiple inheritance?
52) Why Java is not pure Object Oriented language?
53) What is the importance of main method in Java?
54) Can we overload main method?
55) Can we have multiple public classes in a java source file?
56) What is Java Package and which package is imported by default?
57) What are access modifiers?
58) What is final keyword?
59) What is static keyword?
60) Can we declare a class as static?
61) What are Wrapper classes?
62) What is Enum in Java?
63) What is composition in java?
64) What does super keyword do?
65) What is this keyword?
66) What is break and continue statement?
67) What is default constructor?
68) Can we have try without catch block?
69) What is the use of System class?
70) What is instanceof keyword?
71) What is difference between Heap and Stack Memory?

Python Interview Questions

1) What is Python? What are the benefits of using Python and its main features?
2) What is PEP 8?
3) What Are The Built-In Types Available In Python?
4) What is mutable and immutable objects in python?
5) Difference between remove, pop, del on lists?
6) What is the difference between list and tuple?
7) What are tuples?
8) What is difference between tuple and list ? Where will you use tuple and              where will you use list ?
9) What is Dynamic Typing ?
10) What are *args, **kwargs ?
11) How instance variables are different from class variables?
12) Differentiate between “*.py” file and “*.pyc” file?
13) Explain the use “with” statement in python?
14) What does the “self” keyword do?
15) What Are Different Methods To Copy an Object In Python?
16) What does the <yield> keyword do in Python?
17) What is pickling and unpickling?
18) How are arguments passed by value or by reference?
19) What is namespace in Python?
20) How you can convert a number to a string?
21) What is module and package in Python?
22) What is a pass in Python?
23) Write a function to merge the two lists into one sorted list:
       X = [2, 5, 7, 10, 11, 18]
       Y = [1, 4, 6, 12, 14, 17, 21]
24) How can we get home directory using '~' in Python?
25) Difference between range and xrange?
26) Generators in Python and its use?
27) What are Iterators ?
28) How to debug python code using PDB?
29) What Lambda and use in Python?
30) How does Python handle the memory management?
31) What is monkey patching? How can you do it in Python?
32) Why are functions considered first class objects in Python?
33) How will you reverse the list in Python?
34) Explain how can you generate random numbers in Python?
35) Explain the usage of decorators?

What is Data structure?

Data structure is a method of organizing large amount of data more efficiently so that any operation on that data becomes easy.

Data structures are divided into two types:
  • Linear Data Structures 
  • Non linear Data structures 
Linear Data Structure: In Linear data structure, data is organised in sequential order.
Ex: Arrays, Linked list, Stacks and Queues

Non Linear Data Structure: In Non Linear data structure, data is organised in random order.
Ex: Tree, Graphs