DEV Community

Cover image for Basic Commands of Linux.
Bhavesh Goyal for DSC CIET

Posted on • Edited on

Basic Commands of Linux.

Recommended
Installed virtual box and ubuntu.||System Dual booted with Ubuntu.

Basic Terminologies to start with:

  • Kernel − The kernel is the heart of the operating system. It interacts with the hardware and most of the tasks like memory management, task scheduling and file management.

  • Shell − The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous shells which are available with most of the Unix variants.

  • Commands and Utilities − There are various commands and utilities which you can make use of in your day to day activities. cp, mv, cat and grep, etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various options.

  • Files and Directories − All the data of Unix is organized into files. All files are then organized into directories. These directories are further organized into a tree-like structure called the filesystem.
    Basically you can think of directory as a folder in your system.

Basic commands of Linux:-
1.pwd:-To check the present directory in which you are working
right now.

2.ls:-To list the files and directories stored in the current
directory/folder.
Some extensions are:-
ls -l:-To list in the some details of the files in a list format.
ls -a:-To list all the files of a directory including the hidden files.
ls -ld:-To list all the directories within a present directory.

3.cd:-To change the current directory to another.
Some useful commands of this:-
cd ..:-To move to directory that is one level up of pwd.
cd /:-This command is used to change directory to the root directory, The root directory is the first directory in your filesystem hierarchy.
cd ~:-To move back to the home directory.
cd -:-To visit last directory.
cd dir_1/dir_2/dir_3:-This command is used to move inside a directory from a directory.

4.touch:-To create blank files.

5.cat:-To create files with content and to show the content of the file.
It has two situations:-

  • No such file pre-exists in the directory:- It will create a file & you can enter the content.
  • File pre-exists with the same name in the directory:- It will display the contents of that file.

6.wc:-To get a count of the total number of lines, words, and characters contained in a file.
Syntax:-wc filename
Output:- 2 19 103 filename
This implies that it has 2 lines,19 words,103 characters and name of the file is 'filename'.

7.cp:-To make a copy of a file.
Syntax:-cp FILENAME COPIED_FILE_NAME
cp filename copyfile:-This will create the file in the same directory named copyfile which is the copy of filename.
Syntax:-cp FILENAME DESTINATION
cp filename /home/Desktop:-This will create a copy of file named filename at the mentioned location i.e Desktop.

8.mv:-To change the name of a file or a directory.
Syntax:-mv old_file new_file

9.rm:-To delete an existing file.
Syntax:-rm filename1

10.mkdir:-To make a directory.
Syntax:-mkdir dir1

11.rmdir:-To remove a directory.
Syntax:-rmdir dir1

Note − To remove a directory, make sure it is empty which means there should not be any file or sub-directory inside this directory.

12.grep:-To search something(any pattern of characters) in a file.
Synatx:-grep "Helllo" filename
This will search for "Hello" in the file named filename and will display all the lines of that file that contains "Hello" in them.

Thanks for reading.
Will be back soon with some more commands.

Top comments (0)