*nix and important commands

Hello, readers today we will learn about Linux and Linux commands.
Before getting started with Linux and important commands we must have a basic idea about the Operating system and all related stuff so in this blog we will start with an overview of OS and then some important Linux commands.
Operating system - what is it?
The operating system is a system software that acts as an interface between the user and the hardware of the system. It maintains hardware and provides a safe environment for running the program.
OS is loaded into memory when the computer is booted and remains as long as the system is on.
There are two important components of OS:- kernel and shell.
Kernel and the shell
The kernel is the core of the operating system, it contains a collection of routines mostly written in c. The kernel is loaded in memory when the system is booted and communicates directly with the hardware.
The shell is the command line interpreter, it translates commands into actions. when a user types a command the shell examines it for the special character when it finds the special character it rebuilds the command to a simpler version and communicates with hardware for command execution.
why linux
multi-user system
multiprogramming system
multi-tasking system
secure
robust
open source
Files and process
Unix system identifies everything as either files or process.
files may be collections of bytes, data, information etc. Unix system considers directories also as a file.
process is any file or executable file under execution.
Different types of file
Ordinary (regular ) file
Directory File.
Device File.
Ordinary file:- A directory file is the most common type of file, all programs we write belong to this type.
An ordinary file is divided into two types Binary file and Text File.
Directory File:- A directory file contains no data but keeps dtails of files and subdirectories it contains.
it contains the file and the unique identification number of each file and sub directory.
Device file:- Device files are generally found inside a single directory structure /dev.
It is a special type of file which in fact contains nothing.
image of the file structure in Unix
Path name - absolute and relative
An absolute path name is full path specifying the the location of a file or directory from the root directory or start of the actual file system.
absolute path name always start with root symbol that is "/"
Relative path name is the path with reference to our current working directory.
relative path name need not start with root.
File attributes
File attributes are important things to know because working with Linux systems we always have to deal with files.
when we execute the ls -l command in the directory then we get output with all file attributes using which we can play around with the file.
The file attributes are :
file type and permissions
Links
ownership
group ownership
file size
last modification time
file name.
Changing file permission
we can change file permissions in one of two ways
absolute
relative
in absolute mode we can explicitely change the permission without knowing the current permissions.
in relative mode we need to know current file permissions.
Now we have overview of what operating system is and basic understanding of linux systems.
Important Commands
pwdwill show the present working directory in which you're currently present.lswill show you the list of all the files present in a specific directory.ls -awill show you the list of all the hidden files present in a specific directory. Hidden files are starting from dot .ls -lwill show you the list of files with long details present in a specific directory.ls -lawill show you the list of more files including hidden files with long details present in a specific directory.ls -Rwill find all the folders and sub folders and so on recursively.Dot . means current directory, .. double dot means previous directory.
cd(change directory) will change the path location from one directory to another.cat filename(concatenate) will print all the content of a file in a standard output.cat > filenamewill create a new file if it is not present and allow us to enter the text also.trwill translate the characters from one string to another string.cat lower.txt | tr a-z A-Z > upper.txt, the output of the first command is the input of the second command.man command-namewill show you the details of a specific command.mkdir directory-namewill create a new directory.mkdir -p random/middle/hellowill create a middle directory b/w two directories.-pis used for parent's command.touch filenamewill create a new file.cp file.txt copy_file.txtwill make a copy of the file.txtcp -R test randomwill copy the test directory into the random directory.mv file.txt randomwill move the file.txt to the random folder.mv file.txt new_file.txtwill rename the file.txt to new_file.txt.mv test renamedTestwill rename the directory.rm file.txtwill remove a file from your computer permanently.rm -R directory-namewill remove the directory recursively.rm -rf directory-namewill forcefully remove the directory.sudo(super user do) will be used when some commands require administrative permission. If you want to access some files that require admin permission then you will usesudoto enter the password and give the permssion.dfis used to find the disk storage capacity.df -mwill show the data size in MBs.df -mhwill show the data in MBs and in human readable format.duwill estimate the disk space usage statistics.du -hwill give the file usage space in human-readable format.headwill print the first few lines of a file.head -n 4 file-namewill print the first four lines of a file.tailwill print the few lines from the bottom of a file.diffwill compare the content of the files line by line and see if there is any difference.where filenamewill show you the list of directories in which a file is present.open .will open all the files present in a specific directory.echo $PATHWhen one types a command to run, the system looks for it in the directories specified by PATH. It will display the files and folders paths by the difference of colon : It will check the executable command in one of these paths.echo "Hey" > file.txtwill override the text in a file.echo "Hey" >> file.txtwill append the text in a file.export MY_PATH="shyam"will create another path that will contain the string. But this is not permanentlocatewill find the files by name.findsearch all the files present in a directory.find . -type dwill only find the directories that are present in a current directory.find . -type fwill only find the files that are present in a current directory.find . -type f -name "file-name"will only find the files that are present in a current directory and the name of the file is given.-nameis case sensitive but if you don't want to use the case sensitive then use-iname.mmin(last modified n minutes ago)find . -type f -mmin -20will show only the files that are modified in a current directory less than 20 minutes ago.find . -type f -mmin +15will show only the files that are modified in a current directory more than 15 minutes ago.find . -type f -mmin +2 -mmin -10will show only the files that are modified in a current directory more than 2 minutes ago and less than 10 minutes ago.find . -type f -mtime -10will show only the files that are modified in a current directory less than 10 days ago.find . -type f -maxdepth 1will only show the files that are present in the first directory. It is not going recursively. If you want to recursively search then make the maxdepth equal to 2, 3, and so on.find . -size +1Mwill find all the files that has a size more than 1 MB.find . -emptywill find all the empty files.find . -perm 777will find the files that has 7(read), 7(write), and 7(execute) permission.chmod u=rwx,g=rx,o=r file-name
If I write 777, it will assign read, write, and execute permission to every hyphen of a file.
chmod 777 file-name
If I write 577, it will assign read, and execute permission to the first three hyphens and read, write and execute permission to the remaining hyphens of a file.
chmod 577 file-name
How to perform a functionality on many files? Let's you want to find multiple files and delete them.
find . -type f -name "*.txt" -exec rm -rf {} +will find and remove all the files.{}will contain a list of all the files.whoamiwill print the person username who is logged in.
grep(global regular expression print)
grep "text" filenamewill find the text in a file and it is case-sensitive.grep -w "text" filenamewill find the complete word written in a file.grep -i "text" filenamewill find the text in a file even if it is not case-sensitive.grep -n "text" filenamewill find the text with a line number in a file.grep -B 3 "text" filenamewill find the lines that came before the given text.grep -rwin "text" .will find the text recursively in a current directory.grep -wirl "text" .will find all the files that contain the given text.grep -wirc "text" .will count the files that contain the given text.historywill show the history of all the commands that has been used.history | grep "ls"will show history of all the ls command that are used.grep -P "regular expression" filenamewill find the specific text in a file by using regex.In Linux, an alias is a shortcut that references a command. Aliases are mostly used to replace long commands, improving efficiency and avoiding potential spelling errors.
aliaswill show you all the aliases that are generated.alias <key>="<value>"will make a new alias and after that, if you type a key, a functionality according to a value will be performed.unalias <key>will remove an alias from the memory and after that, the key will not be functional.
Ctrl+Awill move you to the first point of the command.Ctrl+Ewill move you to the end point of the command.Ctrl+Uwill delete everything that you entered.Ctrl+Kwill delete the command from the back of the cursor.Ctrl+Rwill search for the previous command.TAB buttonwill auto complete the command without writing it as a whole.!<number>will take a number from the history and run it to access that command.!<command>will take a command from the history that was used last time and run it to access that command.;will help you to add multiple commands in one line.sort file-namewill sort the data in an alphabetical order.sort -r file-nameis the reverse of the sort.sort -n file-namewill return the data in a numerical order.jobswill display all the current processes that are running.ping websitewill display all the data packets from a particular server.wget <URL>will download files from the internet.wget -O file-name <URL>will save the downloaded file under a different name.topwill show that how many processes are running and how much CPU usage is consuming?kill process IDwill close the process.unamewill display the kernel name.uname -owill print the operating system.uname -mwill print the architecture.uname -vwill print the kernel version.cat /etc/os-releasewill give the information of your operating system.lscpuwill give you the CPU details.freewill show you the free memory.vmstatwill display the virtual memory state.idwill print the IDs, group ids and stuff.getent group usernamewill look up the user details on Linux.zipzip-file.ziptext-file.txtwill zip the text-file.txt into zip-file.txt.unzipzip-file.zipwill unzip the file.hostnamewill show the hostname.hostname -iwill show the ip-address.useradd usernamewill add a new user.passwd usernamewill give a password to the user.userdel usernamewill delete a username.lsofwill list all the open files.lsof -u usernamewill list the files that are opened by a username.nslookup websitewill give the ip-address of a website.netstatwill give the details of all the active ports.ps auxwill give a snapshot of the current processes.cut -c 1-2 file-namewill remove sections from each line of files.ping website1 & ping website2"&" operator will fetch multiple sites data.echo "first" && echo "second""&&" operator will say if the first command is executed then execute the second command.echo "hey" && {echo "hi"; echo "I am good"}will say that if the first echo is executed then execute the commands in curly braces.echo "first" || echo "second""||" operator will say if the first command is not executed then execute the second one.| (pipe)will send the output from the first command to the second command.

