Creating New Directories Using mkdir
"." parent directory
".." home directory
$ mkdir dirname
mkdir has no command arguments.
There are two things to keep in mind: You must have write permission to the current directory if you’re creating a new directory, and you should ensure that the name of the directory is not the same as (or, to avoid confusion, similar to) a directory name that already exists.
Copying Files to New Locations Using cp
$ cp original-file new-file-or-directory
$ cp list-of-files new-directory
Generally, UNIX won’t permit you to use the cp command to copy directories.
UNIX copied the file over the existing file. The mv command will cause the same problem.
The good news is that you can set up UNIX so it won’t overwrite files. The bad news is that for some reason many systems don’t default to this behavior. If your system cannot be set up to respond this way, you can use the -i flag to both cp and mv to avoid this problem. Later, you learn how to permanently fix this problem with a shell alias.
Moving Files to New Locations Using mv
$ mv original-file new-file-or-directory
$ mv list-of-files new-directory
Renaming Files with mv
Removing Directories with rmdir
The rmdir command removes only directories that are empty.
To remove a directory, you must first remove all files therein using the rm command.
The permissions of the parent directory, rather than the directory you’re trying to remove, are the important consideration.
Removing Files Using rm
$ rm ...
$ rm -l ... (the i stands for interactive y/n in this case)
$ rm -r ... remove all files and directories inside it
you can give several commands in a single UNIX command line. To do this, separate the commands with a semicolon.
$ ls -l;ls-m
Minimizing the Danger of the rm Command
$ grep miscall /etc/passwd
miscall:x:202:204::/usr/local/miscall:/bin/sh
smsboss:x:204:206::/usr/local/miscall/globalcall/cdr:/bin/sh
Bourne shell sh
Korn shell ksh
C shell csh
Bourne shell is the original command shell of UNIX, lacks an alias feature, a feature that both the Korn shell (ksh) and the C shell (csh) include
$ ls -lF /bin/sh /bin/ksh /bin/csh
lrwxrwxrwx 1 root root 4 Sep 29 2008 /bin/csh -> tcsh*
-rwxr-xr-x 1 root root 1388936 Jan 16 2007 /bin/ksh*
lrwxrwxrwx 1 root root 4 Sep 29 2008 /bin/sh -> bash*
$ chsh
You can use a shorthand, a shell alias, to attach the -i flag automatically to each use of rm. To do this, you need to ascertain what type of login shell you’re running, which you can do most easily by using the following command.
If your entry is /bin/csh, enter exactly what is shown here:
% echo "alias rm /bin/rm -i" >> ~/.cshrc
% source ~/.cshrc
If your entry is /bin/ksh, enter exactly what is shown here, paying particular
attention to the two different quotation mark characters used in the example:
$ echo 'alias rm="/bin/rm -i"' >> ~/.profile
$ . ~/.profile
password entry For each account on the UNIX system, there is an entry in the account
database known as the password file. This also contains an encrypted copy of the account
password. This set of information for an individual account is known as the password entry.
recursive command A command that repeatedly invokes itself.
shell alias Most UNIX shells have a convenient way for you to create abbreviations for
commonly used commands or series of commands, known as shell aliases. For example, if
I always found myself typing ls -CF, an alias can let me type just ls and have the shell
automatically add the -CF flags each time.