quarta-feira, 30 de outubro de 2013

13 Quick Hacks For Linux!

13 Quick Hacks For Linux!

Here we bring to you 13 brilliant quick hacks for Linux users!

If you are a true geek, we are sure you love to do the simplest things in the smartest ways. So, for all the Linux users out there we bring 13 quick hacks to help you to perform some basic to advanced tasks.

1. Ascii Character Lister

To list printable characters and their ascii values, do the following:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}'
To find the ascii code for a specific character (other than the space character, use $ in this example), do this:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep '_\$'
Normal characters don't need and can't use the backslash, so to find the asci value of lower case 'd' you'd do this:
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep '_d'
To find the character corresponding to an ascii value, do this (example uses 100 as the ascii value):
perl -e 'foreach $x (32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep ' 100'

2. Directory Size Lister/Sorter

Ever wondered which directories and trees are eating all your diskspace especially during pruning/archiving, backup, and numerous other activities. The following one line script to find out:
du -sm $(find $1 -type d -maxdepth 1 -xdev) | sort -g
The preceding shellscript prints every directory below the one called as an argument, together with its size, sorted with the largest at the bottom. We sort largest at bottom so there's no necessity to pipe it to less. Instead, you can see the largest 24 on the screen after the command.
If you find a large tree, but can't delete the whole thing, you can explore just that tree by using its directory as the argument, and you'll see all its subtrees and how much space they take.
But let's say you want to see ALL directories in the tree, instantly zeroing in on big diskspace directories. Make the following shellscript, which called alldirsizes:
find $1 -type d  | xargs du -sm | sort -g
Both these scripts do more than just add filesizes. They take into account inodes, so they reveal the space that would be recovered if the directories were deleted.
Both of these scripts are most accurate when run as root, but they're pretty informative run as just a normal user.

3. Man pages formatted as text

Man pages look great on console screens, but piped to files or to browsers they quickly degenerate into cluttered conglomerations of reverse linefeeds and backspaces designed to simulate "bold" on your console screen. You get rid of the clutter by piping the output of man through thecol command. With no args, col blows off the reverse linefeeds but leaves the backspaces (^H). The command you want (using the ls man page as an example) is:
man ls | col -bx > myfile.txt
The preceding command writes the man page to myfile.txt, without backspaces (the -b) and with spaces substituted for tabs (-x).

4. Recording, Playing and Converting sounds

Before you start on this, install aumix and use it to do both record and play volumes, and make sure the microphone is the record device and not muted. Don't use a GUI mixer -- they sometimes get it wrong.
To record a song from the microphone, just do this:
$ rec mysong.au
If you want to change the volume, use -v, which is a float where >1.0 amplifies, and <1 .0="" attenuates.="" font="" hearing="" is="" logarithmic.="" note="" our="">
$ rec -v2 mysong.au
To play it back, do this:
$ play mysong.au
To convert it to a .wav, do this:
$ sox mysong.au mysong.wav
Sox can also amplify, flanger, phaser, echo, and various other effects. See man sox.

5. Finding Who Has a File Open

How often do mounts and unmounts fail because you can't determine what is using the device? How many times can you not eject a CD because something's got it open? How many times have you experienced a "file browser" that keeps a directory open even after you've navigated out of that directory and clicked the "refresh" button? Who's got this thing open??? Use the fuser program to find out:
[slitt@mydesk slitt]$ /sbin/fuser -mu /d
/d:                   1693(slitt)  1891c(slitt)  1894  1894c(slitt)
  1907  1907c(slitt)  1908  1908c(slitt)  1909  1909c(slitt)
  1910  1910c(slitt)  1912  1912c(slitt)  1913  1913c(slitt)
[slitt@mydesk slitt]$
You get the owner and the process ID. From there you can research usingps ax.
Be sure to look at the fuser man page for details on other info you can obtain. You can even kill all processes accessing a file, though its is highly recommend against such a heavy handed move.

6. Modem Init Strings

Delay for Voicemail Phones

On some phone systems with voicemail, when there are unheard messages, the dialtone beeps several times. This can prevent the modem from connecting. If you have this problem, you can solve it with a simple modem init string addition.
On a Hayes compatible modem, and the following string onto the end of your modem init string:
Register S6 determines the delay before checking for dialtone. By instituting a 4 second delay, by the time you check for a dialtone all the beeps will be gone. If 4 seconds isn't enough, try 10, and then trim it down from there.

7. How to enable X across a network connection

  1. You might need to institute the ssh connection as ssh -x
  2. export DISPLAY=":0"
  3. ;xhost +

8. Enabling Root on Ubuntu

