LINUX
Intro:The lab for this lesson will introduce you to the concepts offilesystems. To begin the lab, please use the script command torecord your session. $ script flast_lab11.scr
Activity 1: statThe stat command provides the ability to look up file or systemstatus information. One of the more common usages for the statcommand is to view a great deal of information about a file, forexample, the last time a file was accessed, modified, which diskit's sitting on, etc. Run the stat command on your .bashrcfile:$ stat ~/.bashrcYou may wonder about the difference between the "modification time"and "change time" in the stat report. "Change" refers to a changeto the file metadata (e.g., ownership and/or link information -we'll get to this later) whereas modification means the filecontents have changed (e.g., you've added to it or removedsomething from it).Activity 2: pwdThe pwd (print working directory) command is a quick way todetermine your current directory. Up until this point, we have notmade use of directories very much, so run pwd and you'll likely seeyour home directory is listed:$ pwdThe pwd command (or your shell's builtin equivalent) is usuallypretty simple. Pull up the man page and notice how many options areavailable. Run the pwd command with the option for determining yourphysical directory (avoiding all symbolic links). It's OK that youdon't know what symlinks are yet - we'll get to that in a futurelesson. Also, note that it's likely your home directory isn't asymlink, so the output of both pwd commands may be the same.Activity 3: Using ~The tilde is not a command, but rather a special variable; we'veused it a few times already. The main purpose of the tilde is toprovide a quick shortcut to your user directory. For example, runthe following commands:$ pwd$ cd /$ pwd$ cd ~The cd command changes your directory. In this case, we're tellingthe computer: 1) Show me the current directory. 2) Change Directoryto the root (/) directory. 3) Show me the current directory. 4)Change Directory to my user directory. If you get lost and don'tknow what directory you're in, the simple "cd ~" command can bevery useful.Activity 4: Using relative and absolute pathnamesIn unix, there are two different ways to refer to a directory - byits absolute path or by a relative path. For example, let's createtwo directories off your user dir:$ mkdir cis18a_lesson11a$ mkdir cis18a_lesson11bLet's cd to the first directory and run the pwd command. When we cdto the directory without specifying all the enclosing folders, weare using a relative pathname:$ cd cis18a_lesson11a$ pwdYou should see something like "/home/kmetcalf/cis18a_lesson11a"returned by the pwd command. This is the absolute pathname for thedirectory. Absolute paths are typically easy to spot because theyvirtually all begin with a ~ or a / at the far left. Absolute pathsare NOT ambiguous. It does not matter which directory you startfrom. If you cd to an absolute path (and if you have permission toview that directory) you will ALWAYS end up in the same directory.Let's contrast that with relative path names. Run the followingcommand:$ cd ../cis18a_lesson11b$ pwdYou should see something like "/home/kmetcalf/cis18a_lesson11b"returned by the pwd command. When you run this command, thedirectory you end up in can change, depending on which folder youare in when you run the command. The directory ../cis18a_lesson11bdoes NOT start with a / on the far left - it is NOT an absolutepath. We refer to this as a "relative path" instead. Return to youruser directory with:$ cd ~Note that there is some confusion about whether a pathnamebeginning with a tilde is an absolute or relative pathname."Absolute" pathname in this case means that the directory presentedto a command will not change depending on where you are. Whenyou're tying things at the command line, the shell (in our case,bash) is sometimes changing values en route. We can use the echocommand to see what has been passed to the command. Run thefollowing two commands and notice the difference between the valuesreturned:$ echo ../cis18a_lesson11b$ echo ~/cis18a_lesson11bThe echo command shows us that the pathname beginning with a tildewas automatically expanded to an absolute pathname by the shellbefore it reached echo. In practice, however, you may run acrosslinux users who refer to ~ pathnames as "relative" instead of"absolute." The argument is that the pathname will change dependingon who is running it. Technically, however, the ~ pathnames will beinterpreted by the shell, so they are "absolute pathnames."Note: In the event you are writing a script and need to ensure thata path to a command never changes, be sure to always begin yourpathnames with a / at the far left to ensure there's noconfusion.Activity 5: . vs ..The next two relative path entries are . and .. (one period and twoperiods; no spaces). These are special relative path designations.The single dot means "this directory." For example, "./mydir" means"the directory called "mydir" located in the current directory.Contrast this with the double dot (..) which means "the parent ofthis directory." By parent we mean "the directory located one entryto the left in the absolute pathname of the current workingdirectory." In other words, for the directory /home/kmetcalf, theparent directory is /home. Directories can also have children.Earlier in this lab we created a directory called/home/kmetcalf/cis18a_lesson11a. From /home/kmetcalf/, thedirectory cis18a_lesson11a is a child directory. From your homedirectory, type the following:$ pwd$ cd .$ pwd$ cd ..$ pwdThe first pwd will show you your home directory. The first cd willnot change your current working directory. It may seem useless atfirst, but we'll explain what it's good for in a future lesson. Thesecond directory change (cd ..) moves us "up" one directory - if wethink in terms of a directory tree. By using the . and .. entrieswith the cd command, we can rapidly navigate folders without havingto use long absolute path names. Try the following:$ cd ~/cis18a_lesson11a$ pwd$ cd ../cis18a_lesson11b$ pwdPay close attention to the difference between those commands.
LINUX Intro: The lab for this lesson will introduce you to the concepts of filesystems. To begin the lab, please use the
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am