blog.up-link.ro
12Feb/100

10 Linux Tips and Tricks

Here you will find a collection of usefull tips and tricks for Linux-based Operating Systems.

1. How to remove a file with a dash as first character?

If you accidentally created a file with a "-" in the beginning then you want to remove it, you have to do :

# rm ./-filename

or

# rm -- -filename

2. How to set-up nice welcome messages?

It's not actually a tip, it's just a nice thing that will make every login more cooler.
Go to http://www.filewatcher.org and search for "fortune". Download the version that appliesĀ  to your system (tar.gz or rpm) and install it. Locate where the ELF executable fortune has been placed and then add to /etc/profile the following line:

# /usr/games/fortune

(replace /usr/games with ELF executable path )

This will cause a random "fortune cookie" to appear every time a user logs in.
Alternatively, you can place that line in an independent user's ~/.profile so only he will have this feature enabled.

3. How to get your external IP address?

# wget -O - -q icanhazip.com

4. How to find which libraries a program requires?

To find out which shared libraries a program requires, type:

# ldd program

where program is the program with the full path. Ex: ldd /usr/bin/php

5. How to change the encoding of a text file?

iconv -f INITIAL_ENCODING -t DESIRED_ENCODING filename

For example:

iconv -f ISO-8859-16 -t UTF-8 file.txt

Will change the encoding of file.txt from ISO-8859-16 (Romanian) to UTF-8.

6. How to show date using format modifiers?

date +"%H:%M:%S"

Will output time in format HOUR:MINUTE:SECOND. The double quotes are required in case you need to use spaces. You should read man pages for more formats.

7. How to determine which processes use the most memory?

# ps aux | sort -nk 4 | tail

8. How to examine driver and firmware versions of your Ethernet adapter?

# ethtool -i eth0
driver: e1000
version: 7.3.30-k3-NAPI
firmware-version: 0.3-2

9. How to print a man page?

# man <manpage> | col -b | lpr

The col -b command removes any backspace or other characters that would make the printed man page difficult to read.

10. How to find out what kernel version you are running?

You can find out with the uname command, which prints information about the system. Issued with the -r option, uname prints the kernel version:
# uname -r
2.6.18-164.11.1.el5

Print This Post Print This Post
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


*

No trackbacks yet.