This is the second post of the "Introduction to Unix BASH shell programming" series. Initially, in order to be easier to follow the discussion, some facts concerning the file system structure will be presented. Subsequently, some directory and other basic commands will be discussed, like cp, mv, rm.
Some Unix File System issues
The UNIX file system has records which refer to files and directories. These records are called inodes. According to Wikipedia :
In a Unix-style file system, an index node, informally referred to as an inode, is a data structure used to represent a filesystem object, which can be one of various things including a file or a directory. Each inode stores the attributes and disk block location(s) of the filesystem object's data. Filesystem object attributes may include manipulation metadata (e.g. change, access, modify time), as well as owner and permission data (e.g. group-id, user-id, permissions).
ln - create link. Creates a new inode that points to the same data (address in the disk). This link is called a hard link. ln [-s] <file name> <link name>. When the option -s is used a soft or symbolic link link is created. The symbolic link does not point directly to the data, but to the original inode (much like the link in MS Windows)
Directory BASH commands
mkdir - create a new directory. mkdir <directory name>. The directory name may be sdeclared as an absolute or relative path.
rmdir - remove directory. Delete a directory. rmdir <directory name>. The directory name may be declared as an absolute or relative path, but in ant case it must be empty in order to be removed.
cp - copy file(s) or directory(ies). cp [-i] [-r] [-f] <source file(s)> <target file>. Any combination of files or directories may be used as source. The source files are separated by space. The target could be a file or a directory. In the case of multiple sources the target is a directory. The names of files and directories may be declared using the absolute or relative path. The copy action creates a new inode with the same contents. Thus, a change in either the source or destination file does not reflect to the the other, in contrast with the hard or symbolic links. The -f option does not ask for a permission to overwrite the destination file, when it already exists.
mv - move file(s) or directory(ies). mv [-i] [-r] [-f] <source file(s)> <target file>.This command behaves the same as the copy command except that it removes (deletes) the source object. If the source and destination file are located in the same directory, then the result of the command is to rename the source file giving it the name of the destination.
rm - remove file(s) or directory(ies). rm [-i] [-r] [-f] <source file(s)> <target file>. The -r option removes recursively the contents of the target directory and all subdirectories and files. Be very careful with this command. For example, rm -rf /* might delete all the contents of your disk.