Basic Linux Commands (Part 2/15)

Basic Linux commands

Linux supports GUI (Graphical User Interface) and CLI (Command Line Interface) environments. The GUI is more user-friendly and is easy to point, click and drag without any confusion. You can create folders, files and various operations as per your need and work on them like a window operating system. The traditional UNIX environment supports CLI but not GUI.

Command line interface is a terminal where you can enter command to tell the computer what to do. You can create files, folders and various operations by typing command in CLI terminal and it is faster and more powerful than GUI. Several Linux distributions use similar commands. You need to read several commands before working on Linux with CLI.

No, I will explain the basic command of Ubuntu 14.04 LTS desktop environment. First search for Terminal in your search bar or open the terminal from the keyboard shortcut Ctrl+Alt+T .

List of basic commands:

passwordPrint working directory

Directory is not a new thing but it is same as folder in Windows operating systems. In Linux, folders are known as directories.

The Pwd command prints the current working directory to the terminal.

ashish@ubuntu:~$ pwd // Press the Enter button after entering the command in the terminal

/home/ashish // working directory path and name

euCurrent directory listing

The Ls command displays the list of the current directory and files in the working directory.

For example, I am currently in the directory called gray and I typed the ls command as follows:

ashish@ubuntu:~$ls

the list of directories and files will be displayed in the terminal after entering the ls command as follows:

Main documents EG ldd3 Images sketchbook Videos

Examples of desktop downloads. Public Desktop Music Templates

cdfor changing Directory navigation

The Cd command changes the directory from the current directory located within the current directory. You can enter the following cd command into the directory:.

Command syntax: cd< space >directory name

For example, I am currently in the directory called gray and I typed the cd command as follows to change the directory called FOR EXAMPLE which is located inside gray :

ashish@ubuntu:~$ cd EG

See, now you change the directory from gray to FOR EXAMPLE .

ashish@ubuntu:~/EG$

Note: If you tried to change the directory that is not located in the current working directory, you will not be able to change the directory.

Suppose I want to change the directory from FOR EXAMPLE to Photos ( Photos directory located in ashish, not in FOR EXAMPLE directory)

ashish@ubuntu:~$cd Images

you may see the following messages in the terminal:

bash: cd: Images: No such file or directory

Here the question arises that how one can enter another directory (which is outside the current directory) from the current directory. The solution is that you need to exit the current directory and enter another directory.

You can exit and go to the previous directory using the following command:

Command syntax: cd< space >

Suppose I want to change the directory from FOR EXAMPLE to Photos ( Photos directory located in ashish, not in FOR EXAMPLE directory). So first I will go to the previous directory.

ashish@ubuntu:~/EG$ cd ..

Now you have exited the current directory called EXAMPLE and you are in the directory called gray.

ashish@ubuntu:~$

Then enter the new directory called Photos .

ashish@ubuntu:~$cd Images

See, now you change the directory from gray to Photos .

ashish@ubuntu:~/Images$

If you want to go to the root directory (like C drive in Windows operating system), use the following command:

Command syntax: cd< space >

ashish@ubuntu:~$cd /

You are now in the root directory. Display the following line in the terminal:

ashish@ubuntu:/$

Tap- Create a new file

Command syntax: tap <space>

For example,

You can create a new text file called test.txt in main gray directory. Enter the following command:

ashish@ubuntu:~$ touch test.txt

Now you can go to gray directory and check it.

cp – Create the same copy of the original file in the same directory or any other directory.

Use the following command to create the same copy of the original file in the same directory.

Command syntax: cp< space > <space>

Note: The file name and copy file name are different. You cannot create a copy of the file with the same name in the same folder.

For example,

You want to create a copy of test.txt file in the same directory called copy of test.txt . Enter the following command:

ashish@ubuntu:~$ cp test.txt testcopy.txt

Now you can go to gray directory and find the copy of test.txt file.

Use the following command to create the same copy of the original file in another directory.

Command syntax: cp< space > < space >

Path name – where we want to create the file

For example,

If you want to create a copy of test.txt file in another directory called Music, enter the following command:

ashish@ubuntu:~$ cp test.txt /home/ashish/Music

