UNIX / Linux Tutorial
Chapter 1
1.2.10 Referring To Home Directories | 1.3 First Steps Into Linux | 1.3.1 Moving Around
1.3.2 Look At The Contents Of Directories | 1.3.3 Creating New Directories
1.2.10 Referring To Home Directories
Under both tcsh and bash (1) you can specify your home directory with the tilde character (~). For example, the command:
/home/patrick# more /home/patrick/papers/history-final
The shell replaces the (~) character with the name of your home directory.
You can also specify other user’s home directories with the tilde character. The pathname ~rick/letters translates to
/home/rick/letters by the shell (if /home / rick is rick’s home directory). Using a tilde is simply a shortcut; the directory named ~ does not exist--it’s just syntactic sugar provided by the shell.(1) tcsh and bash are two shells that run under Linux. The shell is a program that reads user commands and executes them; most Linux Systems enable either tcsh or bash for new user accounts.
1.3 First Steps Into Linux
Before we begin, it is important to know that all file and command names on a Linux System are case-sensitive (unlike Operating Systems such as MS-DOS). For example, the command make is very different from Make or MAKE. The same is true for file and directory names.
1.3.1 Moving Around
Now that you can login and you know how to refer to files using pathnames, how can you change your current working directory, to make life easier? The command for moving around in the directory structure is cd, which is short for "change directory". Many often-used Linux commands are two or three letters. The usage of the cd command is:
cd directory
where directory is the name of the directory which you wish to become the current working directory.
As mentioned earlier, when you login, you begin in your home directory. If Patrick wanted to switch to the papers subdirectory, he would use the command:
/home/patrick# cd papers
/home/patrick/papers#
As you can see, Patrick’s prompt changes to reflect his current working directory (so he knows where he is). Now that he is in the papers directory, he can look at his history final with the command:
/Home/patrick/papers# more history-final
Now, Patrick is stuck in the papers subdirectory. To move back up to the next higher (or parent) directory, use the command:
/home/patrick/papers# cd...
/home/patrick#
(Note the space between the "cd" and the (".."). Every directory has an entry named ".." which refers to the parent directory. Similarly, every directory has an entry named "." which refers to itself. Therefore, the command:
/home/patrick/papers# cd.
will get us nowhere.
You can also use absolute pathnames with the cd command. To cd into Karl’s home directory, we can use the command:
/home/patrick/papers# cd /home/karl
/home/karl#
Also, using cd without argument will return you to your own home directory.
/home/karl# cd
/home/patrick#
1.3.2 Look At The Contents Of Directories
Now that you know how to move around directories, you might think, "So what?" Moving around directories is fairly useless by itself, so check out this new command, ls. The ls command displays a listing of files and directories, by default from your current directory. For example:
/home/patrick# ls
letters
papers
/home/patrick#
Here we can see that Patrick has three entries in his current directory: mail, letters and papers. This doesn’t tell us much-are these directories or files? We can use the -F option of the ls command to get more detailed information:
/home/patrick# ls--F
mail/
letters/
papers/
/home/patrick#
From the / appended to each filename, we know that these three entries are in fact subdirectories.
Using ls-F may also append * to the end of a filename in the resulting list which would indicate that the file is an executable, or a program which can be run. If nothing is appended to the filename using ls-F, the file is a "plain old file", that is, it’s neither a directory nor an executable.
In general, each Unix command may take a number of options in addition to other arguments. These options usually begin with a - as demonstrated above with the -F option. The -F option tells ls to give more information about the type of the files involved--in this case, printing a / after each directory name.
If you give ls a directory name, the System will print the contents of that directory.
/home/patrick# ls--F papers
english-lit
hsitory-final
masters-thesis
notes/
/home/patrick#
Or, for a more interesting listing, let’s see what’s in the System’s /etc directory:
/home/patrick# ls /etc
Or, for a more interesting listing, let's see what's in the system's /etc directory: /home/patrick# ls /etc Images ftpusers lpc rc.new shells adm getty magic rc0.d startcons bcheckrc gettydefs motd rc1.d swapoff brc group mount rc2.d swapon brc˜ inet mtab rc3.d syslog.conf csh.cshrc init mtools rc4.d syslog.pid csh.login init.d pac rc5.d syslogd. default initrunlvl passwd rmt termcap disktab inittab printcap rpc umount fdprm inittab.old profile rpcinfo update fstab issue psdatabase securetty utmp ftpaccess lilo rc services wtmp /home/patrick# If you're a MS-DOS user, you may notice that the filenames can be longer than 8 characters, and can contain periods in any position. You can even use more than one period in a filename. Let's move to the top of the directory tree, and then down to another directory with the commands:
/home/patrick# cd .. /home# cd .. /# cd usr /usr# cd bin /usr/bin# You can also move into directories in one step, as in cd /usr/bin. Try moving around various directories, using ls and cd. In some cases, you may run into the foreboding "Permission denied" error message. This is simply UNIX security kicking in: in order to use the ls or cd commands, you must have permission to do so. 1.3.3 Creating New Directories It's time to learn how to create directories. This involves the use of the mkdir command. Try the following: /home/patrick# mkdir foo /home/patrick# ls -F Mail/ foo/ letters/ papers/ /home/patrick# cd foo /home/patrick/foo# ls /home/patrick/foo# Congratulations! You made a new directory and moved into it. Since there aren't any files in this new directory, let's learn how to copy files from one place to another.
1.1 Introduction 1.2.10 Referring To Home Directories 1.3.4 Copying Files
1.6 Exploring The File System 1.8 Wildcards 1.9.3 Pipes 1.10.3 Permissions Dependencies
1.12.4 Stopping And Restarting Jobs 1.13.3 Inserting Text 1.13.9 Including Other Files
1.14.3 Shell Initialization Scripts System Administration 2.3.1 The /etc/imitate file
2.4 Managing File Systems 2.6 Managing Users 2.6.5 Groups 2.7.2 gzip and compress
2.8.3 Making Backups To Tape Devices 2.9.1 Upgrading The Kernel
2.9.3 Installing A Device Driver Module
BOOK: LINUX QUICK COMMAND REFERENCE
http://personal.atl.bellsouth.net/~psadler
© copyright KnowledgeWorks, Inc. (2001)