Skip to main content

Basic Unix and Linux Commands With Examples

Learning unix operating system is very easy. It is just that you need to understand the unix server concepts and familiar with the unix commands. Here I am providing some important unix commands which will be used in daily work.

Unix Commands With Examples:

1. Listing files

The first thing after logging into the unix system, everyone does is listing the files in a directory. The ls command is used to list the files in a directory.

>ls

add.sh
logfile.txt
prime.pl

If you simply execute ls on the command prompt, then it will display the files and directories in the current directory.

>ls /usr/local/bin

You can pass a directory as an argument to ls command. In this case, the ls command prints all the files and directories in the specific directory you have passed.

2. Displaying the contents of a file.

The next thing is to display the contents of a file. The cat command is used to display the contents in a file.

>cat file.txt
This is a sample unix file
Learning about unix server is awesome

3. Displaying first few lines from a file.

The head command can be used to print the specified number of lines from the starting of a file. The below head command displays the first five lines of file.

>head -5 logfile.dat

4. Displaying last few lines from a file.

The tail command can be used to print the specified number of lines from the ending of a file. The below tail command displays the last three lines of file.

>tail -3 logfile.dat

5. Changing the directories

The cd command can be used to change from one directory to another directory. You need to specify the target directory where you want to go.

>cd /var/tmp

After typing this cd command you will be in /var/tmp directory.

6. Creating a file.

The touch command simply creates an empty file. The below touch command creates a new file in the current directory.

touch new_file.txt

7. copying the contents of one file into another.

The cp command is used to copy the content of source file into the target file. If the target file already have data, then it will be overwritten.

>cp source_file target_file

8. Creating a directory.

Directories are a way of organizing your files. The mkdir command is used to create the specified directory.

>mkdir backup

This will create the backup directory in the current directory.

9. Renaming and moving the files.

The mv command is used to rename the files and it also used for moving the files from one directory into another directory.

Renaming the file.

>mv file.txt new_file.txt

Moving the file to another directory.

>mv new_file.txt tmp/

10. Finding the number of lines in a file

The wc command can be used to find the number of line, words and characters in a file.

>wc logfile.txt
21  26 198 logfile.txt

To know about the unix command, it is always good to see the man pages. To see the man pages simply pass the command as an argument to the man.

man ls

Comments

Popular posts from this blog

Steps to remove google accounts from Computer

Open Google . You will see a round shaped picture of google account picture in top right corner as marked in below picture Click on it. Click on sign out of all accounts Click on Sign In at the top right corner as shown in picture below. Click on it. You will see following screen. Select your desired account from it and sign in . Reopen your form by clicking link provided to you, It will be open now.

Steps of splitting pdf files

Goto https://www.ilovepdf.com/split_pdf Click on Select PDF File. Upload your pdf file here. Select Extract Pages from right menu. Click on Split pdf button and wait for the procedure. Now Click on Download Split PDF and you will get a zip file in which there will be separate pdf.

Introduction to Object Oriented Programming ( OOP )

Object-Oriented Programming Object Oriented programming is a programing model that is based upon data and object. Classes   Classes are the blueprint of objects. Now you will think about what actually blueprints are. Blueprints are actually a design or plan to build something. Let's take an example like the map is detail plan of house classes are detail plan in  Object-Oriented programming. let's give you an example of a class on java so that you can unferstand. public class Car {          int horsePower;     String name;     String color;      String Company; } public class Sample {     public static void main(String[] args) {         Car car;         Car mehran;             } } Class name always start with capital letters . It is a good practice to name classes .  We will later learn how this is good. So in the above class Car ...