Removing Files on a Linux Server

An important part of file management is the removing of files that are no longer needed. Files, by their very nature, take up space, and something that is not needed should not take up space on a server, where space is money. The “rm” Linux command handles basic removal of files, but here are some additional settings you can use with “rm” to handle various types of removal tasks.
rm -l With the “-l” flag added after “rm”, the command will prompt you only when removing more than three files. You can use this as a precaution to keep from accidentally removing large amounts of data.
rm –one-file-system This instructs “rm” to remove only files that match the current file system, which is useful when removing several directories at once.
rm -r Recursive removal means that the top-level directory and the files and directories inside it will be removed together.
rm -v This displays information about the removal, rather than just returning to an empty command prompt.
rm -f To force removal without any prompting or warnings, use the “-f” flag, but please use it carefully.
Tag: command, files, filesystem, force, linux, recursive, remove, rm, space
Finding Linux files with "locate"

There are a few of ways to find files on a Linux server, but most of them involve actually searching through each file in the filesystem until the correct one is located. This can be time consuming and taxing on the server’s CPU load, especially if you have a lot of files.
Linux has two commands that make searching a little easier: locate and slocate. Unlike other find utilities, locate searches through a database that contains information about the filesystem, bringing up the search results almost instantaneously. The command to update the database is called “updatedb”, and many Linux distributions have the command run via cron every day.
The alternative version of locate, called slocate, is a security-enhanced version that only allows the user to find files he or she has the permission to access. While locate is a great tool for finding things on a server, it does have its issues. For one, you will only find files that were added or changed prior to the last updatedb execution. Furthermore, the very process of updating the database can be taxing on the server, even if it is only once a day. For the right situations, however, locate is a very useful Linux tool.
Photo Source: Flickr
Tag: command, cpu, database, filesystem, linux, locate, search, server, slocate
How to create a tmp partition in Linux

As we mentioned in a previous post, setting up extra partitions beyond the standard Linux partitions can have certain security and performance benefits. One of the major directories that you should consider partitioning is the /tmp directory. In Linux, temporary files are stored there and accessed when applications need to use them.
Unfortunately, /tmp is also a prime spot for hackers to plant their malicious executables and use your server as the jumping off point for SPAM, bot attacks, and other malicious objectives. Follow these steps to separate /tmp from your root partition and make it non-executable.
If you wanted the partition to be 512MB for example:
# mkdir /filesystems
# dd if=/dev/zero of=/filesystems/tmp_fs seek=512 count=512 bs=1M
# mkfs.ext3 /filesystems/tmp_fs
Add the following line to /etc/fstab:
/filesystems/tmp_fs /tmp ext3 noexec,nosuid,loop 1 1
Then, mount the partition:
# mount /tmp
Source: Parallels
Photo: Flickr
Tag: attacks, filesystem, linux, partition, security, server, spam, tmp
5 Server checks for the New Year

Hopefully, it has not been a year since you have given your server a good checkup, but just in case you need a reminder, here are a few things to check at the start of 2010:
1. Log rotation. Normally, Linux will rotate logs for the kernel, web server, and other applications, saving older ones under alternate names. You should check in /var/log and make sure it’s all working as expected.
2. Filesystem. Run a basic filesystem check (fsck) to see if there are any disk errors. It is important to find them before they lead to data loss.
3. Updates. If you have not installed the latest updates, particularly kernel patches, do it now. An off day is the perfect time to perform a mandatory reboot.
4. Security check. Do a system-wide check for rootkits, vulnerabilities, viruses, and rogue scripts.
5. Memory and CPU usage. Run “top” and monitor CPU and memory usage for a few minutes. Check your load averages. Make sure all of it is within your desired parameters.
Now that you are done with that, enjoy your New Year with a little more peace of mind.
Photo: Flickr
Tag: cpu, filesystem, linux, logs, security, web server
How to format a hard drive in Linux
When you lease a remote managed or even unmanaged server, you do not typically have to concern yourself with formatting hard drives. Still, it is a good skill to learn, and if you find yourself in a situation where you are building your own web hosting server, it is a very useful skill to have. For desktop Linux, there are plenty of graphical tools for formatting, but on a server, you will have to dig your hands into the soil of the command line. Follow these easy steps:
1. Find the name of your hard drive:
# fdisk -l | grep '^Disk'
It will give you a list of the available disks. Make sure you choose the right one:
Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes
2. Create at least one disk partition:
# fdisk /dev/sdb
For more information about hard disk partitioning, see this guide.
3. Format the hard drive. For this you actually use the mkfs (make filesystem) command:
# mkfs.ext3 /dev/sdb1
(Ext3 is a filesystem type. You can use others, such as vfat)
Read the rest of the steps, including mounting your new system at nixCraft.
Tag: fdisk, filesystem, hard drive, linux, mkfs, server
The /usr/bin directory in Linux

In an earlier post, we gave you a brief overview of the Linux filesystem structure. The /usr/bin directory is the main directory for user executables. Essentially, any program you might want to run will usually have an executable in this directory. It is important to note, however, that unlike Windows, not all of the program’s files are in one directory. Only the executables are kept in /usr/bin.
The default Linux path on all distributions includes /usr/bin. Therefore, you do not need to type the entire path to execute a program. For example, if you want to run “top”, you just type “top” without needing to enter “/usr/bin/top”. When you install scripts and applications, however, they might still ask for the full path to the executable on your server. In that case, you would still need to prefix the command with “/usr/bin”.
There is a chance that the program you are looking for is installed elsewhere, like /usr/local/bin or /usr/sbin. The “which” command will reveal its true location. Simple type: “which top” or “which” followed by the command you need to locate. If you are not sure what the exact name is, you can try sorting through the directory like this:
cd /usr/bin
ls -al | grep make
This will output all executables with the word “make” anywhere in its name, such as qmake, makeconv, automake, and imake.
Tag: bin, executables, filesystem, linux, server
Using the "ls" Command in Linux

In Linux, few commands are more important when managing your file system than “ls”. On a server, it is very important to know how to view files and their properties. With “ls” you can view a simple list of files or any number of more complicated variations of the list.
Typing “ls” with no flags will give you multiple columns of files and directories in alphabetical order. Adding an “-a” flag will display hidden files (those with a “.” in front of the names). Add an “-l” flag, and you will see long format, with directory information, permissions, file size, and modification date.
Some servers are set to show colors by default. If yours is not, add the “–color” flag to show your directories and various files in different colors, which makes it easier to distinguish a directory from a file and an executable from a text file. Add an “-r” to display the results in reverse order. “-U” will not sort them at all and leave them in directory order. There are many other combinations and flags you can use with “ls”. For a complete guide, type “man ls” from the command line.
Tag: command, files, filesystem, linux, ls, permissions, server