Most Important Linux Commands

Introduction

Linux is one of the most popular operating systems. So what is an operating system? An Operating System is nothing but a software program that acts as an interface between the hardware, the application software, and the users. The main aim of an operating system is to manage all the computer resources. So, we can say that the operating system gives a platform to the application software and other system software to perform their task.

Linux is an open-source operating system whose main component is Kernel (the central component which manages and provides all the operations of the hardware and the computer). Linux was developed by Linus Torvalds in the year 1994 and he developed Linux using some help from the UNIX operating system and the MINIX operating system.

Some of the features of Linux which make it one of the most widely used operating systems are:

  • Linux is an open-source operating system, so its source code is available and we can make changes to the code according to our preference.
  • Linux is comparatively more secure as viruses and hackers cannot easily attack Linux operating system.
  • Linux is lightweight and the RAM consumption is very less as well.
  • Linux provides simpler updates for all software, we can install the update using a single command (refer to the next section to learn more about the commands).
  • Linux has multiple distributions for example Red Hat Linux, Fedora Linux, CentOS Linux, etc. hence, we can download any type of distribution according to our preference.
  • The root user is a special or superuser in Linux operating system and has all the access to the system. A root user is shown using the $ sign and a normal user is shown using the # sign.
  • Linux file system is a tree-based structure consisting of files and directories. The folders are known as directories in the Linux operating system.

Most Important Linux Commands

As we have discussed that Linux is a lightweight, open-source, secure operating system. So, now let us learn about the various important Linux command.

1. Is command

The ls command is used to list down the files and directories (folders) of the current directory. Here, ls means list.

Command:

Is

Command (view hidden files)

ls -a

2. pwd command

The pwd command is used to print the current working directory (path of the current directory). So, if we want to know where we are then we can use this command.

Command:

pwd

3. clear command

The clear command is used to clear the screen or terminal, we can also press CTRL + D.

Command:

clear

4. history command

The history command is used to see all the commands used by us.

Command:

history

5. cat command

cat or concatenate command is a universal command that helps us to read the data from the file and copy the standard input to the standard output.

Command (read or view file):

cat file-name

Command (create a file):

cat > file-name

Command (add something to the end of a file):

cat >> file-name

Command (concatenate two files):

cat file1 file2 > file3

Some of the operations that we can perform using the cat command are:

  • create a file.
  • concatenate two or more files.
  • copy the content of one file into another file.
  • reverse the contents of a file.

Note:

  1. We cannot edit a file using the cat command.
  2. We generally use the > operator to copy all the contents of the left-side files to the right-side files. For example, in the command cat file1 > file2, the contents of file1 are copied to files2.

6. touch command

The touch command is used to create one or more than one empty files.

Command:

touch file-name(s)

Command (to create an empty hidden file):

touch .file-name(s)

Some of the operations that we can perform using the touch command are:

  • create one or more empty files.
  • change the timestamps of the file(s).
  • update the access time of the file(s).

7. mkdir command

The mkdir command stands for make directory. As the name suggests, the mkdir command is used to create directories.

Command:

mkdir directory-name(s)

Command (to create a hidden directory):

mkdir .directory-name

Command (to create a directory (directory2) inside another directory(directory1):

mkdir -p directory1/directory2

8. cd command

The cd command (change directory) is used to change the working directory to go to a certain directory.

Command:

cd directory-name

Command (to get out of the current directory):

cd ..

9. head and tail command

The head and tail command is used to view the first 10 lines and the last 10 lines of a file respectively. These commands are very useful if the content of a file is very large.

Command

head file-name 

tail file-name

10. copy command

The cp or copy command is used to copy the contents of one file into another file.

Command:

cp source-file destination-file

11. move command

The mv or move command is used to move one or more files and directories from one directory to another.

Command:

mv source destination

Note: We can use the same command to rename the files and directories. We just need to specify the old name at the place of source and the new name at the place of destination in the above command.

12. remove file command

The rm command is used to remove the specified files.

Command (to remove empty and non-empty files):

rm -rf file-name

13. remove directory command

The rmdir command is used to remove the specified directories.

Command (to remove an empty directory):

rmdir directory-name

Command (to remove both the parent and the child directory):

rmdir -p parent-directory/child-directory

Command (to remove a directory if the directory is not empty, it can also delete the sub-directories):

rmdir -pv directory-name

14. hostname command

As the name suggests, the hostname command is used to know the name of the host of the system.

Command:

hostname

15. IP address command

We can use the if config command to know the IP address of the machine.

Command:

if config

16. To know the operating system version

The version of the operating system is stored in the os-release directory present in the etc directory.

Command:

cat /etc/os-release

17. To update and install specific software

We can use the yum command which stands for yellow dog updater modifier to install, update, remove and list down the software in the Linus operating systems.

Command (to install software):

yum install software-name

Command (to list all the installed software):

yum list installed

Command (to remove the installed software):

yum remove software-name

Command (to upgrade package):

yum upgrade

Note: The above command will update all the installed software. ****We can also specify the name of the software that we want to update.

18. To know the details of the current user

The whoami command is used to know the details of the current user.

Command:

whoami

19. To sort the contents of the file

We can use the sort command to sort the contents of the files in alphabetical order.

Command:

sort file-name

20. To add a user

To add a new user to the Linux operating system, we can use the useradd command.

Command:

useradd user-name

21. To add a group

To add a new group to the Linux operating system, we can use the groupadd command.

Command:

groupadd group-name

22. To view the groups and users

We can use the following commands to view the groups and users of the Linux operating system.

Command (groups):

cat /etc/group

Command (users):

cat /etc/passwd

23. To zip and unzip the contents of a file

We can use the gzip command to zip and gunzip command to unzip files in Linux operating system.

Command (zip files):

gzip file-name

Command (unzip files):

gunzip file-name

24. To change the access modes files

We can use the chmod command to change the access permission of files and directories.

Command:

chmod access-number file-name

Refer to the image provided below to understand the access number used in Linux operating system.

[Image courtesy: Devopsschool.com].

Similarly, we can use the chown and chgrp commands to change the owner of files/directories and change the group of files/directories respectively.

25. To know the details of a command

To know the details of any command we can use the man command along with our desired command to know the details.

Command:

man command-name

Some bonus commands

  • data command: The date command is used to print the current day, date, time, and time zone of the current window.
  • cal command: The cal command is sued to view the calendar of any month or year of our choice.
  • grep command: The grep command is used to search for some content in a file.
  • wc command: The wc command is used to count the words in a word file.
  • du command: The du command is used to know the disk usage of the system.
  • df command: The df command is used to know the available disk space of the system.

Conclusion

Linux is one of the most popular operating systems which was developed by Linus Torvalds in the year 1994.  Linux is comparatively more secure as viruses and hackers cannot easily attack Linux operating system. Linux has multiple distributions, such as Red Hat Linux, Fedora Linux, CentOS Linux, etc.; hence, we can download any distribution according to our preference. The source code of the Linux kernel is available and we can make changes to the code according to our preference.