Linux is an open-source operating system that runs on Linux Kernel. Linux can be operated via terminals by using commands in Linux or through the graphical user interface (GUI).
Linux comes with many distributions (also known as distros)such as Ubuntu, Fedora, Kali Linux, Redhat, Debian, etc. Not only programmers but anyone can use Linux easily through these distros.
Apart from using GUI, you can use the terminal to complete tasks. The terminal is similar to the command prompt in Windows OS. It can help you achieve tasks more easily and faster. To use the terminal you require certain commands that you enter and the OS will perform those tasks.
In beginning, you may find it a little annoying to use commands in Linux rather than using the GUI alternative, but once you get a hold of it you can perform many tasks more efficiently. To assist you with we have made a list of the most commonly used Linux commands that you can try while reading this blog on the side.
Also read: Beginners guide to Git and Git commands
First, we have to open the terminal, press Ctrl+Alt+T and the terminal will appear. You can execute a command by entering the Enter key.
Basic commands in linux
Following are some basic commands in Linux that you can use to perform tasks on Linux OS. Linux commands are case sensitive
1. help command
There may be some commands you may not remember and a help command can help you get information on how to use a command.
command_name --help
2. pwd command
The current working directory means the directory in which the user is working. If pwd
is used it shows the path of the current working directory starting from the root.
pwd
3. mkdir command
This command helps to create a new directory (folders). The directory can be created under any directory. This command can create multiple directories at once.
Following command will create a directory in the current working directory a user is.
mkdir <directory name>
4. rmdir command
This command can be used to remove specified directory from linux file system.
rmdir <directory name>
5. ls command
If you want to know the list of files in the current directory, ls
the command displays a list of files in the current working directory
ls
6. cd command
It is used to change the current working directory. If this command is used without any argument then it will change directory to the root folder.
Following example shows how to to change directory with an argument
cd <directory name>
If cd
is used with two dots then it will change the current directory to parent directory from one.
cd ..
cd ../../
7. touch command
This command can be used to create empty files as well as update the timestamps on existing files and directories
touch <file name>
touch <file1> <file2> ....
8. cat command
The cat
the command prints the contents of one or more files and merges files by appending one file’s contents to the end of another file. It can also be used to create and display the contents of files
cat <file name>
9. rm command
This command helps to remove files and directory.
rm <file name>
rm -i <file name> // prompts user before deleting specified file
rm -d <dirname> // used to remove one or more empty directories
10. cp command
This command helps to copy files and directories. It takes two arguments: The first is the location of the file to be copied, the second is where to copy.
cp <existing file name> <new file name>
11. mv command
The mv
command is used to move files and directories from one location to another. It can also be used to rename a file. This command takes two arguments.
mv <file name> <directory path>
mv <old file name> <new file name>
12. sudo command
The Sudo command allows you to run programs as a root user. This command gives a user root and administrative privileges. To execute this command you require the root password.
sudo <command>
13. useradd command
This command can add a new user to the Linux server. To create a user use Sudo
command before the useradd
command.
sudo useradd <username>
14. userdel command
This command can remove a user from Linux server.
sudo userdel <username>
15. passwd command
This command is used to create or change password for a user
passwd <username> //Hit enter and then type in new password
TIPS and Tricks for Linux terminal
Now that we know the basic commands in Linux, here are some tips and tricks you can use in the terminal
- Use the TAB key to fill up the commands in the terminal. For eg: you want to change a directory to a Downloads directory. Just type cd Dow and then press the TAB button the terminal will automatically fill in the rest of the details as
cd Downloads/
- Type clear command to clear the terminal if it’s filled up with too many commands.
- Run multiple commands together by using
;
as a separator between each command. - Use Ctlr+r and the search term to use the command you previously used.
- The up and Down key can help you navigate through the list of commands you have used in the terminal.
- Use Ctrl+c to stop a command from running. Ctrl+z to force stop the running commands.
- Use
exit
command to exit the terminal.
These were some of the basic commands for Linux. Share with us which command you use most often in the comments section below.