===================================== Directories: current, HOME, and /home ===================================== -IAN! idallen@idallen.ca Reference: Learning Unix p.43 Some people become confused about: - "your HOME directory" - the directory given to you by the system administrator and into which you are placed when you first log in - this is the usual place to store your files - this is the directory you go to when you type "cd" with no arguments - you own this directory, and therefore you can change its permissions - the name of your home directory is available in the shell keyword variable named "$HOME" (HOME is UPPER CASE) - the name of your home directory is also available in some shells as a leading tilde on a pathname, e.g. ~/assignments, ~/letters, etc. - on many Unix systems, your home directory is located under the system directory named /home e.g. /home/abcd0001, /home/zyxw0002, etc.; but, this is not always true (e.g. not true on ACADUNIX) - the directory named "/home" - this is a pathname (probably and usually a directory, not a file) under the root directory, named "home" - this is NOT your HOME directory; it is (usually) a directory named /home - (/home might be a file name, not a directory; but, this is rare) - some other names (directories) under root are /etc, /bin, and /usr - this is a system directory; you do not own it and you cannot change it - the "current directory" - also called the "current working directory" or "working directory" - this is the directory that your shell (or any Unix process) is currently in - it changes every time you use a "cd" command - all *relative* pathnames in this process are relative to this current directory (absolute pathnames are not affected) - the name of this directory (whatever it is) is always "." (dot) - the current directory of a shell can be changed by using the "cd" command - every process has its own current directory; changing current directory in one process does not change it for other processes - the current directory is passed on to child processes when they are first started (e.g. from your shell process to shell scripts that you invoke) - changing directories inside a shell script will not affect the parent process that called the shell script (different processes) - since you can use the "cd" command to change the current directory of the shell, you may or may not have permissions to list, read, or modify the filenames in the "current directory"; it depends where your current directory is! Problem: "Put the date into a file out.txt in the current directory." Solution: date >out.txt Problem: "Put the date into a file out.txt in your HOME directory." Solution: date >"$HOME"/out.txt Problem: "List the names (including hidden names) in the /home directory." Solution: ls -a /home Problem: "List the names (including hidden names) in the /home directory and append the output to file foobar.txt in your home directory." Solution: ls -a /home >>"$HOME"/foobar.txt Problem: "Move the item named foo.txt from your home directory to the item named bar.txt in the current directory." Solution: mv "$HOME"/foo.txt bar.txt Problem: "Copy the file foo.txt from the current directory to your home directory." Solution1: cp foo.txt "$HOME"/foo.txt Solution2: cp foo.txt "$HOME"/ Solution3: cp foo.txt "$HOME" --------------------------------------- Review: Absolute vs. Relative pathnames --------------------------------------- Pathnames that begin with a slash (or with a shell variable containing a slash) are absolute pathnames: /home /bin/bash /etc/passwd /home/idallen/.bashrc $HOME/.bashrc ($HOME expands to be /home/userid) ~/.bashrc (leading ~ is the same as $HOME) All other pathnames (that do not start with a slash) are relative pathames - the current directory is added to the front of all relative pathnames. For example, if the current directory is "/foo/bar", then: Relative pathname "file" is actually "/foo/bar/file" Relative pathname "./file" is actually "/foo/bar/./file" Relative pathname "." is actually "/foo/bar/." Relative pathname ".." is actually "/foo/bar/.." Relative pathname "dir/xxx" is actually "/foo/bar/dir/xxx" ...etc...