Top 25 Basic Linux Commands for Beginners [Recommended]

Basic Linux Commands

Michael T

Last Update 3 years ago

We’ve listed 10 of the most common Linux commands here. They’re not all you need to know, but they are some of the most common. And remember, Linux commands are case-sensitive.

1. ls

This command lists directory contents. If you’ve used the Windows command prompt, then you should know that the command dir is used to list the contents in a directory. This is what the ls command does in Linux - it lists files and directories. Some versions may support color-coding. The names in blue represent the names of directories.

The command ls -l | more – helps paginate the output so you can view page by page. Otherwise the listing scrolls down rapidly. You can always use ctrl + c to return to the command line.

2. cd /var/log

This changes the current directory. Note that it uses a forward slash. The example used here changes the location to a Linux directory that is present in all versions of Linux.

When you usels –I you will be able to see more details of the contents in the directory. It lists the following:

Permissions associated with the file

  • The owner of the file
  • The group associated with the file
  • The size of the file
  • The timestamp
  • The name of the file

3. grep

This finds text in a file. The grep command searches through many files at a time to find a piece of text you are looking for.

grep PATTERN [FILE]

grep failed transaction.log

The above command will find all of the words in the files that matched the word ‘failed’.

4. su / sudo command

There are some commands that need elevated rights to run on a Linux system. You must run these as a System Administrator.

The su command changes the shell so that it is used as a super user. Until you use the exit command, you can continue to be the super user.

The sudo command is used when you just need to run something as a super user, you can use the sudo command. This will allow you to run the command in elevated rights and once the command is executed you will be back to your normal rights and permissions.

An example is the shutdown command, which turns off the computer system.

  • sudo shutdown 2:shutdown and turns of the computer after 2 minutes.
  • sudo shutdown –r 2: shuts down and reboots in 2 minutes.
  • Using ctrl Cor shutdown–c: helps in stopping the shutdown process.

5. pwd

One way to identify the directory you are working in is the pwd command. It displays the current working directory path and is useful when directory changes are made frequently.

6. passwd

Though it looks similar to the pwd command, this command is very different. This command is used to change the user account password.

You could change your password or the password of other users. Note that the normal system users may only change their own password, while root may modify the password for any account.

passwd [username]- changes the password for the user.

7. mv

The mv command moves a file or renames it. Here the file name gets changed from first.txt to second.txt.

Type lsto view the change.

8. cp

This command copies a file. The cp command issues a copy of the file second.txt in the same directory.

You can use ls – l to see the new file created.

9. rm

This command is used to remove files in a directory or the directory itself. A directory cannot be removed if it is not empty.

rm [name of the file]

rm –r removes all the contents in a directory and the directory as well.

10. mkdir

The mkdir command makes a directory. The command is written as follows: mkdir [directory name]

Was this article helpful?

2 out of 2 liked this article