basic operations
File
Listing File
ls- listing files in current directoryls -lwill help you get more information of the filesTo list the invisible files, specify the -a option to ls −
Copying Files
To make a copy of a file use the cp command. The basic syntax of the command is −
1 | cp source_file destination_file |
Renaming Files
To change the name of a file, use the mv command. Following is the basic syntax −
1 | mv old_file new_file |
The mv command will move the existing file completely into the new file. In this case, you will find only newfile in your current directory.
Directory
mkdir [name] create a directory
rmdir [name] remove a directory, but it only to be useful with the empty directory.
rm -rf [name] can remove the files or directories permanently.
Changing Directories
You can use it to change to any directory by specifying a valid absolute or relative path. The syntax is as given below −
1 | cd dirname |
File Permission
Every file in Unix has the following attributes −
- Owner permissions − The owner’s permissions determine what actions the owner of the file can perform on the file.
- Group permissions − The group’s permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.
- Other (world) permissions − The permissions for others indicate what action all other users can perform on the file.
The permissions are broken into groups of threes, and each position in the group denotes a specific permission, in this order: read (r), write (w), execute (x) −
- The first three characters (2-4) represent the permissions for the file’s owner. For example, -rwxr-xr– represents that the owner has read (r), write (w) and execute (x) permission.
- The second group of three characters (5-7) consists of the permissions for the group to which the file belongs. For example, -rwxr-xr– represents that the group has read (r) and execute (x) permission, but no write permission.
- The last group of three characters (8-10) represents the permissions for everyone else. For example, -rwxr-xr– represents that there is read (r) only permission.
When we use ls -l command, the permission information will be shown.

The first character represent what type it is.
- represents a file
d represents a directory
Change Permission
We have two modes to change the permission of files.
Symbolic Mode
a ->all(user,group,other)u ->userg ->groupo ->other
| Chmod operator & Description | |
|---|---|
| + | Adds the designated permission(s) to a file or directory. |
| - | Removes the designated permission(s) from a file or directory. |
| = | Sets the designated permission(s). |
Example
1 | chmod o+wx testfile |
Absolute Permissions
The second way to modify permissions with the chmod command is to use a number to specify each set of permissions for the file.
Each permission is assigned a value, as the following table shows, and the total of each set of permissions provides a number for that set.
| Number | Octal Permission Representation | Ref |
|---|---|---|
| 0 | No permission | — |
| 1 | Execute permission | –x |
| 2 | Write permission | -w- |
| 3 | Execute and write permission: 1 (execute) + 2 (write) = 3 | -wx |
| 4 | Read permission | r– |
| 5 | Read and execute permission: 4 (read) + 1 (execute) = 5 | r-x |
| 6 | Read and write permission: 4 (read) + 2 (write) = 6 | rw- |
| 7 | All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 | rwx |
Here’s an example using the testfile. Running ls -1 on the testfile shows that the file’s permissions are as follows −
1 | $ls -l testfile |
Then each example chmod command from the preceding table is run on the testfile, followed by ls –l, so you can see the permission changes −
1 | $ chmod 755 testfile |
