16 LINUX OS TIPS AND TRICKS YOU NEED!! #1: Check processes not - TopicsExpress



          

16 LINUX OS TIPS AND TRICKS YOU NEED!! #1: Check processes not run by you Difficulty: Expert Application: bash Imagine the scene - you get yourself ready for a quick round of Crack Attack against a colleague at the office, only to find the game drags to a halt just as youre about to beat your uppity subordinate - what could be happening to make your machine so slow? It must be some of those other users, stealing your precious CPU time with their scientific experiments, webservers or other weird, geeky things! OK, lets list all the processes on the box not being run by you! ps aux | grep -v `whoami` Or, to be a little more clever, why not just list the top ten time-wasters: ps aux --sort=-%cpu | grep -m 11 -v `whoami` It is probably best to run this as root, as this will filter out most of the vital background processes. Now that you have the information, you could just kill their processes, but much more dastardly is to run xeyes on their desktop. Repeatedly! #2: Replacing same text in multiple files Difficulty: Intermediate Application: find/Perl If you have text you want to replace in multiple locations, there are several ways to do this. To replace the text Windows with Linux in all files in current directory called test[something] you can run this: perl -i -pe s/Windows/Linux/; test* To replace the text Windows with Linux in all text files in current directory and down you can run this: find . -name *.txt -print | xargs perl -pi -es/Windows/Linux/ig *.txt Or if you prefer this will also work, but only on regular files: find -type f -name *.txt -print0 | xargs --null perl -pi -e s/Windows/Linux/ Saves a lot of time and has a high guru rating! #3: Fix a wonky terminal Difficulty: Easy Application: bash Weve all done it - accidentally used less or cat to list a file, and ended up viewing binary instead. This usually involves all sorts of control codes that can easily screw up your terminal display. There will be beeping. There will be funny characters. There will be odd colour combinations. At the end of it, your font will be replaced with hieroglyphics and you dont know what to do. Well, bash is obviously still working, but you just cant read whats actually going on! Send the terminal an initialisation command: reset and all will be well again. #4: Creating Mozilla keywords Difficulty: Easy Application: Firefox/Mozilla A useful feature in Konqueror is the ability to type gg onion to do a Google search based on the word onion. The same kind of functionality can be achieved in Mozilla by first clicking on Bookmarks>Manage Bookmarks and then Add a New Bookmark. Add the URL as: google/search?q=%s Now select the entry in the bookmark editor and click the Properties button. Now enter the keyword as gg (or this can be anything you choose) and the process is complete. The %s in the URL will be replaced with the text after the keyword. You can apply this hack to other kinds of sites that rely on you passing information on the URL. Alternatively, right-click on a search field and select the menu option Add a Keyword for this Search.... The subsequent dialog will allow you to specify the keyword to use. #5: Running multiple X sessions Difficulty: Easy Application: X If you share your Linux box with someone and you are sick of continually logging in and out, you may be relieved to know that this is not really needed. Assuming that your computer starts in graphical mode (runlevel 5), by simultaneously pressing the keys Control+Alt+F1 - you will get a login prompt. Insert your login and password and then execute: startx -- :1 to get into your graphical environment. To go back to the previous user session, press Ctrl+Alt+F7, while to get yours back press Ctrl+Alt+F8. You can repeat this trick: the keys F1 to F6 identify six console sessions, while F7 to F12 identify six X sessions. Caveat: although this is true in most cases, different distributions can implement this feature in a different way. #6: Faster browsing Difficulty: Easy Application: KDE In KDE, a little-known but useful option exists to speed up your web browsing experience. Start the KDE Control Center and choose System > KDE performance from the sidebar. You can now select to preload Konqueror instances. Effectively, this means that Konqueror is run on startup, but kept hidden until you try to use it. When you do, it pops up almost instantaneously. Bonus! And if youre looking for more KDE tips, make sure you check out our article, 20 all-new KDE 4.2 tips. #7: Backup your website easily Difficulty: Easy Application: Backups If you want to back up a directory on a computer and only copy changed files to the backup computer instead of everything with each backup, you can use the rsync tool to do this. You will need an account on the remote computer that you are backing up from. Here is the command: rsync -vare ssh [email protected]:/home/jono/importantfiles/* /home/jono/backup/ Here we are backing up all of the files in /home/jono/importantfiles/ on 192.168.0.2 to /home/jono/backup on the current machine. #8: Keeping your clock in time Difficulty: Easy Application: NTP If you find that the clock on your computer seems to wander off the time, you can make use of a special NTP tool to ensure that you are always synchronised with the kind of accuracy that only people that wear white coats get excited about. You will need to install the ntpdate tool that is often included in the NTP package, and then you can synchronise with an NTP server: ntpdate ntp.blueyonder.co.uk A list of suitable NTP servers is available at eecis.udel.edu/~mills/ntp/clock1b.html. If you modify your boot process and scripts to include this command you can ensure that you are perfectly in time whenever you boot your computer. You could also run a cron job to update the time. #9: Finding the biggest files Difficulty: Easy Application: Shell A common problem with computers is when you have a number of large files (such as audio/video clips) that you may want to get rid of. You can find the biggest files in the current directory with: ls -lSrh The r causes the large files to be listed at the end and the h gives human readable output (MB and such). You could also search for the biggest MP3/MPEGs: ls -lSrh *.mp* You can also look for the largest directories with: du -kx | egrep -v \./.+/ | sort -n #10: Nautilus shortcuts Difficulty: Easy Application: Nautilus Although most file managers these days are designed to be used with the mouse, its also useful to be able to use the keyboard sometimes. Nautilus has a few keyboard shortcuts that can have you flying through files: Open a location - Ctrl+L Open Parent folder - Ctrl+Up Arrow keys navigate around current folder. You can also customise the file icons with emblems. These are little graphical overlays that can be applied to individual files or groups. Open the Edit > Backgrounds and Emblems menu item, and drag-and-drop the images you want. #11: Defrag your databases Difficulty: Easy Application: MySQL Whenever you change the structure of a MySQL database, or remove a lot of data from it, the files can become fragmented resulting in a loss of performance, particularly when running queries. Just remember any time you change the database to run the optimiser: mysqlcheck -o You may also find it worth your while to defragment your database tables regularly if you are using VARCHAR fields: these variable-length columns are particularly prone to fragmentation. #12: Quicker emails Difficulty: Easy Application: KMail Cant afford to waste three seconds locating your email client? Cant be bothered finding the mouse under all those gently rotting mountains of clutter on your desk? Whatever you are doing in KDE, you are only a few keypresses away from sending a mail. Press Alt+F2 to bring up the Run command dialog. Type: mailto:plop@ploppypants Press return and KMail will automatically fire up, ready for your words of wisdom. You dont even need to fill in the entire email address. This also works for Internet addresses: try typing slashdot.org to launch Konqueror. #13: Parallelise your build Difficulty: Easy Application: GCC If youre running a multiprocessor system (SMP) with a moderate amount of RAM, you can usually see significant benefits by performing a parallel make when building code. Compared to doing serial builds when running make (as is the default), a parallel build is a vast improvement. To tell make to allow more than one child at a time while building, use the -j switch: make -j4; make -j4 modules #14: Save battery power Difficulty: Intermediate Application: hdparm You are probably familiar with using hdparm for tuning a hard drive, but it can also save battery life on your laptop, or make life quieter for you by spinning down drives. hdparm -y /dev/hdb hdparm -Y /dev/hdb hdparm -S 36 /dev/hdb In order, these commands will: cause the drive to switch to Standby mode, switch to Sleep mode, and finally set the Automatic spindown timeout. This last includes a numeric variable, whose units are blocks of 5 seconds (for example, a value of 12 would equal one minute). Incidentally, this habit of specifying spindown time in blocks of 5 seconds should really be a contender for a special user-friendliness award - theres probably some historical reason for it, but were stumped. Write in and tell us if you happen to know where it came from! #15: Wireless speed management Difficulty: Intermediate Application: iwconfig The speed at which a piece of radio transmission/receiver equipment can communicate with another depends on how much signal is available. In order to maintain communications as the available signal fades, the radios need to transmit data at a slower rate. Normally, the radios attempt to work out the available signal on their own and automatically select the fastest possible speed. In fringe areas with a barely adequate signal, packets may be needlessly lost while the radios continually renegotiate the link speed. If you cant add more antenna gain, or reposition your equipment to achieve a better enough signal, consider forcing your card to sync at a lower rate. This will mean fewer retries, and can be substantially faster than using a continually flip-flopping link. Each driver has its own method for setting the link speed. In Linux, set the link speed with iwconfig: iwconfig eth0 rate 2M This forces the radio to always sync at 2Mbps, even if other speeds are available. You can also set a particular speed as a ceiling, and allow the card to automatically scale to any slower speed, but go no faster. For example, you might use this on the example link above: iwconfig eth0 rate 5.5M auto Using the auto directive this way tells the driver to allow speeds up to 5.5Mbps, and to run slower if necessary, but will never try to sync at anything faster. To restore the card to full auto scaling, just specify auto by itself: iwconfig eth0 rate auto Cards can generally reach much further at 1Mbps than they can at 11Mbps. There is a difference of 12dB between the 1Mbps and 11Mbps ratings of the Orinoco card - thats four times the potential distance just by dropping the data rate! #16: Unclog open ports Difficulty: Intermediate Application: netstat Generating a list of network ports that are in the Listen state on a Linux server is simple with netstat: root@catlin:~# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State 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 That shows you that PID 698 is a Perl process that is bound to port 5280. If youre not root, the system wont disclose which programs are running on which ports.
Posted on: Mon, 11 Nov 2013 17:08:02 +0000

Trending Topics



Recently Viewed Topics




© 2015