📜 ⬆️ ⬇️

10 working methods in the terminal Linux, which very few people know

A close acquaintance with the capabilities of the terminal is one of the hallmarks of a person who is well versed in Linux. Although it is difficult to remember some things, there are rather simple but effective techniques that can improve the quality and speed of work in the terminal. Perhaps every Linux user sooner or later acquires his own list of valuable little things. Hopefully, some of those ten Linux command line tricks that we want to share with you will be on your personal list of useful commands.


№1. Go to the previous directory


We all use the cd .. to go to the parent directory. And to go to the previous directory, you can use the command cd - . This technique is similar to the "Back" button.

 test@linoxide:~/Downloads$ cd - /home/eyramm test@linoxide:~$ cd - /home/eyramm/Downloads test@linoxide:~/Downloads$ 

Here we first located in the Downloads directory, then moved to the Home directory, and finally returned to the Downloads directory.
')

№2. Repeat last command


To repeat the previous command, just enter !! . In this example, we will repeat the previous command with superuser rights.

 $ apt install vlc E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? $ sudo !! sudo apt install vlc vlc is already the newest version (2.2.2-5ubuntu0.16.04.3). 

This technique is very useful precisely in situations similar to that considered when the command entered earlier must be executed with the superuser rights.

Number 3. Repeated execution of a command until successful completion


In order to execute a command until it is successfully completed, use the command return code in this construction:

 while ! [command]; do sleep 1; done 

For example:

 $ while ! ./run.sh; do sleep 1; done cat: run.sh: No such file or directory cat: run.sh: No such file or directory linoxide.com 

The command in this example will be repeated until the run.sh file is run.sh and its contents are displayed.

№4. View file transfer progress


To monitor the progress of the file transfer, use the pv command:

 $ pv access.log | gzip > access.log.gz 611MB 0:00:11 [58.3MB/s] [=> ] 15% ETA 0:00:59 

№5. Scheduling tasks


You can schedule Linux tasks using the at command:

 echo wget https://sample.site/test.mp4 | at 2:00 PM 

To view pending jobs, use the atq command.

№6. Data output in the form of a table


By calling the ls , or anything else that displays data on the screen, you may encounter long lists that require long-term scrolling to view. What is displayed on the screen can easily be organized as a table with the help of the column -t command. For example:

 $ cat /etc/passwd | column -t 


Here is what we got.


Command output organized as a table

№7. Useful keyboard shortcuts


The clear command clears the terminal screen. The key combination Ctrl + L allows you to achieve the same faster.

Alt + . key combination Alt + . allows you to navigate through previously entered commands. The key combination Ctrl + U removes from the line everything that is already entered into it. For example, you can try this to clear the password entered on the command line.

For incremental reverse search in command history use the key combination Ctrl + R

№8. Compress, split and encrypt files


Transferring large files between computers is not an easy task. You can simplify it by compressing files using the zip command, or, if the files are just very large, you can create a multi-volume archive. If you also need to encrypt the files, use the -e key.

 $ zip -re test.zip AdbeRdr11010_en_US.exe run.sh Smart_Switch_pc_setup.exe Enter password: Verify password: adding: AdbeRdr11010_en_US.exe (deflated 0%) adding: run.sh (stored 0%) adding: Smart_Switch_pc_setup.exe (deflated 2%) 

№9. Stress Test Laptop Battery


Want to know how long your laptop battery lasts when the processor is fully loaded? Try the following command:

 $ cat /dev/urandom > /dev/null 

№10. Rename or move files


If you need to quickly rename or move many files with suffixes - try a command like this:

 $ cp /home/sample.txt{,-old} 

Here's how to decipher it:

 $ cp /home/sample.txt /home/sample.txt-old 

The following is an example of renaming files with a specific extension in batch mode:

 $ ls text_comes_here_1.txt text_comes_here_2.txt text_comes_here_3.txt text_comes_here_4.txt $ rename 's/comes_here/goes_there/' *.txt $ ls text_goes_there_1.txt text_goes_there_2.txt text_goes_there_3.txt 

Results


We talked about several techniques for interacting with the Linux command line. We hope you have found something here that will help you simplify and speed up your daily work.

Dear readers! What would you add to our list of non-obvious Linux command line utilities?

Source: https://habr.com/ru/post/336060/


All Articles