Linux Basic Commands
You need to open the command line before proceeding to the list of commands. Check out this CLI tutorial if you’re still not sure about the command-line interface.
However, depending on the distribution you’re using, the command line may be located under the utility section.
An overview of Linux commands can be found here:
1. pwd command
Displays the current directory. Depending on whether your Linux command line displays this information, this can be convenient for you. A script for getting the directory reference will need to execute this command in Bash programming.
2. cd command
Using the cd command, you can navigate Linux files and directories. If you’re in a working directory, either the full path or the name of the directory is required.
Imagine you are in the home directory, a subdirectory of cd /home, and you want to access dnf file. Simply type cd /etc/dnf to do this.
Here are a few shortcuts to make navigation faster:
· cd .. To move one directory up, click (with two dots)
· cd The home folder is directly accessible from the cd
· cd — You can move back to your previous directory by pressing the cd- key (with a hyphen)
3. ls command
Viewing a directory’s contents with ls is possible. The contents of the current working directory will be displayed by default when you run this command.
Enter ls and the path of the directory you wish to view. To view the contents of Documents, enter ls /etc.
ls can be used in the following ways:
· ls -a command will show hidden files
· ls -l will show the files and directories with detailed information like the permissions, size, owner, etc.
· ls -R will list every file in every subdirectory
4. cat command
A frequently used command in Linux is cat (short for concatenate). The standard output (sdout) is used to display the contents of a file. You must type cat followed by the file’s name and extension to run this command. For example cat file.txt.
cat can also be used in the following ways:
- cat > filename creates a new file
· cat file1 file2 > file3 Using the command cat, join filename1 and filename2 and create a new file (3), containing their output (4).
· Use cat filename | tr a-z A-Z >output.txt to convert a file to upper-case or lower-case
5. cp command
You can copy files from one directory to another with the cp command. For example, the command cp file1 /root/Download would file1 (from your current directory) into the Download directory.
6. mv command
Rename or move files and directories. It is noteworthy that the procedure is the same in Linux. A file is renamed when it is moved to a new folder with the same name.
For Linux, type mv file1 new_file to rename files
7. mkdir command
Make new directories. With -p (Parents), you can create the whole structure of subdirectories, even if they do not exist, with one command.
8. rmdir command
Use the rmdir command to remove a directory. Rmdir, however, only allows you to delete empty directories.
9. rm command
A directory and its contents can be deleted using the rm command. You can also use rm -r to delete a directory instead of rmdir.
Using this command, be sure you are in the right directory. Nothing can be undone with this operation.
10. touch command
Through the Linux command line, you can create a blank new file using the touch command. Touch blanck_file to create an empty file entitled under the home directory.
11. grep command
A useful command for everyday use is undoubtedly grep, since it is a basic Linux command. A file can be searched through all the text contained therein.
For example, ls | grep file searches for the word blue in the file. The full text of the lines containing the searched word will be displayed.
Linux command-line utility that counts the number of characters, bytes, and words.
13. sudo / su
Both sudo and su are ways to run a program on behalf of another user. Most likely, you use one of the two, depending on your distribution. Both work, however. Su switches you to another user, whereas sudo only executes commands on its behalf. It is, therefore, safest to use sudo.
Su switches you to another user:
whereas sudo only executes commands on its behalf. It is, therefore, safest to use sudo:
14. df command
To see how much disk space the system is using, use the df command. For megabytes, type df -m.
15. du command
The du (Disk Usage) command shows how much space a file or directory takes up. Instead of the usual size format, the disk usage summary displays disk block numbers. By adding the -h argument to the command line, you can see the size in bytes, kilobytes, and megabytes.
16. head command
You can view the first lines of any text file using the head command. If you prefer, you can change the number of lines it shows to your liking. If you want to see only the first five lines, type head -n 5 filename.
17. tail command
The tail command has a similar function to the head command, but instead of showing the first ten lines of a text file, it will show the last ten lines. For eTail -n filename.ext, for example.
18. diff command
By comparing two files line by line, the diff command compares their contents. It will then output the duplicate lines after analyzing the files. The program has been rewritten rather than rewritten by a programmer.
File1.ext file2.ext diff is the simplest form of this command:
19. chmod command
Linux’s chmod command changes the read, write, and execute permissions of files and directories.
Myfile: chmod u=rwx,g=rx,o=r
In this example, symbolic permissions are used. “User”, “group”, and “other” are represented by the letters u, g, and o. An equal sign (“=”) means “set the permissions exactly as shown,” and the letters “r”, “w”, and “x” stand for “read”, “write”, and “execute”, respectively. There are no spaces between the different permission classes.
Using octal permissions notation, here is the equivalent command:
File_name chmod 754
The digits 7, 5, and 4 in this example represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:
· “Read” is represented by 4
· “Write” stands for “2”
· Execute is represented by 1;
· The 0 represents “no permission.”
The permissions assigned to 7 are 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
20. chown command
Many users can be supported by Linux. Due to this, it must keep a careful record of who has access to a file and how they can access it. Permissions control access to resources.
In general, there are three types of permissions for files:
· Permissions for users. Only one user has access to these permissions. The owner is this user.
· Permissions for groups. These are for users with access to a single file. The group owns the property.
· Permissions of other types. All other users on the system are subject to these rules. Others, or the world, are known as these users.
An owner and group pair is created when a file is created, with the owner being the user who wrote the file.
These values can be changed by chown.
21. useradd, userdel command
Linux is a multi-user operating system, so multiple people can operate it concurrently. Passwd is used to add a password to a user’s account, while useradd creates a new user. Type useradd John and then type passwd 123456789 to add John as a new user.
Adding a new user is very similar to removing one. Users can delete their accounts with userdel UserName
22. ps command
This utility displays or displays information regarding the running processes on your Linux system using the ps command, which is short for Process Status. A multi-processing and multitasking system is Linux, as we all know. Therefore, multiple processes can run simultaneously without interfering with each other
.ps-aux adds additional information about all processes owned by the current user to the previous two commands
23. kill command
A kill command sends a signal to a process on Linux-like operating systems. In the absence of a signal specification, TERM will be sent by default, terminating the process.
The kill command is located at /bin/kill in GNU/Linux.
24. uname command
By running uname, or Unix Name, you can find out what your Linux system’s name, operating system, kernel, and CPU type is.
25. sleep command
Dummy jobs are created by using the sleep command. Delaying the execution of a dummy job is helpful. By default, the time is listed in seconds, but you can change it in any format you want by adding a small suffix (s, m, h, d). The NUMBER command pauses the execution for a given amount of time.
26. wget command
With the wget command, you can even download files from the internet using the Linux command line. You can do this by typing wget followed by the download link.
27. whatis command
The whatis command in Linux displays a one-line description of a manual page. There is a description on every manual page in Linux. The command searches for manual pages names and displays their descriptions when a filename or argument is specified
28. whereis command
In Linux, the whereis command locates a command’s binary, source, and manual page files. It searches a set of restricted directories for files (binary files directories, man pages directories, and library directories).
29. ip/ifconfig command
Ip addresses are assigned to network interfaces and/or network interface parameters are configured on Linux systems by using the IP command. On modern Linux distributions, this replaces the old and now deprecated ifconfig command.
30. man command
Are you unsure of how certain Linux commands work? Using the man command in the Linux shell is a great way to learn how to use them. The man tail command, for example, will display the manual instructions.
31. history command
As soon as you’ve used Linux for a while, you’ll realize you’re capable of running hundreds of commands on a daily basis. This way, you can review commands you have previously entered by running history command.
32. ping command
To check if you’re connected to a server, use the ping command. The ping command, for example, measures the response time and whether you’re able to reach Google.
With the help of basic Linux commands, users can complete tasks easily and efficiently. Initially, remembering some of the basic commands can be a challenge, but with plenty of practice, nothing is impossible.
It is undoubtedly beneficial for you to master and know this basic Linux commands at some point. Good Luck!