12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Shell Basics 105To remove a directory, invoke the rmdir command, where is adirectory within the current directory or the full path to the directory. If any files are still inthe directory , the error message Directory not empty will be displayed, and the directorywill not be deleted. This prevents users from removing a directory that still contains files.TIPTo force the removal of a directory with all the files and subdirectories within thatdirectory, use the rm -rf command. This command does not ask you toconfirm the deletion, and there is no way to reverse the removal of the files and directories.Use extreme caution with this command. Double-check the directory specifiedbefore pressing Enter to execute the removal.To remove a file, use the rm command. If only the filename is specified, it must bein the current working directory. Alternatively, the full path to the file and the filenamecan be specified such as the rm /home/tfox/status.odt command.4To view the contents of a current directory, execute the ls command, or use the ls command to view the contents of . As with the othercommands discussed, can be relative to the current working directory or thefull path to a directory. The ls command accepts the * wildcard character. For example,to list all the OpenOffice.org text documents, use the ls *.odt command, or the lsstatus* to find all files whose filename begins with status. Multiple wildcards can beused such as ls *status* to list all files that have status somewhere in their name.To copy a file from one location to another, use the cp , where is thefile to copy and is the directory or filename to copy it to. If the specified is adirectory, the file is copied to that directory using the same filename. The directory can bethe full path to a location or a directory relative to the current working directory. If a filenameis specified for , the original file is copied to another file with the specifiedname. If a path followed by a filename is used, the file is copied to another file with thenew name in the specified directory. For example, the cp status.txt reports/status01.txt will copy the status.txt file from the current working directory to thereports/ directory relative to the current working directory as the new filenamestatus01.txt. The reports/ directory must exist, or the error message cp: cannotcreate regular file `reports/status01.txt’: No such file or directory isdisplayed, and the file is not copied.When a file is moved, the file no longer exists in the original location. The mv command is similar to the cp command. The only difference is that the original file will no longer exist after the move operation.Multiple files can be specified as the for both the cp and mv commands, and bothcommands accept the * wildcard. For example, the mv *.txt textfiles/ commandmoves all files that end in .txt to the textfiles/ directory in the current working directory.Or, multiple files can be specified using their filenames. For example, cp chap1.odtchap2.odt chap3.odt backup/ copies the chap1.odt, chap2.odt, and chap3.odt files tothe backup/ directory.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!