Basic Linux Commands

 Basic Linux Commands

Basic Linux Commands | Linux Commands | Linux command to change directory | Linux command to create new user | Linux command to delete user | Linux command to create new folder | Linux command to view files | Linux command to delete files | Linux command to delete folder | Linux head command | Linux Tail command | Linux command to create new file | pwd command | grep command | Linux command to zip a file or folder | Linux command to unzip file or folder

Get Started:

So guys to we are going to discuss about Linux commands. So if you are a admin or a normal user and wants to work with Linux or Unix OS (operating system) you should know the basic commands to handle your daily work activities that can be maintain users or file handling. So let’s get started.

Linux Admin Commands:

Note:

  • Below Commands are explaining as a Ubuntu user. Commands can be mismatched or bit differs for another Linux OS.   
  • Admin commands can be performs by admin or root users only.

Create User:

You can create a new user by given commands “adduser” or “useradd”. Here we are showing you example with command “useradd”.

First you need to switch to the root account, for that type below command to enter root account and root password:

$su - root

To create a new user gives command to your terminal as:

$useradd USERNAME

The above command will create a new user with the name of USERNAME.

To add password at USERNAME type below:

$passwd USERNAME

The above command will set password to your USERNAME

To verify you can switch to the new user account by given below command and USERNAME password:

$su – USERNAME

Check the below Screen Shot:

Linux Command to add New User

View Users:

To view the number of user in your Linux machine you need to check the below path file:

$cat /etc/passwd

Checkout below image:

Linux command to check User List

Delete User:

To delete a user you have to give command as:

$useldel USERNAME

The above command will delete the particular user.

Checkout below image:

Linux Command to Delete User
 

How to change User Password:

To change your password you can change them from below two methods:

$passwd USERNAME

Linux Command to change user password

$sudo passwd USERNAME

Linux Command to change user password


Working with Files and Folders:

Create a File:

To create a file you can use two ways 1st is by using “touch” command or 2nd is by using “vi” command by vi editor. In this post first we will create file using “touch” command and edit it later using “vi” command.

So let’s start,

To create a file in Linux system we use below command:

$touch filename

As in below image you can see we have created “testFile1” using touch command, which is a blank file.

linux touch command

Edit & Save a File:

To edit a file or to add data/text into your file we use:

$vi filename

In below image we open “testFile1” to insert some dummy data into it using above command. After given your command your terminal will look like below image:

Edit a file in linux

To add data into your file and to save it you need to follow below steps:

  • First press “i” button from keyboard once to insert data to your file.
  • Once you done with your data adding press “ESC” button from your keyboard once to get out from the editing.
  • At last type “:wq” and hit “enter”.

Your file is save now.

Save file in linux

View a File:

To view your saved files, go to the file path and type:

$cat fileName

In below image we can see our data which we add in previous commands.

linux cat command

Head and Tail Command:

If you have a big list file and you wanted to see only few lines of your files from top or from bottom, “head” and “tail” commands are here, these commands are running through pipe.

To view top lines you need to give “head” command:

$cat filename | head –n

(n is number of lines you wanted to print)

To view bottom lines you need to give “tail” command:

$cat filename | tail –n

(n is number of lines you wanted to print)

Linux head and tail command

Delete a File:

To delete a file you can use below command:

$rm fileName

Linux Command to delete a file

Create a Folder:

To create a folder use below command:

$mkdir folderName


As you can see we have created a folder with the name “testFolder1” at desktop.

Delete a Folder:

To delete a folder use below command:

$rm –rf folderName

linux command to delete a folder

You can see, we deleted “testFolder1”.

Copy File and Folder:

To copy a file we will use:

$cp “path_of_the_file” “path_of_the_location"

linux command to copy a file

linux command to copy a file

To copy a folder we will use:

$cp –r "path_of_source_folder" "path_of_destination_folder"

linux command to copy a folder

Move File and Folder:

To move a file or folder we use below command:

$mv “path_of_source_file” “path_of_destination”

Linux command to move a file

To move a folder use:

$mv “path_of_source_folder” “path_of_destination”

Linux command to move a folder


Archive your data:

TAR or UNTAR a file:

To make a file or folder in archive in Linux we generally make them tar.

Tar is default command which is present in every Linux system. If you want to zip/rar then you need to install particular packages first in many Linux systems.

To tar a file:

$tar –czvf filename_with_extention_.tar.gz location_where_to_save

Linux command to tar a file
 
To untar use below:

$tar –xvf filename.tar.gz

Linux Command to untar a file


Other Important Commands:

View current path:

To view the current path where user is present right now we use:

$pwd

(pwd stands for present working directory)

pwd command

Change current path:

To change the current path we use cd command which stands for change directory.

$cd directory_path

Linux Command to change directory

Use of GREP:

GREP command is use to list out or find some particulate file if present.

$grep “ajay”

Use of PIPE:

The PIPE symbol is use to connect two command to perform a single output.

$ls | grep “something”

The above command will list out items and list out “something” as result if present.

Use of MAN command:

This command is usually use to get manual of any command. You can get a deep detail of the target command. This command work like:

$man commandName

When you run the command it will look like:

$man ls

Linux man command
 

Check the active users:

To check the list of active user you can type below command:

$who

The above command will give you list of active user on network.

Check the History of commands:

to check the histroy of your typed command use below: 

$history

linux command to check history
 
That's all for now, feel free to leave your valuable comments.

Thank you

Read More:

4 Comments