Are you looking for a simple way to improve your Linux skills? Our Linux TechMail is the answer. This message contains valuable information that can save you time and effort. Below, you'll find five examples of what this TechMail has to offer. Get tips on printing, networking, security, and much more, all delivered straight to your inbox—absolutely free! Sign up for the Linux TechMail today!
Undo a tar extraction
If you extract a huge tar archive to the wrong location, here's an easy way to undo the operation. Suppose you've just run the tar command to extract the files from an archive named tons_of_files.tar. By default, the tar utility extracts the files to an archive created one directory below the working directory. Here's the command you run to extract the archive:
tar -xvf tons_of_files.tar
Now, suppose you realize that you really didn't want to extract all those files to a directory positioned one level below the current directory. Fine, but what do you do about all those extraneous files? The following command uses the xargs utility to remove the files you just extracted. It works by using the tar command to list the files; the list is then passed via a pipe to xargs, which runs the rm command on each of the extracted files. Here's the command:
tar -tf tons_of_files.tar | xargs rm
After you run this command, the extracted files will be gone.
Change the ownership of a group of files
The Linux filesystem is designed for use by more than one person. The key to exploiting this capability is the ability to assign the ownership of a file to a group as well as to an individual. Once a file's ownership is assigned to a group, the file's group permissions specify what the members of the group can do with the file. For example, a group called team1 could be given read and write privileges to a file named Proposal.doc. This means that any member of the team would be able to open and modify Proposal.doc.
It makes good sense to place all the files a group will use into a single directory that's reserved for the group's use. Thanks to the chgrp command, you can easily change the group membership of all the files in a directory. To do so, follow these instructions:
- In a terminal window, type su and press [Enter] and then type the root user's password. You need to be the root user to change the group ownership of a file.
- Change to the directory that contains the file, if necessary.
- Type chgrp -R followed by the name of the group and press [Enter]. So, for example, to change the ownership of all the files in the directory to team1, you'd type chgrp -R team1 and press [Enter].
Kill that program the easy way
Users migrating to Linux from Microsoft Windows will hunt in vain for the handy [Ctrl][Alt][Delete] shortcut, which enables Windows users to terminate a comatose program. In console mode (or in a terminal window), the solution involves using the ps utility to determine the process identification number (PID) of the stalled process and then using the kill command to remove the software from the computer's memory.
But there's an easier way if users are running the X Window System. Most window managers include a window control menu that enables users to kill a stalled process (the one that's running within the process' window). For example, the Sawfish window manager that is included with the current GNOME desktop environment enables users to kill the process nicely (equivalent to a SIGTERM message) or brutally (equivalent to a SIGKILL message). Sometimes an application crashes in a way that brings X down too; if X won't respond, it's generally possible to avoid a restart by pressing [Ctrl][Alt][Backspace], which restarts the X server software.
Share printers with Samba
One of the best reasons for running Samba, the open source Linux implementation of the Windows networking protocols, lies in the ease with which you can make Linux printers available to Windows users. If you've installed and configured a printer for a Linux system, you can use Samba to make this printer's services available to other users on your network.
Once you've installed Samba on your Linux system and configured it so that Samba networking services are available, a couple of easy modifications to the Samba configuration file, /etc/smb.conf, will do the trick. After logging on as the root user, switch to the /etc directory and open smb.conf with a text editor. Remove the comments in front of the following two lines:
printcap name = /etc/printcap
load printers = yes
Save /etc/smb.conf and quit the text editor. You'll need to restart Samba. (On Red Hat and similar systems, type /etc/rc.d/init.d/smb restart and press [Enter].) In most cases, that's all you need to do to configure the local Linux printer to be available to Windows users on your network. Note that the new printer service may not be immediately available to Windows users; up to 30 minutes may be required for news of the service's availability to propagate throughout the network.
Don’t mess with the /var directory structure
If you’re running low on disk space, you might be tempted to delete directories within the /var directory that don’t look like they’re doing anything important. Don’t! Deleting directories within /var could mess up some of your system’s most important services, such as cron (the command scheduler) and lpd (the printing daemon).
In general, the /var directory is used to store the data that a program or service requires in order to work properly; for example, the printing daemon stores print output files in /var/spool/lpd and associated subdirectories. You may think these are just temporary files, some of which can be deleted when they’re no longer needed—that’s not a safe bet, and it’s a very unwise move to delete any of the directories you’ll find within /var. Many system commands expect certain directories to exist with the /var directory, and they won’t start properly—or at all—if you delete them.
If you would like to receive more Linux tips, sign up for the Linux TechMail. Let us know what you think about this article and the Linux TechMail. Post a comment or send us a note.
Bill Detwiler has nothing to disclose. He doesn't hold investments in the technology companies he covers.
Bill Detwiler is Managing Editor of TechRepublic and Tech Pro Research and the host of Cracking Open, CNET and TechRepublic's popular online show. Prior to joining TechRepublic in 2000, Bill was an IT manager, database administrator, and desktop support specialist in the social research and energy industries. He has bachelor's and master's degrees from the University of Louisville, where he has also lectured on computer crime and crime prevention.