Linux Shorts

30 November -0001
by: Justin
December 11, 2002
Q: How do I tell what ports are open on my machine?

A: Use the 'netstat -l' command to find out what ports (TCP and others) are open and what protocol they are listening on. Note that this doesn't necessarily show you what ports the outside world can see as some of the ports may be firewalled off.

Q: I got a new monitor and my machine is set to start Linux on boot but X fails. How can I get X to stop so that I can log in and change the settings?

A: Start up in safe mode to keep your machine from entering runlevel 5, thats where X starts up. Then you can reconfigure x using Xf86config command line tool. Alternatively if you can ssh into the machine you can edit the file /etc/inittab and comment out the following line:

x:5:respawn:/etc/X11/prefdm -nodaemon

This line tells the machine to fire up X when it reaches runlevel 5, if you comment it out X won't start and you should be able to reboot normally.

Q: I'm new to Linux, what are some good alternatives to the programs I use on Windows?

A: There are actually a TON of useful programs that emulate the functionality you get from Windows programs, here are list of a few:

Window$ ProgramLinux AlternativeURL
MS OfficeOpenOffice
OutlookKMail or Mozilla Mail
Internet ExplorerMozilla
Windows Media PlayerXMovie

Q: How can I start MySQL so that it doesn't listen for remote connections?

A: Start the service using 'mysqld --nolisten tcp' and you should be good to go.

Q: I keep getting spam from the same person/domain, how can I block them?

A: If you're using sendmail you can edit the access database stored in /etc/mail/access. Simply add lines to the script such as:      REJECT      REJECT      ERROR:550 " Piss off!"

The first two will simply reject mail from the specified person in the first case, domain in the second case, with a 'User Unknown' error. The third entry will reject the mail and return it with the error message " Piss off!" in the reply. You can change this wording to whatever you want. You can also use IP addresses instead of domains or email addresses. To block a whole subnet use a trailing period, so using 192.168. will block everything coming from IP to You have to restart sendmail for the changes to take effect.

Q: How can I forward all my email to another address?

A: This is actually quite simple. Create a file named .forward in your home directory and include the new email address in the file. This will forward all mail to the new address.

Q: Can I use a printer that is shared from a Windows machine from my Linux machine?

A: This is actually really simple in Mandrake. You're going to need quite a few packages installed, including the samba-client, samba, and cups packages, but you can use the Mandrake Control Center and it will install all of them for you. When you open up the Mandrake Control Center, select hardware, then printers. Click the 'Configure' button to begin and select 'Add printer' and click 'Ok', then select 'Printer on SMB/Windows 95/98/NT Server' and click 'Ok', then fill in the form with the server host name, IP, the printer share name, and any username/password/workgroup, etc. and click 'OK'. Then fill in a description (its arbitrary), click 'Ok' and print off a test page. Things should work just fine from there on out.

Q: When I press the up arrow key in a bash shell I get my previous command, where is this information stored? Alternatively how can I check to find what commands other users have issued?

A: The history of bash commands is stored in a user (yours for instance) home directory in a file named .bashrc. Note that the preceeding period before the filename will hide it from most directory views. You can open a user's .bashrc file to find out what commands they have issued recently.

Q: How can I find out who has logged into my machine and from where?

A: You can use the 'who' command to find out who is currently logged into your machine and from where. You can use the 'last' command to find out the last several logins.

Q: When I put a cd (or floppy) into the drive I can't see any contents or access the drive, what gives?

A: In Linux you have to 'mount' a drive to be able to use it. Mounting the drive allows users to access information on the media in the drive. You may have to be root to mount a drive, but the command is very simple: 'mount /mnt/cdrom' or 'mount /mnt/floppy'. When you're done with the drive you may need to 'unmount' the drive to eject the cd or floppy. Use the unmount command to do this: 'umount /mnt/cdrom' or 'umount /mnt/floppy'.

Q: I have a whole batch of .mp3 files that I want to convert to .wav, what is the easiest way to do this?

A: The easiest method I have found is to install the package mpg123. Once installed all you have to do is issue the following at the command line:

mpg123 -w file.wav file.mp3

where 'file.wav' is the name of the .wav file you want to create and 'file.mp3' is the name of the mp3 that you have already. This process usually only takes a couple of seconds to complete.