Linux Commands for Beginners

I am currently an undergraduate in Computer Science and Engineering . I am currently working on my skills in java language and I also having knowledge of C language. Looking forward to improve my skills in android development and making some interesting projects .
If you are headed towards this blog then you must be interested in learning about Linux. You must have heard that Linux is an Open Source Unix like Operating System. What does it actually mean by 'Unix like Operating System'? It means that Linux shares similarities with Unix Operating System i.e. Architecture, Command Line Interface, Security and Open Source Nature.
It was created by a person named Linus Torvalds in 1991.
What is Open source? Open Source means that their source code is openly visible to the everyone . What’s cool is that anyone can see how the system works and this openness only encourages people to contribute more and make Linux more better and efficient.
Linux Distribution
Linux Distribution also termed as 'Distro' is a complete and pre configured operating system that includes Linux Kernel , system libraries, software applications, and configuration files.
Examples are :
Ubuntu
Fedora
Linux Mint
Debian
Arch Linux
CentOS
Basic Linux Commands
pwd : pwd stands for 'print working directory' . When you run this command in your terminal it outputs the current working in which you are currently working.
pwdUsing this command you can get the path to the current working directly.
ls : ls stands for 'list'. This command is used when you want to list all the contents of your current working directory(folder) but it does not show the subdirectories.
lsls -a : This command is used when we want to show all the hidden files in our folder. Hidden files generally start with (.) and they are hidden because these are not meant to be viewed or changed by the users on regular basis.
ls -als -l : Lists all the files with long details.
ls -lls -al : Lists all the files including hidden files with long details.
ls -alls -R : Lists all the directories and files in the current working directory with subfolders also.
ls -R
mkdir : mkdir stands for make directory . This command is used to create a directory.
mkdir exampleThe above command will create a directory i.e. folder with name example in your current working directory.
touch: For creating directories we have mkdir command and for creating files we have touch command.
touch abc.txtWhen you run this command then it will create a abc.txt file in your current working directory.
cd : This command is very important and is most often used. cd stands for change directory and it is used when you want to move into another directory.
cd exampleSuppose you are in a directory named abc and inside that directory you have example directory and if you want to go inside this directory you have to write the above command.
cd .. : This command is used when you want to come out of any directory.
cd ..Consider the above scenario , now you are in example directory and you again want to come back to abc directory then there this command is used.
cat: cat stands for concatenation and this command is used for 4 purposes:
to write into a file
cat >> abc.txtWhen you will run this command then you can enter data into this file and save it using Ctrl+D . If you have already created this file then its fine but you haven't then cat will do the same work for you.
to read from file
cat abc.txtAfter you are done writing into the file you can view the content of that file using the above command.
As its name suggest concatenation which means to concatenate the data of two files and display them on screen.
cat abc.txt xyz.txtThis command will display the data of abc.txt file first and xyz.txt file later on and vice versa. It do not copy the content of files but rather display them on terminal.
to add content of one file into another file using cat
cat abc.txt > xyz.txtThis command will load all the content of abc.txt file into xyz.txt file
cp : With this command you can copy the content of one file to another.
cp abc.txt xyz.txtcp -R: This command is used when we want to copy one directory into another.
cp -R example1 example2When you'll run this command on your terminal it will copy all the content of example1 directory to example2 including subdirectories also.
mv: Short for move. This command is used to move one file or folder to another location and it can also be used to rename files and directories.
For moving files: mv file_name location
mv abc.txt AFor renaming files:
mv abc.txt new_file.txtFor moving directories
mv abc xyzSuppose we have both abc and xyz directories in our current working directory so the above command will move the abc directory to xyz directory.
For renaming directories
mv directory_name new_directory_name
whoami: To check which user is currently logged in type this command in terminal.
whoamirmdir: To delete a directory type this command.
rmdir examplerm: To delete a file.
rm abc.txthead : This command is used when you only want to see only some content of the file from first.
head -n 3 hi.txtIt will display only the first 3 lines of hi.txt files
tail : To display content of files from back.
tail -n 5 names.txtIt will display last file lines of names.txt file
grep : global regular expression print is used to search text inside a file and it is case sensitive.
grep -V : to check version of grep
grep -Vgrep "world" hi.txt: this will search world keyword in hi.txt file. And this is case sensitive which means it will not show World.
grep "world" hi.txtgrep -i "world" hi.txt": Now it is not case sensitive and will show World also.
grep -i "world" hi.txtgrep -n : This command will show in which line the word you want to search is present.
grep -n "world" hi.txtgrep -wirl : It is used to show all the directories with the files that contains the keyword you want to search.
grep -wirl "Hello"Shows all the folders and files that contains the word Hello.
grep -wirc : Shows the count that how many times the number you want to search is present in every files.
grep -wirc "Hello"grep -B number keyword file_name: To see specific number of lines before the keyword.
grep -B 2 "Hi" example.txtThis will show 2 lines before the keyword Hi in example.txt file.
grep -A number keyword file_name: To see specific number of lines after the keyword.
grep -A 3 "Hi" example.txtThis will show 3 lines after the keyword Hi in example.txt file.
man : man short for manual. This command is used when you want to see the manual of the command.
man mkdirThis command will show you the manual of the mkdir command.
Exception: cd command do not have any manual.
echo: If you want to print anything on terminal use this command.
echo Hello WorldIt will print Hello World in terminal.
history : It will display history of all the command you have used.
historyhistory -c: to clear the history
history -c
Conclusion
Linux commands provide a powerful and efficient way to interact with the operating system. Learning basic commands like ls (list), cd (change directory), mkdir (make directory), and cp (copy) is essential for navigating and managing files. Understanding sudo for administrative tasks is crucial, while grep helps in searching through files. Embracing the command line enhances efficiency and control, making Linux a versatile and accessible platform for users at all skill levels. Practice and exploration are key to mastering Linux commands and unleashing the full potential of this open-source operating system.
So these are the basics command Linux commands which you should know and after that you are good to go.



