File storage control and access :

Many of these commands have already been covered and a few will revisited in more detail in a later module.

cp
- copy the contents of a file to another file.
mv
- move a filename to a different directory list or change its name.
rm
- remove a filename from a directory list.
mkdir
- create a new directory list.
rmdir
- remove an empty directory.
ln
- create a second name for a file.
Original file must exist and not be a directory. Some other file types can be linked to.
New file name must not exist or -f needed to force.
File names will share the same inode and file data.
  • ln original-file new-file
  • ln -s
    - create a new file with the path to original file stored in it.
    original file does not need to exist.
    And a directory can be symbolicly linked to.
  • ln -s original-file new-file
  • ls - list contents of a directory list.

  • chmod - change access permissions to a file.

  • umask - set initial (default) maximum access permissions for any new file.

  • chown - change ownership of a file. This command usually can only be performed by the system administrator.

    chown user_id filelist

    User_id can be the name or numeric UID of the user of interest. The GNU version will also allow the group id to be changed at the same time.

  • chgrp - change the group association. This command is available to you as long as you owner of the file and are a member of the target group.

    chgrp group_id filelist

  • file - examines the file and attempt to describe the type of file it is. This command recognizes both the standard Unix classifications, (filetypes) and several of the more common file formats such as c source code or shell script. Read the man page on file to see it determines a file's type.

    find - search all sub-directories from a specified starting point for a file matching specified criteria. The following would search for all c source code files in all directories under your home directory.

    find $HOME -name "*.c"

    find will be covered in more detail in its own module.

    Exercise :

    #( Run the following command and look at the output. Lines in parenthesis are comments, don't enter them)

    #( List a character special file. This is the interface to the sound card and takes serial streaming data )

    #(lists possible filetypes recognized)

    file -l  
    
    ls -l /dev/console
    file /dev/console
    
    #( List a symbolic link file. This is the interface to the cd/dvd reader. Because it may be either, two symbolic links to the actual interface file were created. )

    ls -l /dev/dvd
    file /dev/cdrom
    ls -l /dev/cdrom
    ls -l /dev/dvd
    ls -l /dev/sr0
    file /dev/sr0
    
    #( List a block special file. This is the interface to one of the hard drives. )
    ls -l /dev/sda 
    file /dev/sda 
    
    #( List a named pipe. A pipe is a special interface between running processes or programs that allow them to communicate with each other. init is the program that starts most other programs (children) and initctl is a named pipe interface that allows init and its children to communicate. )
    ls -l /dev/xconsole
    file /dev/xconsole
    
    #( List a directory file. )
    ls -ld /dev
    file /dev
    
    #( The following are all regular files but have formats or data specific to certain programs. )

    #( List some different regular files. )

    ls -l /etc/fstab
    file /etc/fstab
    
    file /etc/udev/udev.conf
    file /etc/xml/xml-core.xml
    file /etc/console-setup/cached_UTF-8_del.kmap.gz
    file /etc/ssh/moduli
    file /etc/emacs/site-start.d/50autoconf.el
    file /bin/setupcon
    file /bin/readlink
    

    The filetypes found above are not comprehensive, just a sampling. At one time, the recognized filetypes were kept in a text file.

    However, Debian currently stores them in /usr/share/file/magic.mgc which is a binary most likely in a database format.

    See man on topics :

  • file
  • magic

    Command list