Wątki

[ Pobierz całość w formacie PDF ]
." and.".The directory."refers to the current directory and." is the parent directory.These are shortcut" directories.They exist in every directory, but don't really t the folder in a folder" concept.Even the rootdirectory has a parent directory|it's its own parent!The le.chapter-1 would be the le called chapter-1 in the current directory.Occasion-ally, you need to put the." for some commands to work, although this is rare.In most cases,.chapter-1 and chapter-1 will be identical.The directory." is most useful in backing up":usr local bin cd.usr local ls -Farchives bin emacs@ etc ka9q lib tcl@usr local ls -F.srccweb linux xmrisusr localIn this example, I changed to the parent directory using cd., and I listed the directoryusr src from usr local using.src.Note that if I was in home larry, typing ls -F.srcwouldn't do me any good!The directory ~ is an alias for your home directory:usr local ls -F ~usr localYou can see at a glance that there isn't anything in your home directory! ~ will become moreuseful as we learn more about how to manipulate les.4.3.3 Creating and Removing Directoriesmkdir directory1 directory2.directoryNCreating your own directories is extremely simple under Unix, and can be a useful organizationaltool.To create a new directory, use the command mkdir.Of course, mkdir stands for makedirectory.Let's do a small example to see how this works:home larry ls -Fhome larry mkdir report-1993home larry ls -Freport-1993home larry cd report-1993home larry report-1993 4.4.MOVING INFORMATION 31mkdir can take more than one parameter, interpreting each parameter as another directory tocreate.You can specify either the full pathname or a relative pathname; report-1993 in the aboveexample is a relative pathname.home larry report-1993 mkdir home larry report-1993 chap1 ~ report-1993 chap2home larry report-1993 ls -Fchap1 chap2home larry report-1993rmdir directory1 directory2.directoryNThe opposite of mkdir is rmdir remove directory.rmdir works exactly like mkdir.An example of rmdir is:home larry report-1993 rmdir chap1 chap3rmdir: chap3: No such file or directoryhome larry report-1993 ls -Fchap2home larry report-1993 cd.home larry rmdir report-1993rmdir: report-1993: Directory not emptyhome larryAs you can see, rmdir will refuse to remove a non-existant directory, as well as a directory thathas anything in it.Remember, report-1993 has a subdirectory, chap2, in it! There is one moreinteresting thing to think about rmdir: what happens if you try to remove your current directory?Let's nd out:home larry cd report-1993home larry report-1993 ls -Fchap2home larry report-1993 rmdir chap2home larry report-1993 rmdir.rmdir:.: Operation not permittedhome larry report-1993Another situation you might want to consider is what happens if you try to remove the parent ofyour current directory.This turns out not to be a problem since the parent of your current directoryisn't empty, so it can't be removed!4.4 Moving InformationAll of these fancy directories are very nice, but they really don't help unless you have some place tostore you data.The Unix Gods saw this problem, and they xed it by giving the users les. 32 CHAPTER 4.THE UNIX SHELLWe will learn more about creating and editing les in the next few chapters.The primary commands for manipulating les under Unix are cp, mv, and rm.They stand forcopy, move, and remove, respectively.4.4.1 cp Like a Monkcp -i source destinationcp -i le1 le2.leN destination-directory7cp is a very useful utility under Unix, and extremely powerful.It enables one person to copymore information in a second than a fourteenth century monk could do in a year.Be careful with cp if you don't have a lot of disk space.No one wants to see a Disk full" messagewhen working on important les.cp can also overwrite existing les without warning|I'll talk moreSLOWabout that danger later.We'll rst talk about the rst line in the command template.The rst parameter to cp is the leto copy|the second is where to copy it.You can copy to either a di erent lename, or a di erentdirectory.Let's try some examples:home larry ls -F etc passwdetc passwdhome larry cp etc passwd.home larry ls -Fpasswdhome larry cp passwd froghome larry ls -Ffrog passwdhome larryThe rst cp command I ran took the le etc passwd, which contains the names of all theusers on the Unix system and their encrypted passwords, and copied it to my home directory.cpdoesn't delete the source le, so I didn't do anything that could harm the system.So two copies ofetc passwd exist on my system now, both named passwd, but one is in the directory etc andone is in home larry.Then I created a third copy of etc passwd when I typed cp passwd frog|the three copiesare now: etc passwd, home larry passwd and home larry frog.The contents of these threeles are the same, even if the names aren't.cp can copy les between directories if the rst parameter is a le and the second parameter isa directory.In this case, the short name of the le stays the same.7cp has two lines in its template because the meaning of the second parameter can be di erent depending on thenumber of parameters. 4.4.MOVING INFORMATION 33It can copy a le and change it's name if both parameters are le names.Here is one danger ofcp.If I typed cp etc passwd etc group, cp would normally create a new le with the contentsidentical to passwd and name it group.However, if etc group already existed, cp would destroythe old le without giving you a chance to save it! It won't even print out a message remindingyou that you're destroying a le by copying over it [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • mikr.xlx.pl
  • Powered by MyScript