[Robelle] [SmugBook] [Index] [Prev] [Next]

Listing Filenames and Attributes in UNIX

The ls command is the UNIX way to list file directories. MPE uses the :Listf and :Listfile commands.

% ls [-adlFR] [ pathnames ]

There are many more options. Try also the l, ll, lsf, lsr, and lsx commands.

Text version.

% ls -F{adds "/" for directory, "*" for exec, "@" for link}
% ls -ld a* b*{long format, directory status, starting with "a" or "b"}
% ls -lR test/{long list, recursively show sub-directories of "text"}
% ls -a{shows "hidden" dot files as well}

Hidden Files

Filenames in UNIX can contain almost any character and start with almost any character. However, filenames starting with a "." (dot, period) are often called hidden files because they don't show up in a regular ls command and you don't get rid of them with a rm * command. It is common for UNIX tools to create "dot" files for temporary files and to maintain control and history information. Users are also expected to create them as configuration files.

Text version.

.profile is your Bourne and Korn shell configuration file (the Korn shell also executes
the shell script in the ENV variable before reading .profile).
.login is your C shell startup file.
.logout is your C shell termination file.
.cshrc is your C shell configuration file.
.history is your shell command history file.
.mailrc is your mail configuration file.
.forward forwards your mail to another e-mail address. When you leave home, do
echo bsmith@hotel.com >.forward. When you return, do rm .forward.

Use ls -a to see hidden files and rm .??* to delete them. The rm -r command is a sure-fire way to get rid of invisible files and files with non-printing characters in the name and all subdirectories.

On UNIX, "fopen" is MUCH Simpler

There are only two parameters to fopen on UNIX: the filename and the access type ("r", "w", "a", "rb", "wb", "ab"..)
    if ((destfp = fopen(dest_file,"r")) == NULL)
       fprintf(stderr, "error opening %s file\n", dest_file);

The access types are:

Text version.

"r"=open for reading
"w"=erase or create new empty
"a"=append or create for writing
"rb"=open binary file for reading
"wb"=erase binary file or create empty
"ab"=open binary file for appending
"r+"=open for reading and writing
"w+"=erase, open for reading/writing
"a+"=retain contents, read/write
"r+b" or "rb+"=open binary file for read/write
"w+b" or "wb+"=erase binary file, read/write
"a+b" or "ab+"=retain contents of binary file, read/write

Closing a File on UNIX

The fclose() routine takes only one parameter:
    int fclose(FILE *stream)
fclose() writes any buffered data for the named stream and then closes it. This is automatic for all open files when you call exit(2).


[Robelle] [SmugBook] [Index] [UNIX] [Prev] [Next]