Basic Handy Linux commands to know by default

Hi everyone,

We all have seen tutorials mentioning about basic commands to use in terminal like ls - list files/directories, cd - change directory and so on.

This post is not about those general commands we use in day to day terminal work, however to introduce to commands which will reduce your googling time and searching for answers from stack overflow.
I will introduce you to a situation and then give a solution to make this post more interesting.

Problem 1 -
I am using a linux shell, and want to know which type of shell is this meaning whether it is a Bourne shell (sh) or C shell(csh) or Kourne shell (ksh) or Bourne Again shell (bash) and so on.

Solution -
Type echo $0 to know your shell type or alternatively echo $shell - prints path where shell is being accessed from.

Problem 2 -
Kill the current shell - As we know that to kill shell we need information about process id [PID]. So how do we find this?

Solution-
Type echo "$$" = this prints the process id of the current bash shell.

Problem 3 -
I want to know version of linux distribution, kernel revision and package number release. How do I do that?

Solution -
1. Type uname -r  => this gives information on the kernel release.
2. Type lsb_release -a => this gives information on the distribution you are using
3. Type dpkg -l openssl => On debian machine this will find the package number of the release.

Problem 4 - 
I want to find CPU hardware information for my PC. How to proceed?


Solution -
1. Type - cat /proc/cpuinfo => It's a file that contains details about individual cpu cores.
It displays every processor or core is listed separately the various details about speed, cache size and model name are included in the description.

2. Type lscpu => Print the cpu hardware details in a user-friendly format. 

3. Type hardinfo => A gtk based gui tool that generates reports about various hardware components. But
Note - Hardinfo also performs a few benchmark tests taking a few minutes before the report is displayed.

4. Type lshw =>  Display's limited information about the cpu. lshw by default shows information about various hardware parts, and the '-class' option can be used to pickup information about a specific hardware part.

5. Type nproc => Prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.

6. Type dmidecode -t 4 as sudo => Displays some information about the cpu, which includes the socket type, vendor name and various flags.

7. Type cpuid after installing thus utility using "sudo apt-get install cpuid" for Debian systems.
It fetches CPUID information about Intel and AMD x86 processors.

8. Type inxi -C => Script that uses other programs to generate a well structured easy to read report about various hardware components on the system. Install using "sudo apt-get install inxi"

Problem : - Delete all sub-directories from a particular folder in linux

Command : - Type rm -rf */
Be very careful while using the command.

Problem : - How to find number of files within the sub directories of a folder. ??
Number of files in a subdirectory in a folder

Command : -  find . -maxdepth 2 -mindepth 2 -type f -printf "%h\0" | uniq -zc | tr '\0' '\n'

Split up of above command - Run command in your current folder - find all files print unique files and count the number of files.