| Search: This Site | People | Departments | Penn State |
![]() |
![]() |
| contact | PRI news | directory | sitemap | home |
rm command for the mv
command (with the name to rename it to) if you want to to rename it.
(helpful if you want to look at the file first before deleting it)
% ll -rw-r--r-- 1 barr 87 May 17 14:02 hey look at me -rw-r--r-- 1 barr 232 May 17 14:09 normal.wp -rw-r--r-- 1 barr 670 May 17 14:01 normal1.wp % rm hey look at me rm: hey: No such file or directory rm: look: No such file or directory rm: at: No such file or directory rm: me: No such file or directory %At the command line, the space character is used to separate arguments to a command. Unfortunately if a file has spaces, this is a conflict! To have UNIX treat what you type as all one file, put single quotes around it:
% rm 'hey look at me' % ll -rw-r--r-- 1 barr 232 May 17 14:09 normal.wp -rw-r--r-- 1 barr 670 May 17 14:01 normal1.wp %
% ll -rw-r--r-- 1 barr 0 May 17 14:20 "oops" -rw-r--r-- 1 barr 0 May 17 14:16 here's a file -rw-r--r-- 1 barr 232 May 17 14:09 normal.wp -rw-r--r-- 1 barr 670 May 17 14:01 normal1.wp % rm "here's a file" % ll -rw-r--r-- 1 barr 0 May 17 14:20 "oops" -rw-r--r-- 1 barr 232 May 17 14:09 normal.wp -rw-r--r-- 1 barr 670 May 17 14:01 normal1.wp % rm '"oops"' % ll -rw-r--r-- 1 barr 232 May 17 14:09 normal.wp -rw-r--r-- 1 barr 670 May 17 14:01 normal1.wp %
' " ! $ ^ & * ? < > ( ) { } [ ] ; \ | ~ `
(The last character is a backquote, which may appear here or on paper
as a forward single quote.)If any of these characters appear in your files, you will need to "escape" them to tell the shell to treat them as their literal value, instead of treating it specially. This is done by putting a backslash (\) before the character. You can also put single quotes (') around the whole thing if there are multiple metacharacters in the filename. (though this won't work right if there is also a single quote in the filename)
Here are a few examples:
% ll -rw-r--r-- 1 barr 53 May 17 14:31 *.log -rw-r--r-- 1 barr 45 May 17 14:33 ;asldfjasd;lkasj;dflaj -rw-r--r-- 1 barr 23413 May 17 14:41 a:\docs\thesis.wp -rw-r--r-- 1 barr 45390 May 17 14:31 save.$ -rw-r--r-- 1 barr 42304 May 17 14:31 ~thesis.txt % rm \*.log % rm ';asldfjasd;lkasj;dflaj' % rm 'a:\docs\thesis.wp' % rm save.\$ % rm \~thesis.txt %
% ll -rw-r--r-- 1 barr 687534 May 17 14:59 g?thesis % rm g\?thesis rm: g?thesis: No such file or directory %In this case, the question mark is a convenient reminder, since the question mark is also a wildcard which matches any single single character. But watch out, because the wildcard may match another file in the directory, say
gothesis.
To make sure you're not deleting files that you don't want to,
use the -i option to rm. This will
remove files interactively, asking you whether to delete
each file in turn before it actually deletes them.
% ll -rw-r--r-- 1 barr 683534 May 17 14:56 gothesis -rw-r--r-- 1 barr 687534 May 17 14:59 g?thesis % rm -i g?thesis rm: remove gothesis? n rm: remove gthesis? y %When all else fails...
you can use this last trick to remove files interactively. Just remember to use-i!!.% rm -i * rm: bigfile.log? n rm: bigfile.lst? n rm: bigfile.sas? n rm: remove gob&ld$e@go???k? y rm: thesis.wp? ^C %After you get prompted for the file you wanted to delete, you can type control-C to abort the rest of the command.Click Here To Return To Main File Management Page
Last modified: 10/26/01 | Contact Webmaster
| Privacy and Legal Statements | Copyright Information | ©Copyright 2006, The Pennsylvania State University |