Basic Linux Commands
An operating system is a spirit and consciousness for computers and other contemporary computing devices. It is a program that handles all of the hardware resources linked with your desktop or laptop. In other words, the operating system oversees the connection between your program and your hardware.
Linux is so widespread that it is found in mobile phones, vehicles, refrigerators, even Roku devices. It operates much of the Internet and multiple supercomputers. In reality, stock markets around the globe in various nations operate on Linux. Linux became the platform to operate PCs, servers, and embedded devices around the world since it is one of the most stable, secure, and resilient operating systems available.
Basic Linux Commands
Now, let us look at the most significant 20 commands in Linux. Linux commands are case sensitive so you need to be cautious about what you are keying in.
1. ls –
List directory contents. If you know windows you would know that the command dir is used to list the items of a directory. In Linux, the ls tool is used to list out files and directories. Some versions may enable color-coding. The names in blue are the names of directories.
ls -l | more – this helps to paginate the output so you may see page by page. Otherwise the listing scrolls down swiftly. You may always use ctrl c to get back to the command line.
$ ls -l filename
2. cd /var/log –
Change the current directory. The forward slash is to be used in Linux. The example is a Linux directory that comes with all versions of Linux.
When you run ls –I you will be able to examine additional information about the items in the directory
It will list down the
- Permissions related with the file
- The owner of the file
- The group connected with the file
- The size of the file
- The time stamp
- The name of the file
$ cd /var/log
3. grep –
Find text in a file. The grep command scans through several files at a time to locate a fragment of text you are searching for.
grep PATTERN [FILE]
grep failed transaction.log
The above program will locate all of the terms in the files that matched the word ‘failed’.
$ grep ‘failed’ transaction.log
4. su / sudo command -
There are several commands that require elevated access to operate on a Linux system. So you run them as a System Administrator which regular users cannot do.
su function causes the shell to be used as a super user and until you execute the exit command you may continue to be the super user
sudo - if you merely need to execute anything as a super user, you may use the sudo command. This will enable you to run the command under elevated privileges and after the program is done you will be restored to your usual rights and permissions.
Example – shutdown command the shutdown command securely shuts off the computer system.
5. pwd - Print Working Directory
One technique to determine the directory you are working in is the pwd command
It indicates the current working directory path and is handy when directory changes happen frequently
6. passwd –
Though looks similar to the pwd command the role it plays is different.
This command is used to update the user account password. You might update your password or the password of other users. Note that the typical system users may only change their own password, but root may edit the password for any account.
passwd [username] - updates the password for the user.
$ passwd admin
7. mv – Move a file
To relocate a file or rename a file you would use the mv command.
Here the file name is changed from first.txt to second.txt.
Type ls to see the change
$ mv first.txt second.txt
8. cp — Copy a file
cp source file destination file. In case you require a copy of the file second.txt in the same directory you have to use the cp command
$ cp second.txt third.txt
You may use ls – l to view the new file produced. The two files will be precisely of the same size.
9. rm –
This command is used to delete files in a directory or the directory itself. A directory cannot be deleted if it is not empty.
rm [name of the file]
rm –r removes all the contents in a directory and the directory as well.
$ rm file1
$ rm -r myproject
10. mkdir – to create a directory.
mkdir [directory name] if you would want to create a directory with the name ‘myproject’ type
$ mkdir myproject
11. chmod –
To change mode of a file system object. Files may have r – read, w- write and x-execute permissions.
chmod mode FILE
chmod 744 script.sh
- The first number stands for the user who is linked with the file
- The second number is for the group linked with the file
- The third number is connected with everyone else who is not a member of the user or group .
12. chown –
This command is used to alter the ownership of a file/folder or even multiple files/folders for a particular user/group.
chown owner name file name
$ chown user1 script.sh
Assume that if you are a user called user1 and you wish to change ownership to root use “sudo” before syntax.
$ sudo chown root script.sh
13. cat -
The cat command (short for “concatenate “) is one of the most commonly used commands in Linux. cat command enables you to create single or many files, inspect contents of file, concatenate files and redirect output in terminal or files.
$ cat file.txt
$ cat file1.txt file2.txt
Output will reveal the complete contents of the file(s).
14. echo –
This command is used to show a text or a string to the standard output or a file.
$ echo “This is an article on fundamental linux commands”
This is an article on fundamental linux commands
The echo –e option operates as an interpretation of escape characters that are back-slashed.
$ echo –e “This is an article intended for beginners. \nIt is on fundamental linux commands
Will show the output as
This is an article designed for beginners.
It is on fundamental linux commands \s\n the newline character is processed by the echo –e command
15. wc -
The wc (word count) command in Linux operating system is used to find out the number of new lines, word count, byte and characters count in a file indicated by the file parameters.
wc [options] filenames.
$ wc –l readme.txt
Shows the result as - 120 readme.txt
- wc -l : Prints the number of lines in a file.
- wc -w : prints the number of words in a file.
- wc -c : Displays the count of bytes in a file.
- wc -m : prints the count of characters from a file.
- wc -L : outputs just the length of the longest line in a file.
16. man –
This command is used to see the on-line reference manual pages for commands/programs.
$ man grep
$ man mkdir
17. history –
This command is used to display previously used commands or to receive information about the commands performed by a user.
18. clear –
This command lets you clear the terminal screen.
19. apt –get
apt -get is a robust and free front-end package manager for Debian/Ubuntu systems. It is used to install new software packages, delete available software packages, update current software packages as well as upgrade the complete operating system. apt – stands for advanced packaging tool.
$ sudo apt-get update
20. reboot –
This command may be used to stop, power-off or reboot a machine as follows.