Oracle 8i | Oracle 9i | Oracle 10g | Oracle 11g | Oracle 12c | Miscellaneous | PL/SQL | SQL | Oracle RAC | Oracle Apps | Linux

Linux Files, Directories and Permissions

This article gives an overview of files, directories and permissions on Linux, with specific reference to the information needed for the RHCSA EX200 and RHCE EX300 certification exams.

Remember, the exams are hands-on, so it doesn't matter which method you use to achieve the result, so long as the end product is correct.


The touch command is used to create a new empty file with the default permissions.

# touch /tmp/my.log
-rw-r--r--. 1 root root 0 Mar  5 16:08 /tmp/my.log

Files can also be created by output redirection using the ">" or ">>" operators.

# echo "This is going into a file." > /tmp/my2.log
# cat /tmp/my2.log
This is going into a file.
# echo "Here is another line in the file." >> /tmp/my2.log
# cat /tmp/my2.log
This is going into a file.
Here is another line in the file.

The vi editor can be used to create or edit files. An explanation of vi is beyond the scope of this article, but you can find lots of information on the internet about it, such as this.

The ls command lists all files and directories in the specified directory. If no location is defined it acts on the current directory. The "-a" flag lists hidden "." files. The "-l" flag lists file details.

# ls
# ls /u01
# ls -al

The rm command is used to delete files and directories. The "-R" flag makes it deleted recursively and the "-f" flag stops it from prompting for confirmation.

# rm my.log
# rm -Rf /archive

The mv command is used to move or rename files and directories. The "." represents the current directory.

# mv [from] [to]
# mv my.log my1.log
# mv * /archive
# mv /archive/* .

The cp command is used to copy files and directories. The "-R" flag makes it recursive.

# cp [from] [to]
# cp my.log my1.log
# cp * /archive
# cp -R /archive/* .

The find command can be used to find the location of specific files.

# find / -name dbmspool.sql
# find / -print | grep -i dbmspool.sql

The "/" flag represents the staring directory for the search. Wildcards such as "dbms*" can be used for the file name.


The pwd command displays the current directory.

# pwd

The cd command is used to change directories.

# cd /u01/app/oracle

The mkdir command is used to create new directories. The "-p" flag causes it to create any missing directories in the path.

# mkdir /archive
# mkdir -p /new/path/to/mydir

The rmdir command is used to delete directories.

# rmdir archive

Remember, the mv and cp command apply to Navigate between directories using the cd command described earlier.directories as well as files.

The which command can be used to find the location of an executable you are using.

# which mkdir

The "which" command searches your PATH setting for occurrences of the specified executable.

The "~" symbol represents the users home directory.

# cd ~


The umask command can be used to read or set default file permissions for the current user.

# umask 022
# umask

The umask value is subtracted from the default permissions (666) to give the final permission.

666 : Default permission
022 : - umask value
644 : final permission

The chmod command is used to alter file and directory permissions. The "-R" makes it recursive.

# chmod 777 *.log
# chmod -R 600 /my/dir

The output below explains what permissions the the numbers represent.

Owner      Group      World      Permission
=========  =========  =========  ======================
7 (u+rwx)  7 (g+rwx)  7 (o+rwx)  read + write + execute
6 (u+wx)   6 (g+wx)   6 (o+wx)   write + execute
5 (u+Rx)   5 (g+Rx)   5 (o+Rx)   read + execute
4 (u+r)    4 (g+r)    4 (o+r)    read only
2 (u+w)    2 (g+w)    2 (o+w)    write only
1 (u+x)    1 (g+x)    1 (o+x)    execute only

Character equivalents can be used in the chmod command.

# chmod o+rwx *.log
# chmod g+r   *.log
# chmod -Rx   *.log

The chown command is used to reset the ownership of files and directories after creation. The "-R" flag makes it recursive.

# chown oracle.oinstall /u01/myfile.txt
# chown -R oracle.oinstall /u01

The chgrp command is used to change just the group associated with a file or directory.

# chgrp oinstall /u01/myfile.txt
# chown -R oinstall /u01

If multiple users are part of the same group, for example "dev", setting the group of a directory to that group and setting the "g+s" flag will allow them all to share the directory. Normal permissions still apply, so the user must grant read/write permissions to the group for any files or directories they create. This is most easily done by setting umask 002 in the "~/.bashrc" or the "~/.bash_profile" file for each user in the group.

# chgrp dev /u01/dev_share
# chmod g+s /u01/dev_share

When attempting to perform certain file operations you may be presented with permissions problems.

# echo "Keep this a secret" >> /secret.txt
# chmod o-r /secret.txt
# su - tim_hall
$ cat /secret.txt
cat: /secret.txt: Permission denied
$ cp /secret.txt .
cp: cannot open `/secret.txt' for reading: Permission denied

When you see these types of errors at the command line or in log files, you need to change the permissions on the file. Always try to grant the least permissions needed to allow an action to be performed.

# chmod o+r /secret.txt
# su - tim_hall
$ cat /secret.txt
Keep this a secret
$ cp /secret.txt .

The basic permissions system can be extended using ACLs, which provide a greater level of flexibility and control. You may also need to consider ACLs, when diagnosing permissions problems.


The ln command is used to create hard or soft (symbolic) links to files or directories. Directories contain links to all their child directories and files. A hard link allows you to manually create a new reference to a child file, allowing the same file to be present in multiple directories or with multiple names. There is only a single file, but it is seemingly present in multiple locations.

# echo "Test file" > /tmp/test.txt
# ln /tmp/test.txt ~/test.txt
# ls -al /tmp/test.txt
-rw-r--r--. 2 root root 10 Mar  5 17:07 /tmp/test.txt
# ls -al /root/test.txt
-rw-r--r--. 2 root root 10 Mar  5 17:07 /root/test.txt

A soft (symbolic) link is merely a pointer to a file in another location. Deleting the link does not affect the original file. Deleting the original file leave the soft link pointing at nothing.

# echo "Test file" > /tmp/test.txt
# ln -s /tmp/test.txt ~/test.txt
# ls -al /tmp/test.txt
-rw-r--r--. 1 root root 10 Mar  5 17:09 /tmp/test.txt
# ls -al /root/test.txt
lrwxrwxrwx. 1 root root 13 Mar  5 17:09 /root/test.txt -> /tmp/test.txt

For more information see:

Hope this helps. Regards Tim...

Back to the Top.