If you're reading this now, you probably got a rude awakening when you tried to log into a Ubuntu box as user root. By default, it can't be done.
The trick is that Ubuntu enables anything, absolutely anything, via the sudo command. As a matter of fact, anyone logged in as any user can get a root shell with the sudo bash command. This in itself is a horrible security problem, because anyone who logs in, locally or remotely, as any user can have the way with the machine. This situation must be rectified immediately.
What you'll want to do, in plain English, is this:
  1. Get into a root shell
  2. Use the passwd command to enable logging into user root
  3. Test that you can log into root
  4. Disable overly permissive sudo capabilities
Here are the specific commands:
  1. sudo bash
  2. passwd root
    • Set a root password
  3. Ctrl+Alt+F3 to access a new CLI terminal
  4. Log in as root
  5. visudo
    • Comment out root=(ALL) ALL to eliminate this dangerous sudo capability
    • Comment out %admin=(ALL) ALL to eliminate this dangerous sudo capability

9. Turning Off OpenOffice Autocompletion

Of all the obnoxious "features" ever created, OpenOffice's "Word Autocompletion" is probably the worst. It makes the old "Microsoft Bob" look positively benign.
OpenOffice's autocompletion looks at your typing, and when a word appears to resemble another word in the document, it "helps" you by highlighting the whole word and adding letters to make it the resembled word. For a fast touch typist, it's distracting as the dickens.
So turn it off. From the OpenOffice menu, Tools->Autocorrect, and then uncheck the "Enable Word Completion" checkbox. That's it -- no more obnoxious word completion.

10. Copying Via SSH

If you want to copy an entire tree from one computer to another, sftp won't do it. Rsync can do it, but in certain cases rsync can consume too much RAM. Assuming you're user slitt on the destination, and the tree belongs to user slitt on the source, here's a very easy to remember way to do it:
ssh slitt@source 'tar -cz /home/slitt/mytree' | tar -xzp
The p on the end of the extraction tar means "preserve permissions". The preceding places the home/slitt/mytree into the current directory, so you'll need to move mytree where you need it and delete the rest of the tree. To avoid that hassle and put mytree right into the current directory, use the -C option:
ssh slitt@source 'tar -C /home/slitt -cz mytree' | tar -xzp
Notice that everything within the singlequotes is performed on the remote computer, and everything after the last quote is performed on the local computer. The ssh program, when running a command, outputs the remote command's stdout on the local computer, so that data can be piped to local processes, which is what we're doing here.
The plot thickens if some files within the tar have different owners. In that case, the best thing to do is log into the local machine as root, go to the destination directory, and run it with the --same-owner argument on the extraction tar:
ssh slitt@source 'tar -C /home/slitt -cz mytree' | tar -xzp --same-owner
Although unless space is too tight to maintain both the .tgz and the extracted tree on the destination computer, this is better done as a three stage process:
ssh slitt@source 'tar -C /home/slitt -cz mytree' > /spare_directory/mytree.tgz
tar -tzp --same-owner -f /spare_directory/mytree.tgz
tar -xzp --same-owner -f /spare_directory/mytree.tgz
The first command creates a tarball, on the local computer, from the tree on the remote computer. The second command checks what's in the tarball, so if there's something wrong you can quit rather than possibly overwriting something valuable. The third command extracts the tarball to the current directory. Once again, the only real disadvantage of this is that you must have room for both the tarball and the extracted tree.

11. Running Terminals With Specific Fonts

This works for xterm and rxvt, and probably works for others. To specify a normal font (as opposed to a font used for bold), you run xterm with the -fn option:
rxvt -fn font_alias
The only trouble is, how do you find the font alias? That's contained in a file called fonts.alias. You find that file with locate command:
locate fonts.alias
When you look inside that file, each line has an alias followed by a space followed by a complete file specification, as shown in the following example:
lucidasanstypewriter-12 -b&h-lucidatypewriter-medium-r-normal-sans-12-120-75-75-m-70-iso8859-1
So in the preceding, the alias is lucidasanstypewriter-12. So your rxvt command would be as follows for this font:
rxvt -fn lucidasanstypewriter-12

12. Initiating svscan in Ubuntu (for djbdns, for instance)

The way DJB conceived djbdns, it would autostart using a line in /etc/inittab. Trouble is, Ubuntu doesn't use /etc/inittab. Instead, Ubuntu uses directory /etc/event.d by processing every file in it. So you create /etc/event.d/svscan with the following contents:
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on shutdown
exec /command/svscanboot
Be very, very careful to get the right directory for the svscanboot command or it will silently fail and give you all sorts of trouble.

13. Finding All Info About All Partitions

The below command can help you find out all what you need to know about all the partitions: Device name, uuid, label, and mount point (if any):

courtesy: troubleshooters

Fonte: 13 Quick Hacks For Linux!

Nenhum comentário:

Postar um comentário