How To Use Ubuntu Terminal Like A Pro!

In 1990, there was no chat GPT or Google search engine where you could ask and search about how to use commands or what they were for. Fortunately, the terminal itself contains the answers to many of these questions. Many people just don’t know how to use it, and they would rather search on Google or other search engines. But in this article, I will tell you how exactly to use the terminal without having prior knowledge, and you won’t even need a search engine.

First, let’s start with the shortcut for opening the terminal. Press Ctrl + Alt + T. You can ignore this if you want, but I just wanted to share it. It might be useful if you are a person who mostly uses the keyboard rather than clicking here and there.

pwd Command

The pwd command will help you to know exactly where your current directory is.

ls Command

The ls command will help you to list all kinds of files and folders in your current directory

man <some command>

man is short for manual. Just like I said, you don’t need a search engine to know what a command can do. For example, man ls will show you a manual of what you can do with ls.

cd Command

cd stands for change directory. It allows you to move from one directory to another. If you want to go back to the previous directory, you can just type cd .. and it will move you to your initial or previous directory.

mkdir Command

mkdir is short for make directory. It allows you to easily create directories.

touch Command

If we just learned how to make a directory, now we learn how to make a file using the touch command.

rm Command

rm is short for remove. It allows you to remove some files. If you add the flag -r, for example rm -r <some folder>, it means you want to delete the folder. But if you just type rm <some folder>, it won’t work because rm without -r is used to delete a file.

cp Command

cp is short for copy. It allows you to duplicate some files and give that file a new name.

history Command

Just like its name, history allows you to see all commands that you have run on the terminal.

find Command

The find command allows you to find any kind of file based on the name, file type, size, and more.

vim Command

magine in 1990, there was no VS Code. So how did programmers do the coding? They used vim, a text editor. Don’t forget to install vim before you start. Below, I will make a C program and execute it. I assume you guys know how to execute a C program using the command line since this article is not about C/C++.

You might find it a little bit difficult to use vim. I suggest you read this article for more detail.

cat Command

Do you have a cat in your house? This one is not a pet. cat is used to see the content inside a file.

echo Command

If you are a PHP programmer, you may be familiar with this command. The function is almost the same; you can print or output anything with echo.

head Command

The head command is usually used for outputting the first n lines in a file.

tail Command

The tail command is usually used for outputting the last n lines in a file.

grep Command

The grep command is very useful for finding any string in a file that satisfies the given condition.

| (pipe) Operator

This pipe, when used together with grep, will find a file or folder with the given condition.

>,>>,< Operator

These operators are used for outputting to or inputting from a file that is pointed to by the arrow.

  1. > Operator:
    • The > operator is used to redirect the output of a command to a file. It will overwrite the contents of the file if it already exists.
    • Example: echo "Hello, World!" > output.txt will create a file named output.txt and write the text “Hello, World!” into it.
  2. >> Operator:
    • The >> operator is similar to >, but it appends the output to the specified file instead of overwriting it.
    • Example: echo "Appended text" >> output.txt will add “Appended text” to the end of the output.txt file.
  3. < Operator:
    • The < operator is used to redirect input from a file to a command.
    • Example: cat < input.txt will display the contents of the input.txt file using the cat command.

sudo Command

The sudo command is used to execute commands with administrator privileges.

chmod Command

The chmod command is used to change the permissions of a file or directory. It might seem a bit tricky, but bear with me. I will guide you through it.

The string “dwrxwrxwrx” can be interpreted as follows:

  • “d” indicates that it is a directory (if it were a regular file, it would be represented by “-“).
  • “rwx” indicates read, write, and execute permissions for the owner of the file or directory.
  • “r-x” indicates read and execute permissions for the group associated with the file or directory.
  • “r-x” indicates read and execute permissions for others (users who are not the owner and not in the group).

ps, kill, pstree Command

When running a program in a Unix-like operating system (such as Linux), using Ctrl+CCtrl+Z, and fg are related to managing processes in the terminal. Here’s what each of these commands does:

Ctrl+C

Pressing Ctrl+C sends the interrupt signal (SIGINT) to the currently running process in the terminal. This signal is often used to gracefully terminate a running program. For example, if you have a long-running command, pressing Ctrl+C will usually interrupt and stop it.

Ctrl+Z

Pressing Ctrl+Z sends the suspend signal (SIGTSTP) to the currently running process. This will pause the process and put it in the background. The process is stopped and can be resumed later or brought back to the foreground.

fg

The fg command is used to bring a background process back to the foreground. After you’ve suspended a process with Ctrl+Z, you can use fg to resume it and continue its execution in the foreground.

Here’s a typical scenario of how you might use these commands:

  1. You start a long-running command in the terminal.
  2. While the command is running, you realize you need to temporarily stop it, so you press Ctrl+Z to suspend it.
  3. You can then issue other commands in the terminal while the original command is in the background.
  4. When you want to resume the original command, you use the fg command to bring it back to the foreground.

These commands provide a way to manage and control processes in the terminal, allowing you to interact with them and control their execution.

For kill and fg, you can try them on your own since there’s nothing in my directory that can be killed right now.

That’s all for this article. If you have any questions, please leave a comment. I hope you find this article useful!

Join the ForwardLedge Community!

SUBSCRIBE TO FORWARDLEDGE - YOU WON'T MISS OUR PRECIOUS UPDATE

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *