📜 ⬆️ ⬇️

20 tips for Linux geeks

What makes a typical Linux user different from a professional? The answer is simple: these are the years spent studying the tricks and techniques that allow you to solve not quick tasks in an instant. If you want to increase the speed of work without long stuffing cones in the console, selected 20 easy to learn techniques. They will help make your work efficient and get the most out of your computer.


1. List of not your processes


Imagine the situation: you have already prepared for the game of Counter-Strike with your colleagues on Friday evening, but one thing - your computer is not slowing down a little, and the mouse pointer shows you a slide show. It could be someone from those users who “steal” precious time with their scientific experiments, web servers and other geeky things.

No problem, get a list of all the processes that you did not start:
ps aux | grep -v `whoami`

Or, let's make a bit more cunning, we get a list of 10 processes that most load the processor:
ps aux --sort = -% cpu | grep -m 11 -v `whoami`

')

2. Replacing text in files


Difficulty: medium
Application: find / Perl

If you need to replace the text in a single file, then there are several ways. To replace the text “Windows” with “Linux” in all files in the current directory, the name of which begins with “test”, enter in the console:
perl -i -pe 's / Windows / Linux /;' test *

To perform the same operation in all subdirectories:
find. -name '* .txt' -print | xargs perl -pi -e's / Windows / Linux / ig '* .txt

Or do you want to do the same for ordinary files with many line breaks and strange characters (the file is in a different encoding):
find -type f -name '* .txt' -print0 | xargs --null perl -pi -e 's / Windows / Linux /'

Save a lot of time and get the status of guru Linkus.

3. Fix the console


Difficulty: Easy
Application: bash

If you use the less or cat command to view a file, at the end of which is binary data, you can easily spoil the console. Because any combination of control codes can be caught in the binary data: the computer will make beep-beep sounds, cool characters will appear, strange color combinations. In the end, the font will change to some hieroglyphs. Bash obviously continues to work, but you cannot read and do nothing. Just type in the console initialization command:
reset

and all will be well.

4. Create keywords in Mozill


Difficulty: Easy
Application: Firefox / Mozilla

A useful feature of Konqueror is the ability to google the word onion in the address bar “gg onion”. The same can be done in Firefox: first, find the menu Bookmarks > Manage Bookmarks and select Add a New Bookmark . Add this URL:
www.google.com/search?q=%s

Select this entry in the bookmark editor and open its properties. Enter in the keyword field gg - and all. The% s will be replaced with the text after gg. This technique can be applied to other sites that rely on data in the URL.

Another option: right-click in the search field and select the Add a Keyword for this Search ... menu item. A window will appear where you can set the keyword.

5. Run Multiple X Sessions


Difficulty: Easy
Application: X

If you need to give someone access to your computer, you can discover that it is not always necessary. If we assume that the computer starts in graphics mode (runlevel 5), then simultaneously pressing Ctrl + Alt + <F7>, you will be taken to the console. Enter your login and password, then execute the following code:
startx -- : 1

To go to the graphic environment. To return to the previous session, press Ctrl + Alt + <F7>, for one more return - Ctrl + Alt + <F8>. You can do this trick: the F1 through F6 keys are responsible for 6 console sessions, and the F7 through F12 keys for 6 X sessions. Reef: in different distributions can use different keyboard shortcuts.

6. Accelerate Surfing


Difficulty: Easy
Application: KDE

KDE has a little-known but useful option to speed up web surfing. Launch KDE Control Center and select System > KDE performane . You can enable Konqueror preloading. That is, the browser will load when the system is started in the background. When it is needed, it will appear almost instantly. Tip: read 20 more tips to speed up KDE

7. Easy backup


Difficulty: Easy
Application: Backups

If you need to backup the folder and copy only the changed files, you can use rsync to do this (you need an account on the remote computer):
rsync -vare ssh jono@192.168.0.2: / home / jono / importantfiles / * / home / jono / backup /

This command backs up all files from / home / jono / backup / to / home / jono / importantfiles / on the computer with the IP address 192.168.0.2

8. Keep your watch up to date


Difficulty: Easy
Application: NTP

If your watch seems to be in a hurry or lagging behind, then use NTP to guarantee synchronization with very high accuracy. You need to install an NTP package and then synchronize with the server:
ntpdate ntp.blueyonder.co.uk

A list of suitable NTP servers can be found at http://support.ntp.org/bin/view/Servers/NTPPoolServers . Add this command to autoload - and your watch will always be accurate.

9. Search for the largest files


Difficulty: low
Application: shell

You may encounter a problem when you need to delete several large files. They can be found in the current directory with the command:
ls -lSrh

The key r means that large files should be displayed at the end. The following command can find the largest MP3 / MPEG files:
ls -lSrh * .mp *

You can also find the largest directories:
du -kx | egrep -v "\ ./.+/" | sort -n


10. Nautilus hotkeys


Difficulty: low
Application: Nautilus

Although most file managers should support mouse control these days, it is sometimes useful to use a keyboard. Nautilus has several combinations that allow you to instantly move between files:

- Open directory - Ctrl + L
- Move up one level - Ctrl + Up
- Move inside directory - arrows

11. Database Optimization


Difficulty: low
Application: MySQL

Any change to the database structure or deletion of large amounts of data can result in files becoming fragmented, resulting in a loss of performance. Just remember a simple rule: run the database optimizer for any database changes:
mysqlcheck -o <databasename>

You may notice that you should regularly optimize the bases when using fields with the VARCHAR type: these fields with variable length are especially prone to fragmentation.

12. Quick letters


Difficulty: low
Application: KMail

Can't afford to lose 3 seconds to find your email client? Not tired of searching for a mouse pointer among all the beautiful turmoil on your desktop? Whatever you do in KDE, you are separated by just a few keystrokes from sending a letter. Press Alt + F2 to open the 'Run command' dialog. Type:
mailto: plop@ploppypants.com

Press Enter - and KMail will automatically open. You don't even have to type in the full mailing address. This trick also works with Internet addresses: just type www.hab.ru to launch Konqueror.

13. Parallel assembly


Difficulty: low
Appendix: GCC

If you have a multi-core system with a decent amount of RAM, you can significantly increase the speed by using a parallel assembly. If you compare with a sequential assembly, then the speed increase is several times. To use two or more streams, add the -j switch:
make -j4; make -j4 modules


14. Increase battery life


Difficulty: medium
Application: hdparm

You probably encountered hdparm for tuning the hard disk, but it can also increase the battery life of your laptop and reduce the noise of rotating parts.
hdparm -y / dev / hdb
hdparm -Y / dev / hdb
hdparm -S 36 / dev / hdb

The first command forces you to go into standby mode, the second one - into sleep mode, and the last one sets the automatic shutdown time. The numeric parameter is a multiple of 5.

15. Wireless speed control


Difficulty: medium
Application: iwconfig

The speed at which the radio receiver and transmitter can communicate depends on the strength of the signal. In order to maintain communication when a signal deteriorates, data must be transmitted at a slower rate. Usually, the radio tries to calculate the available signal and automatically selects the highest transmission rate.

In areas of interference with an insufficient signal level, the packets may spontaneously disappear, and the receiver and transmitter constantly adjust the speed. If you can not add antennas or move your equipment to enhance the signal, then you need to reduce the synchronization speed. This means fewer reconnects and can be significantly faster than a flip-flop connection. Each network card has its own way to establish a connection. In Linux, the speed limit can be set via iwconfig:
iwconfig eth0 rate 2M

This command causes the network card to synchronize only at 2Mbps. You can also set a speed limit: the network card is automatically synchronized at any speed less, but not faster:
iwconfig eth0 rate 5.5M auto

Using the auto directive means that you can work at any speed up to 5.5Mbps. To remove the speed limit, simply type:
iwconfig eth0 rate auto

Network cards can operate over long distances at a speed of 1Mbps than at a speed of 11Mbps. The difference between 1Mbps and 11Mbps is 12 decibels for Orinocco cards, that is, theoretically, you can increase the maximum working distance by 4 times, reducing the transmission speed.

16. List of open ports


Difficulty: medium
Application: nestat

Obtaining a list of open ports in the Listen state is very simple in Linux:
~ # netstat -lnp
Active Internet connections (only servers)
Proto Recd-Q Send-Q Local Program PID / Program Name
tcp 0 0 0.0.0.0:5280 0.0.0.0:* LISTEN 698 / perl
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 217 / httpd
tcp 0 0 10.42.3.2:53 0.0.0.0:* LISTEN 220 / named
tcp 0 0 10.42.4.6:53 0.0.0.0:* LISTEN 220 / named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 220 / named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 200 / sshd
udp 0 0 0.0.0.0:32768 0.0.0.0:* 220 / named
udp 0 0 10.42.3.2:53 0.0.0.0:* 220 / named
udp 0 0 10.42.4.6:53 0.0.0.0:* 220 / named
udp 0 0 127.0.0.1:53 0.0.0.0:* 220 / named
udp 0 0 0.0.0.0:67 0.0.0.0:* 222 / dhcpd
raw 0 0 0.0.0.0:1 0.0.0.0:* 7 222 / dhcpd

In this example, you can see that the process with PID 698 is the Pearl interpreter process, which listens on port 5280. If you are not root in the system, then the system will not show the path to the programs.

17. Increasing the speed of hard drives


Difficulty: high
Application: hdparm

hdarm can be used to improve performance. Be careful: changing these settings may result in data loss, so make a backup copy of the data beforehand. Speed ​​testing can be done with the following command:
hdparm -tt / dev / sda

The result will look something like this:
hdparm -tt / dev / sda
/ dev / sda:
Timing cached reads: 1784 MB in 2.00 seconds = 892.56 MB / sec
Timing buffered disk reads: 82 MB in 3.04 seconds = 26.96 MB / sec

To find out the current settings, simply add the device name to hdparm:
/ dev / sda:
IO_support = 0 (default)
readonly = 0 (off)
readahead = 256 (on)
geometry = 4865/255/63, sectors = 78165360, start = 0

Most distributions have secure settings selected for most hard drives. In order to increase the speed, you can enable DMA mode. Most computers support 3 mode — 32-bit data transfer, which almost doubles the speed:

18. Remote access to your programs.


Difficulty: low
Application: X

If you need remote access to graphical applications, this can be done using SSH. First, you need to enable this option in / etc / ssh / sshd_config:
X11Forwarding yes

Secondly, you can now start GIMP remotely:
ssh -X 192.168.0.2 gimp


19. More comfortable mana
Difficulty: low
Application: man

If you are looking for information on a specific team or subject, then mana is a good place to start your search. The usual access to mans is man <command>, but you can search for the desired pages by keyword. For example, search mana associated with the login process:
man -k login

It is useful to use search when reading manas: just press the / key and type the desired word.

20. Packet Interconnection Chart


Difficulty: low
Application: Debian

The most important part of Debian is the ability to install packages along with all dependencies. If you want to see all the relationships between packages, you can use the Graphiz package from a non-free (non-free) repository of Debian:
apt-cache dotty> debain.dot

This file can be loaded in dotty:
dotty debian.dot


21. Forced shutdown of busy devices


Difficulty: low
Application: bash

You are probably faced with a situation when you need to otmuntit disk, but the system when trying to turn off reports that it is busy. One team can find out which application uses it:
lsof + D / mnt / windows

It shows the PID and the start command of any process using / mnt / windows.

22. Converting text file encodings


Difficulty: low
Application: recode

recode is a small utility that will simplify the transfer of text files created on different platforms. One of the main reasons is the difference in line breaks. In some systems, a newline character is used; in others, a carriage return is used; in others, both methods are used. As a result, if you transfer text from one platform to another, then you open the file and you will see many (or, conversely, few) line breaks and many strange characters.

The utility parameters are a bit confusing, but this can be bypassed by setting aliases:
alias dos2unix = 'recode dos / CR-LF..l1'
alias unix2win = 'recode l1..windows-1250'
alias unix2dos = 'recode l1..dos / CR-LF'

There are many options: recode can convert texts between a number of encodings.

23. Search for files modified today


Difficulty: low
Application: various

For example, in the morning you created a file that is very necessary right now. However, you cannot remember its name. Manually going through the home directory is meaningless, where more than one thousand files have accumulated. But there is a small trick showing the effectiveness of the pipes and combining several console commands:
ls -al --time-style = +% D | grep `date +% D`

The ls command options require the date to be displayed in a specific format. The trick is: that which will give ls, goes to the input of grep. The grep parameter is a command in itself (enclosed in reverse apostrophes), which substitutes the current date in the dropout pattern. It is easy to modify to search for other dates, file size, etc.

©

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


All Articles