18 Most Frequently Used Commands in Linux

Linux is a free and open-source operating system widely used in servers, desktops, and embedded systems. It provides a powerful and flexible command line interface that allows users to accomplish tasks efficiently. This article will highlight some of the most frequently used commands in Linux.

1. pwd

The pwd (print working directory) command is used in Unix-like operating systems, including Linux and macOS, to display the path of the current working directory. When executed, it returns the absolute pathname of the current directory.

Ubuntu Most Useful Commands Techhyme

2. echo

The echo command in Linux is a built-in command that is used to display text or other information on the screen. It is a basic command and is commonly used in shell scripts and other command-line programs to output text or the value of variables.

Ubuntu Most Useful Commands Techhyme

3. su

The su command in Linux is used to switch the current user to another user account or to the superuser (root) account. It allows a user to temporarily assume the privileges of another user account, such as the root account, to perform administrative tasks.

Ubuntu Most Useful Commands Techhyme

In case, if you want to switch to other user, then the syntax would be:

Command: su <user>

Note that using the su command can be dangerous, as it allows the user to perform actions with root privileges that can potentially harm the system. It is important to use the su command carefully and only when necessary.

Ubuntu Most Useful Commands Techhyme

4. sudo

The sudo (superuser do) command in Unix-like operating systems, including Linux and macOS, is used to execute a command as another user, usually the superuser (root) account. The sudo command allows a user with sufficient privileges to execute commands that require elevated permissions, such as installing software or modifying system files.

Syntax: sudo adduser <new user>

When a user runs a command with sudo, they are prompted for their password. If the user is authorized to use sudo for the specified command, the command is executed with elevated privileges.

Ubuntu Most Useful Commands Techhyme

5. clear

The clear command in Unix-like operating systems, including Linux and macOS, is used to clear the terminal screen. This command removes all text from the terminal window and redisplays the prompt, making it easier to see the output of subsequent commands.

Ubuntu Most Useful Commands Techhyme

6. cp

The cp command is a Unix/Linux command used to copy files and directories from one location to another. It can be used as follows:

Syntax: cp <source> <destination>

The below command would copy abc.txt to the Downloads directory in the root.

Ubuntu Most Useful Commands Techhyme

7. mv

The mv command is a Unix/Linux command used to move or rename files and directories. It can be used as follows:

Syntax: mv <source> <destination>

When the destination is an existing directory, the source file or directory is moved inside it. When the destination is not an existing directory, the source is renamed to the destination.

The below command would move abc.txt to the techhyme directory in the user’s home directory.

Ubuntu Most Useful Commands Techhyme

8. rm

The rm command is a Unix/Linux command used to remove files and directories. It can be used as follows:

Syntax: rm <file name>

It’s important to be cautious when using the rm command, as the removed files and directories are typically not recoverable. It is recommended to always use the -i option or to move files to a different directory (e.g., trash or recycle bin) instead of deleting them permanently.

Ubuntu Most Useful Commands Techhyme

9. grep

The grep command is a Unix/Linux command used to search for patterns in text files. It can be used as follows:

Syntax: grep [options] pattern [file(s)]

If a file is specified, grep searches for the pattern in that file. If no file is specified, it searches for the pattern in the standard input (e.g., from a pipe).

In below command, it would search for the string “techhyme” in the file newfile.txt and display the lines that contain it.

Ubuntu Most Useful Commands Techhyme

10. cat

The cat command is a Unix/Linux command used to concatenate and display the contents of one or more files. It can be used as follows:

Syntax: cat <filename>

If one or more files are specified, cat displays the contents of each file in the terminal. If no files are specified, cat reads from the standard input and outputs it to the terminal.

It’s worth noting that cat is often used in combination with other commands to accomplish various tasks, such as combining multiple files into one file, displaying the contents of a file and writing it to another file, or reading data from the keyboard and writing it to a file.

Ubuntu Most Useful Commands Techhyme

11. ls

The ls command is a Unix/Linux command used to list the contents of a directory.

If a directory is specified, ls lists the contents of that directory. If no directory is specified, ls lists the contents of the current directory. If one or more files are specified, ls lists information about those files.

Ubuntu Most Useful Commands Techhyme

12. cd

The cd command is a Unix/Linux command used to change the current working directory. It can be used as follows:

Syntax: cd <directory>

If a directory is specified, cd changes the current working directory to that directory. If no directory is specified, cd changes the current working directory to the user’s home directory.

Ubuntu Most Useful Commands Techhyme

13. sort

The sort command is a Unix/Linux command used to sort the contents of a file or the standard input. It can be used as follows:

Syntax: sort <filename>

Some common options include:

  • -n for sorting numerically (e.g., 2 is considered less than 11)
  • -r or –reverse for reversing the sort order
  • -t followed by a delimiter character for specifying a different field delimiter
  • -k followed by a field number for specifying the sort field

The below command would sort the contents of filenew.txt in reverse numerical order and display the sorted results in the terminal.

Ubuntu Most Useful Commands Techhyme

14. mkdir

The mkdir command is a Unix/Linux command used to create a new directory. It can be used as follows:

Syntax: mkdir <directory>

The below command would create a new directory named as “newdirectory“.

Ubuntu Most Useful Commands Techhyme

And to remove the directory name, the command is “rmdir”.

Ubuntu Most Useful Commands Techhyme

15. chmod

The chmod command is a Unix/Linux command used to change the permissions of a file or directory. It can be used as follows:

Syntax: chmod +x <file>

The chmod +x <file> syntax is used to add execute permission to a file in Unix/Linux. The +x option allows the file to be executed as a program or script.

The below command would add execute permission to the file bash.sh. After the permissions are set, the file can be executed using ./bash.sh.

Ubuntu Most Useful Commands Techhyme

16. apt-get install

apt-get install is a command used in Debian-based Linux distributions to install software packages. apt-get is a package manager tool that provides an easy way to install, update, and remove packages. The basic syntax is:

Syntax: apt-get install <package>

The below command would install the curl on your system.

Ubuntu Most Useful Commands Techhyme

17. tar

The tar command is a Unix/Linux command used to create and extract archive files. Tar stands for “tape archive” and is commonly used to distribute software and backup files. The basic syntax for creating tar archive file is:

Syntax: tar -cvf <filename> <file(s)>

The below command would create a new tar archive named file.zip containing the contents of the techhymefolder.

Ubuntu Most Useful Commands Techhyme

To extract the contents of an archive, you can use the -x option:

Syntax: tar -xvf <filename>

This would extract the contents of file.zip to the current working directory.

Ubuntu Most Useful Commands Techhyme

18. ssh

The ssh command is a secure shell protocol used to remotely log in to a networked computer or server. It allows you to run commands and transfer files securely over an encrypted connection.

The basic syntax of the ssh command is as follows:

Syntax: ssh user@example.com

The ssh command also provides several options for configuring the connection, such as specifying a different port number, using public key authentication, and forwarding X11 or TCP connections.

Ubuntu Most Useful Commands Techhyme

 

You may also like:

Related Posts

Leave a Reply