Read: why should you learn linux
Choosing a distro:
When you start learning about linux , Redhat, Ubuntu, centos , Fedora, suse and mint are names that would be going through your brain. But believe me, there are nearly six hundred different distros of linux. I suggest you to start with Centos ( a derivative of Redhat enterprise linux) and Ubuntu ( a debian based distro). Choosing a distro is of your choice. For more info on choosing a distro , read thisIn this tutorial I will be explaining the important things to do when you start learning the Linux command line. I started learning linu from udemy course. If you are new to linux and you want a good grip on linux, you can subscribe for the online course. It is a really good course for linux foundation.
Course link: Linux tutorials by linux academy
Getting started:
Shell: To run command in Linux we use a command line interpreter called shell. You can virtually do any Linux based operations using the shell.You can open a shell terminal using the GUI options in your distro or you can user Ctrl + Alt + T shortcut keys to open the terminal.
Also read: Linux shell scripting beginner tutorial
Viewing OS information:
cat command is used to view the contents of a file. The information about the CPU and OS are present inside files under the /etc folder.1. Command to view the cpu information
cat /proc/cpuinfo2. Commad to find the OS details
cat /etc/*release*
Adding users and Passwrods:
1. Open the terminal and issue the following command to execute commands as root.sudo su
2. To Create an user , lets say scriptuser , execute the following command in the terminaluseradd -s /bin/bash -m -d /home/scriptuser -g root scriptuser
the above command creates a user “scriptuser”, create the home directory for the user.3. Add password for the user.
Passwd scriptuser
4. Only the root user will have all the privileges to execute and modify all the files in the server. Inorder for the user to have certain privileges to executes commands and install softwares, it should have some root privileges. To provide the user root privileges , you should add the user to ther sudoers list. Sudoers file will be present inside the /etc folder. location: /etc/sudoers. Use any one of the foloowing commands to open the sudoers file.vi /etc/sudoers (or)
visudo
vi is the editor for linux. There are other ediotors like nano.5. Add the following line to the sudoers file.
scriptuser ALL=(ALL:ALL) ALL
scriptuser is the username and ALL=(ALL:ALL) ALL will give the user certain root privileges. After adding this line , press Esc key , w and q to save the edited file. Now you will be able to execute commands using root privileges by using sudo before the command.Working with directories (folders)and files:
1. Create a directory using the following commandmkdir directory_name2. Remove a directory
rmdir directory_name3. You can browse through the directories using cd (current directory) command
cd /dir1/dir24. You can find the current working directory using the following command.
pwd
Editor:
vi is the commonly used and a very powerful text editor. 1. Open a file
vi filename2. Save a file by pressing the following keys consequently.
esc + w +q3. Exit the file without saving
esc + q4. Search for a particular word in a file
/keyword + enter5. Delete a particular line
<pre>use dd by placing the cursor in the line which you want to delete the file.</pre>
6. Undo the action by pressing u
7. Copy and paste and particular line
yy to copy and
p for paste
To create a file you can either use the editor or touch command.
1. If you create a file using touch command, the file size will be zero.
touch filename2. Creating a file using vi.
vi file name3. Deleting a file
rm filename4. Force deleting
rm –f filename5. To delete all the files in a folder , cd in to the directory and issue the following command.
rm –rf *r stands for recursive and f stands for force, * denotes all.
6. To delete a folder with files.
rm –rf foldername7. Create a hidden file by appending a . operator before the file name.
mkdir .dirname
touch .filename
Listing Files and folders:
1. You can list all the files and folders using the ls command.ls2. Use the following command to list all the hidden folders
ls –a3. List all the files with particular extension.
ls *.png4. List all the files with their starting with a
ls *.sh
ls a*5. List all the files starting with letter a to d from a particular folder
ls /folder-name/[a-d]*kindly share this article and leave a comment for queries.