Linux Notes

Table of Contents

Section 5: Files and Directories

The filename has probably no limits, but it is specific to each system. Of course again, case sensitive.

There is no need to use the file extension - as it is only for information purposes.

The symbols prohibited to use as a filename component - the wildcards - are: *?[]`$\'" - and they will be explained in one the next Linux courses.

If the filename begins with a period it means that the file is hidden. So, when the user issues the ls command (ls lists the current directory contents), those files won't be shown.

The filesystem is hierarchical. The basic directory is the root directory, marked by a slash (/). The root splits into other directories, which contain files and other directories:

/
    bin
    etc
    usr
        ronin
    boot
        tc5660
        tc6729
            some.files

So the path to those files would be:

/usr/tc6729/some.files

Note that MS-DOS used the backslash (). Here, you have to use the slash.

Each directory contains at least two files. Those are "." and "..". The double dot (..) stores information about the parent directory for the current one and the single dot (.) stores info about the current directory.

Some commands:

pwd

  • shows user the full actual directory pathname
$ pwd

cd

  • changes directory (just like in MS-DOS)
$ cd <directory>

ls

  • lists the contents of a current directory
$ ls [options] <files>

Options:

  • -a shows all the files
  • - shows a slash (/) after a directory, a star () after an executable file and an at (@) after a symbolic link
    -x uses more than one column
  • -d if the argument is a directory, only names are shown
  • -i the file node is shown
  • -l full info displayed

Example:

$ ls -l
-rwxrwxrwx 1 astatine cs 350 May 15 03:14 iwats.project.23

(file type and access rights, number of links, file owner, workgroup, last modification, filename)

ln

  • creates a link to a file
$ ln [options] <name> <new_name>

Options:

  • -f doesn't query user
  • -n if the new name already exists, doesn't link
  • -s creates a symbolic link

mv

  • moves and renames files
$ mv [options] <file1> <file2> (renames file1 to file2)
$ mv <file> <directory> (moves the file to the directory)

Options:

  • -f doesn't query user if the second file already existed

mvdir

  • moves directories and their contents
$ mvdir <source> <target>

mkdir

  • creates a directory
$ mkdir [options] <directory>

rm

  • removes files
$ rm [-i][-f][-r] <file>
$ rm [-i][-f][-r] <directory> [files]

Options:

  • -i queries user before each delete
  • -f no query
  • -r first deletes all directory contents and then removes the directory

rmdir

  • removes the directory
$ rmdir [options] <directory>

Options:

  • -p removes nested directories if they're empty
  • -s disables queries on standard output