The rm Command
The rm command is probably one of the first commands you learned. Here we look at some options that may save you a lot of time. Before we get into the details, some words of warning. In the Unix tradition, Linux does not ask unnecessary questions. If you tell it to remove a file or a set of files, it will do just that. If you want it to ask you for confirmation, you will need to ask it to do that.
The basic syntax of rm is:
rm [options] filenames
The options must start with a -. One or more filenames can be specified, and wildcards are permitted (because the shell, not rm, expands them).
If you are not familiar with wildcards (* and ? to name the most dangerous), read up on them. Placing a wildcard character in the file name list by accident can make you a very unhappy camper.
rm is the command used, in Linux terminology, to unlink a file. What this means is that the directory entry for the file is removed. A side effect (and the effect that we generally expect) is that the file is deleted. But this may not be the case.
The Linux file system makes it possible for a file to have more than one name or directory entry. The ln command allows you to create these additional names or links. If these links are hard links, links created with the ln command without the -s option, you have a file that can be accessed by these multiple names.
By using the rm command on one of these names, you only delete the name, not the actual file. When the last name pointing to the file is removed, the file is finally removed.
Now that you know about the basics, there are a bunch of options that make it possible to do more than just remove a file. A handy option for the timid is -i. The -i stands for interactive. When specified, rm will prompt you before it deletes each file. If you respond with y or Y the file will be deleted, otherwise the delete will be skipped.
For example, if you enter:
rm -i dog cat pig
you will be prompted with:
rm: remove `dog'?
Pressing y or Y and <return> will cause the file dog to be deleted. No matter what you pressed, rm will then move along to the next file, in this case cat, and prompt again.
Normally, if rm encounters a file that you do not have write permission to, but you do have permission to modify the file's directory, it will ask for confirmation. You then enter y or Y followed by <return> to force the removal of the file. The -f option overrides this default behavior. If you specify -f, rm will do the removal without the prompt. This option also eliminates the error message that rm generally produces if a specified file is not found.
Now, the scary option, -r. The -r stands for recursive. If you specify a directory name and the -r option, rm will remove the specified directory and all its contents, including any subdirectories contained within it (and the subdirectories' files and subdirectories and so forth). For example, if you had a directory named Joe in your current directory which contained the files name address phone and a directory Other that contained the files ssn and age, you could delete each file individually with the following command:
rm Joe\name Joe\address Joe\phone Joe\Other\ssn\ Joe\Other\age
You could then use the rmdir command to remove the directories Other and Joe:
rmdir Joe/Other Joe
rm -r Joe
Finally, a trick. A common problem people run into is how to delete a file whose name starts with a -. For example, if you entered the command
in an attempt to remove a file named -garbagefile, you would get the error message:
rm: illegal option -g
Try rm -help for more information.
This is because rm assumes that if its first argument starts with a - it is an option. The solution is to use a name that does not confuse rm. For example, you can use either the full pathname of the file or a relative pathname where you explicitly specify the current directory using ./. Thus, the following command would do the job:
Phil Hughes is the publisher of Linux Journal.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- Google's SwiftShader Released
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Managing Linux Using Puppet
- Non-Linux FOSS: Caffeine!
- Interview with Patrick Volkerding
- SuperTuxKart 0.9.2 Released
- Parsing an RSS News Feed with a Bash Script
- Doing for User Space What We Did for Kernel Space
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide