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

Computer Buses

Computer Buses   A computer system consists of different devices.CPU must be able to communicate with all devices. The devices are connected together by a communications channel called bus. A bus consists of a set of communication lines or wires. It is used to move a large amount of bits in the form of electrical pulses from one unit to another. The bus is used to connect the following units: Central Processing Unit Control Unit  Arithmetic and Logic Unit Main Memory ( RAM, ROM) Input / Output Devices Bus is a common path to transfer data and commands between CPU, memory and input / output devices.It is also used to send or receive data from secondary storage.The capacity of a bus depends on the number of data lines in it.A bus with 16 lines can carry 16 bits or 2 bytes at a time. A bus with 32 lines can carry 32 bits or 4 bytes at a time . Types Of  Buses Different types of buses are as follows: 1. Data Bus 2.Addres...

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.

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.