Now you can go to Ashish/Music directory and find the copy of test.txt file.

mv – moves file or directory from source to destination

Command syntax: mv< space > < space >

For example,

You want to move test.txt file from the directory named gray to the directory named Garage . Enter the following command:

ashish@ubuntu:~$ mv test.txt /home/ashish/Garage

You can also rename the file name using the mv command as follows:

ashish@ubuntu:~$ mv test.txt renametest.txt

Most basic commands

This command renames the test.txt file with the new name renametest.txt.

rm – Remove or delete file from directory

Command syntax: rm< space >

For example,

If you want to remove copy of test.txt file from the directory called gray enter the following command:

ashish@ubuntu:~$ rm testcopy.txt

mkdir – creates new directory

Command syntax: mkdir <space>

For example,

To create a new directory called Garage, type the following command:

ashish@ubuntu:~$ mkdir Garage

Enter the following command if you want to create a subdirectory recursively:

Command syntax: mkdir <space> P

For example,

To create a new directory called folder1 and inside folder1 create folder2, . type the following command:

ashish@ubuntu:~$ mkdir -p folder1/folder2

rmdir – removes existing directory

Command syntax: rmdir <space>

Note: You can remove or delete the directory if it is empty. It cannot be deleted if the directory contains some files or another directory.

For example,

to remove the directory named Garagem, . type the following command:

ashish@ubuntu:~$ rmdir Garage

Enter the following command if you want to remove or delete the directory containing some files or another directory:

Command syntax: rm< space > r< space >

r- Recursive means repeating the procedure like entering the directory within another directory and continuing. (I didn't understand the line)

For example,

To remove the directory named Garage which contains some file or other directory. type the following command:

ashish@ubuntu:~$ rmdir -r Garage

su – change super ID or log in as superuser

Su command is used to sudo to enter or log in as root or superuser. The simple user cannot log in or access as superuser. Superuser or root permission is required if you want to install any app or some setting. You can log in as superuser using the following command:

ashish@ubuntu:~$ su //after entering su, terminal asks to enter password

Password:

It is password protected, so you need to enter the password you set as your superuser password during setup.

exit – out or exit superuser or root

The superuser can log out or exit by typing the exit command.

root@ubuntu:~# exit //after entering exit, terminal displays logout message

to go out

man – manio or provide all information about the specific command.

If you don't know about the usage of a specific command, the terminal provides the command man facility which helps you find all the information about the command.

Command syntax: man <space>

clear – clears the command line interface terminal

It is a normal command to clear the screen means CLI terminal.

date – Provides the system date with time

ashish@ubuntu:~$data

The terminal displays the system date with time as follows:

Tuesday, January 19, 17:26:39 IST 2016

history – displays the command insertion history

It displays the list of previously entered commands.

ifconfig – Shows the system’s IP address, internet, Ethernet, mask, etc.

ifconfig displays the system-related IP address, Ethernet, mask, etc. information. and package information.

uptime – displays the current time

The uptime command displays current time, number of users, and system load information.

cal – Displays the calendar for the current month

The cal command displays the calendar for the current month. You can show the year calendar using the cal command.

Displays the current month's calendar with the following syntax:

Command syntax: cal

Displays the calendar for any year following the syntax:

Command syntax: cal <space>

For example,

ashish@ubuntu:~$cal 2016

It displays the calendar for the entire year 2016.

whoami – print effective user ID

It displays the login user ID.

w – Displays information about who is online

It displays information about who is online and what they are doing.

uname – Displays system information

It displays the information of kernel name, distribution, version, etc.

For example,

Enter the following command if you want to display the kernel name:

ashish@ubuntu:~$ unname

The output is:

Linux

Enter the following command if you want to display all system information:

Command syntax: uname <space> The

ashish@ubuntu:~$ uname -a

Terminal displays the following information:

Linux ubuntu 3.16.0-30-generic #40 ~ 14.04.1-Ubuntu SMP Thu Jan 15 17:45:15 UTC 2015 i686 i686 i686 GNU/Linux

free – Displays the amount of used memory and free memory

It displays the information of total memory, free memory and usage memory. It also displays cached, buffered, shared, and swap memory.

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.