Linux Basic Commands
Linux supports both GUI (Graphical User Interface) and CLI (Command Line Interface) environments. GUI is more user friendly for users and it’s easy to point, click and drag without any confusion. You can create folder, file and various operations as per your need and work upon them like window operating system. Traditional UNIX environment supports CLI but not GUI.
Command Line Interface is a terminal where you can enter the command to tell computer what to do. You can create file, folder and various operations by entering command in CLI terminal and it is faster and more powerful than GUI. Various Linux distributions make use of similar commands. You need to read various commands before working in Linux with CLI.
No I am going to explain the basic command with Ubuntu 14.04 LTS desktop environment. First search the Terminal from your Search Bar or open the terminal from keyboard shortcut Ctrl+Alt+T.
List of Basic Command:
pwd - Print Working Directory
Directory is not a new thing but it is same as folder in windows operating systems. In Linux, folders are known as directory.
Pwd command prints the current working directory on terminal.
ashish@ubuntu:~$ pwd // Press the enter button after entering command in terminal
/home/ashish // path and name of working directory
ls – Listing of Current Directory
Ls command displays the list of current directory and files in working directory.
For example, currently I am in directory named ashish and I entered command ls as following:
ashish@ubuntu:~$ ls
the list of directory and file will be displayed on terminal after entering ls command as follows:
core Documents EG ldd3 Pictures sketchbook Videos
Desktop Downloads examples.desktop Music Public Templates
cd – for navigation change Directory
Cd command changes the directory from current directory located inside the current directory. You can enter the following cd command in the directory:.
Syntax of command: cd<space>name of directory
For example, currently I am in directory named ashish and I entered command cd as following for changing the directory named EG which is located inside ashish:
ashish@ubuntu:~$ cd EG
See, now you change the directory from ashish to EG.
ashish@ubuntu:~/EG$
Note: if you tried to change directory which is not located inside current working directory, you cannot change the directory.
Suppose, I want to change directory from EG to Pictures (Pictures directory located in ashish, not in EG directory)
ashish@ubuntu:~$ cd Pictures
you can see the following messages on terminal:
bash: cd: Pictures: No such file or directory
Here question arises as to how one can enter another directory (which is outside of current directory) from current directory. Solution is that you need to exit from current directory and then enter in another directory.
You can exit and go to the previous directory using following command:
Syntax of command: cd<space><dot><dot>
Suppose, I want to change directory from EG to Pictures (Pictures directory located in ashish, not in EG directory). So first I will go into previous directory.
ashish@ubuntu:~/EG$ cd ..
Now you are exited from current directory named EG and you are in directory named ashish.
ashish@ubuntu:~$
Next enter the new directory named Pictures.
ashish@ubuntu:~$ cd Pictures
See, now you change the directory from ashish to Pictures.
ashish@ubuntu:~/Pictures$
If you want to go to the root directory (like C drive in window OS), use the following command:
Syntax of command: cd<space><forward slace>
ashish@ubuntu:~$ cd /
Now you are in the root directory. Display the following line on terminal:
ashish@ubuntu:/$
Touch- Create a new file
Syntax of command: touch<space><file name>
For example,
You can create a new text file named test.txt in main ashish directory. Enter the following command:
ashish@ubuntu:~$ touch test.txt
Now you can go to ashish directory and check it.
cp – Create same copy of original file in same directory or any another directory.
Use the following command for createing same copy of original file in the same directory.
Syntax of command: cp<space><file name><space><copy file name>
Note: file name and copy file name are different. You cannot create a copy of the file with same the name in same folder.
For example,
You want to create copy of test.txt file in same directory named testcopy.txt. Enter the following command:
ashish@ubuntu:~$ cp test.txt testcopy.txt
Now you can go to ashish directory and find the copy of test.txt file.
Use the following command for creating same copy of original file in another directory.
Syntax of command: cp<space><file name><space><Path name>
Path name – where we want to create file
For example,
If you want to create copy of test.txt file in another directory named 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 – move file or directory from source to destination
Syntax of command: mv<space><file or directory- source ><space><destination path>
For example,
You want to move test.txt file from directory named ashish to directory named Garage. Enter the following command:
ashish@ubuntu:~$ mv test.txt /home/ashish/Garage
You can also rename the file name using mv command as following:
ashish@ubuntu:~$ mv test.txt renametest.txt
More Basic Commands
This command renames the file test.txt with new name renametest.txt.
rm – Remove or delete file from directory
Syntax of command: rm<space><file name>
For example,
If you want to remove testcopy.txt file from directory named ashish, enter the following command:
ashish@ubuntu:~$ rm testcopy.txt
mkdir – create new directory
Syntax of command: mkdir<space><Directory name>
For example,
To create new directory named Garage, enter the following command:
ashish@ubuntu:~$ mkdir Garage
Enter the following command if you want create subdirectory in recursively manner:
Syntax of command: mkdir<space><hyphen>p<Subdirectory name>
For example,
To create new directory named folder1 and inside folder1 create folder2,. enter the following command:
ashish@ubuntu:~$ mkdir -p folder1/folder2
rmdir – remove existing directory
Syntax of command: rmdir<space><Directory name>
Note: You can remove or delete the directory if it is empty. It cannot delete if the directory contains some files or another directory.
For example,
to remove directory named Garage,. enter the following command:
ashish@ubuntu:~$ rmdir Garage
Enter the following command if you want to remove or delete directory which contains some files or another directory:
Syntax of command: rm<space><hyphen>r<space><Directory name>
r- Recursive means repeat the procedure as enter directory inside enter another directory and go on.(Didn’t get the line)
For example,
To remove directory named Garage which contains some file or another directory,. enter the following command:
ashish@ubuntu:~$ rmdir -r Garage
su – change super Id or enter as superuser
Su command is used for sudo in order to enter or login as root or Superuser. Simple user cannot enter or access as a superuser. Superuser or root permission is required if you want to install some application or some configuration. You can enter as superuser using following command:
ashish@ubuntu:~$ su //after entered su, terminal ask for enter password
Password:
It is password protected so you need to enter password which you had set as superuser password during configuration.
exit – out or exit from superuser or root
Superuser can exit or logout by entering exit command.
root@ubuntu:~# exit //after entered exit, terminal display logout message
logout
man – manio or provide the all information regarding specific command.
If you don’t know about the use of a particular command, terminal provides the facility with man command which helps to find all the information regarding command.
Syntax of command: man<space><Command name>
clear – clear the command line interface terminal
It is normal command to clear the screen means CLI terminal.
date – Provide the system date with time
ashish@ubuntu:~$ date
Terminal display the system date with time as following:
Tue Jan 19 17:26:39 IST 2016
history – display the history of entering command
It displays the list of previously entered command.
ifconfig – Show the IP address of system, internet, Ethernet, mask etc.
ifconfig displays the information of IP address related to system, Ethernet, mask etc. and package information.
uptime – display current time
uptime command displays the information of current time, number of users and system load.
cal – Display the calendar of current month
cal command displays the calendar of running month. You can show the year’s calendar using cal command.
Displays the calendar of current month by following syntax:
Syntax of command: cal
Displays the calendar of any year by following syntax:
Syntax of command: cal<space><year>
For example,
ashish@ubuntu:~$ cal 2016
It displays the calendar of whole 2016 year.
whoami – print effective user ID
It displays the Login user ID.
w – Display the information that who is online
It displays the information that who is online and what they are doing.
uname – Display System information
It displays the information of kernel name, distribution, version etc.
For example,
Enter the following command if you want to display the name of kernel:
ashish@ubuntu:~$ uname
Output is:
Linux
Enter the following command if you want to display all system information:
Syntax of command: uname<space><hyphen>a
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 – Display the amount of used memory and free memory
It displays the information of total memory, free memory and usage memory. It also displays cached, buffer, shared and swap memory.
You may also like:
Filed Under: Featured Contributions, Tutorials
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.