We’ve prepared 7 great tips for Linux users who love to use the terminal screen. In this way, you will perform your transactions quickly by increasing the interaction in daily Linux use. You can become a terminal guru with these tips that you can use in many Linux distributions.
Run multiple processes in a single command line
Let’s say you need to run multiple commands one after the other. Instead of running the commands one by one, we can say that the first command is finished with a semicolon, and it should go to the next command.
cd Desktop; touch cloud7news.txt; echo “Hello world” > cloud7news.txt; cat cloud7.txt;
When we examine the following command in a single line; we wanted it to go to the Desktop folder from the main directory, create a file named cloud7news.txt there, and write the text “Hello world” in it and display the text written in cloud7news.txt to the terminal. The result was successful as you can see:
“If” condition for running multiple processes
Double ampersand makes sure that the first command runs successfully for the second command to run. We simply use a conditional expression. Let’s try this condition with one of the frequently used commands, update/upgrade.
In the following command lines, we want to update the packages if the update command has been completed successfully on Debian or Ubuntu-based distributions:
sudo apt update && apt upgrade -y
Quick navigation in Terminal
Instead of holding down the left key in the terminal, we can go to the beginning of the command in one move by pressing CTRL+A. If we are going to continue to write your code, we can go to the end of the terminal line by pressing CTRL+E.
Are you using a Linux operating system and looking for a file you have already created? For this, I want to tell you about the “find” command. Let’s take a look at how the command works:
Syntax of “find” command
find [options] [path…] [expression]
find /home/cloud7/Desktop -type f -iname cloud7news.txt
If you want to do a case-sensitive search, change the -iname part to -name.
Shorten everything with the alias command
Sometimes it can be boring to write long commands, so I can recommend you the alias command to make better use of your time. Thus, thanks to an alias you will create, you will avoid typing the same commands over and over.
Type alias in the terminal to view the currently existing aliases:
Let’s create an alias that might be useful. We may need to update packages frequently. So let’s shorten the command sudo yum update && sudo yum upgrade -y by specifying an alias update:
alias yupdate="sudo yum update && sudo yum upgrade -y"
Writing the output of commands to a file
The > and >> operators make sure the output of the commands used before them will be written in the target files. Here is the syntax for them:
ps aux > cloud7.txt ps aux >> cloud7.txt
The first command directly rewrites the target file with the output of the ps aux command every time it is used. The second one on the other hand, simply adds lines to the end of the file like a log file.
Securely transfer your files
With SCP (Secure Copy), you can securely transfer files between two locations. During the transfer process, the traffic is encrypted and your sensitive data is securely transferred to the destination. There are many things you can do with the SCP command.
- You can transfer data from the local system to a remote server.
- You can transfer data from a remote server to your local system.
- You can share files between two remote systems and each other.
Syntax of “scp” command
scp [option] [[email protected]_HOST:]file1 [user:@DEST_HOST:] file2
Let’s transfer data from your local system to a remote server
scp file.txt [email protected]:/directory/
Let’s transfer data from a remote server to your local system
scp [email protected]:/remote/file.txt /local/directory