Result
Do you use Linux commands regularly? Today, we will be looking at 10 Linux commands you should know. The commands listed below are some of the most useful and widely used Linux commands.
Prerequisites
- We will run these commands on an Ubuntu server, but you can follow along on any modern Linux distribution.
1.Order lsOn Linux
This lsThe command is used to list files and directories in the current working directory. This is one of the most commonly used Linux commands that you should know.
As you can see in the image above, using the command alone without any arguments gives us an output with all the files and directories in the directory. This command offers a lot of flexibility in terms of displaying the data in the output.
2. Order pwdOn Linux
This pwd It allows you to print the current working directory in your terminal. This is a very basic command and serves its purpose well.
Now, your terminal prompt should usually have the full directory. But if it doesn't, this can be a quick command to see what directory you're in. Another use for this command is when creating scripts where it can allow us to find the directory where the script is stored.
3. Order cd On Linux
While working in the terminal, navigating within directories is almost a necessity. The cd command is one of the important Linux commands that you should know and it helps you navigate within directories. Just type cd followed by the directory as shown below.
root@ubuntu:~# cd <directory path>
As you can see in the command above, I simply typed cd /etc/ to enter the /etc folder. We used the pwd command to print the current working directory.
4. Order mkdi On Linux
The mkdir command allows you to create directories from within the terminal.
root@ubuntu:~# mkdir <folder name>
As you can see in the image above, we created the JournalDev directory with just this simple command.
5. cp and mv commands
Commands c.p. and mv They are equivalent to the copy-paste and cut-paste commands in Windows. But since Linux doesn't really have a command for renaming files, we also use the mv command to rename files and folders.
root@ubuntu:~# cp <source> <destination>
In the above command we created a copy of the file named Sample. Let's see what happens if we use the mv command in the same way.
root@ubuntu:~# mv <source> <destination
In the above case, since we were moving the file in the same directory, it acted as a rename. Now the file name has changed.
6. Order rm On Linux
In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and folders and is one of the important Linux commands that you should know.
root@ubuntu:~# rm <file name>
To remove a directory, you must add the -r argument to it. Without the -r argument, the rm command will not remove directories.
root@ubuntu:~# rm -r <folder/directory name>The -r flag in the rm command in Linux stands for “recursive.” When used with the rm command, it recursively deletes not only the specified file, but also all of its subdirectories and the files within those subdirectories.
7. Order Touch On Linux
The Touch command in Linux creates an empty file or updates the timestamp of an existing file.
root@ubuntu:~# touch <file name>
8. Order ln On Linux
We use the ln command to create a link to another file. If you plan to work as a Linux administrator, this is one of the most important Linux commands you need to know.
root@ubuntu:~# ln -s <source path> <link name>The -s flag creates a symbolic link (also known as a symbolic link or soft link) to a file or directory. A symbolic link is a special type of file that acts as a shortcut or pointer to another file or directory.
By default, the ln command creates hard links instead of symbolic or soft links.
9. Order clear On Linux
The clear command in Linux clears the terminal screen. It removes all the text and output displayed in the terminal, giving you a clean screen to work with.
Here is an example of how to use the clear command:
root@ubuntu:~# clearThis will clear the terminal screen and move the cursor to the top left corner of the screen.
You can also use the clear command in combination with other commands, like this:
root@ubuntu:~# ls -l; clearThis will list the files and directories in the current directory and then clear the terminal screen.
10. Cat, Echo, and Less Commands
When you want to output the contents of a file or print anything to the terminal output, we use the cat or echo commands. Let's see their basic usage.
root@ubuntu:~# cat <file name>
root@ubuntu:~# echo <Text to print on terminal>As you can see in the example above, the cat command, when used in our New-File, prints the contents of the file. Meanwhile, when we use the echo command, it simply prints whatever follows the command.
The Less command is used when the output printed by any command is larger than the space on the screen and needs to be scrolled. The less command allows the user to break the output and scroll through it using the enter or space keys.
A simple way to do this is to use the (|) operator.
root@ubuntu:~# cat /boot/grub/grub.cfg | less


















