A beginner's guide to shell navigation, manipulation and permissions.

A beginner's guide to shell navigation, manipulation and permissions.

Introduction:

A shell is a program that helps you communicate with your computer using commands. So when you type in a command, the shell interprets it and tells the computer what to do. This is useful because it allows you to perform tasks quickly and efficiently.

The shell is an important part of the Unix operating system because it helps you communicate with the kernel. The kernel is responsible for managing your computer's hardware resources and executing the commands you give it through the shell. The shell helps you talk to the kernel, so you can get things done.

Software engineers and system administrators need to understand shell navigation, manipulation and permissions simply because it enables them to navigate through the Linux filesystem and make changes to files and directories or remove and create files and directories. As a developer or system administrator, you also need to understand shell permissions so you can control who has access to files and directories. This is important for maintaining your computer's security.

Shell Navigation:

Shell navigation is when a user moves around the Linux file system and accesses different files and directories through the shell using the shell navigation commands. There are several shell navigation commands and they are:

  • ls = for listing files in a directory.

  • cd = for changing directories.

  • pwd = to print the current working directory.

Here are examples of use cases where shell navigation commands are used.

cd directory-name
ls directory-name
pwd

Shell Manipulation:

Shell manipulation stands for managing and modifying files and directories in the Linux filesystem.

There are several shell manipulation commands used in Linux:

  • cp = to copy files or directories from one location to another.

  • mv = this command is used to move files or directories from one location to another.

  • mkdir = to create a new directory.

  • rmdir = to remove or delete a directory.

  • touch = to create an empty file.

  • rm = to delete or remove a file.

  • cat = to view file content in the terminal.

Here are examples of use cases where shell manipulation commands are used:

cp filename directory-name/
mv filename directory-name/

You can move and copy multiple file names at a time by writing the command this way:

cp filename filename filename directory-name/ 
mv filename filename filename directory-name/

Note: The directory name is the location or directory you want to copy the file and also directories can be copied and moved too using the cp and mv command

cp directory directory-name/
mv directory directory-name/

Other commands used cases are:

mkdir directory-name
rmdir directory-name
touch file-name
rm file-name
cat file-name

Note: You can create and remove or delete multiple files and directories at the same time by adding the names to the command keyword.

Shell Permissions:

Shell permissions give a user control over who is allowed to gain access to either a file or directory to ensure security.

In the shell three different types of permissions can be given to either "Owner", "Group" or "Other users" in Linux and the three types of permissions are Read, Write and Execute. In the shell, you can control who can gain access to a file and directory and what they can do with the file and directory by using "chmod" known as the change mode command. With "chmod" you can change the permission of a file to either read, write or execute.

There are ways you can represent a user (also known as owner), group, other users and all in the shell when using the chmod to modify the permissions.

user -> u: This is known as the owner of the file or directory.

group -> g: This is known as the group owners of the file or directory.

others -> o: This is known as other users that are not the owner or group owners of the file or directory.

all -> a: This stands for all three categories.

So when using the chmod command, you can give specific permissions to different categories of users. am going to illustrate an example below:

For this example, I will be using the user(owner) category

chmod u+w file or directory name

u stands for the user which is the owner

w stands for write permission.

This is called shell permission notation also known as symbolic notation, which is a way of representing the specific permissions with alphabetical characters as they are listed below:

read -> r: to give read permission to the users.

write ->w: to give write permissions to the users.

execute->x: to give executable permissions to the user.

Here is an illustration that shows how to give multiple permissions to a user:

chmod u+rwx <file or directory name> -> this gives the user read, write and execute permissions.

chmod g+rw <file or directory name> -> this gives the user read and write permissions.

chmod o+wx <file or directory name> -> this gives the user write and execute permission.

chmod a+rwx <file or directory name> -> this gives all the user categories read write and execute permission.

Note: The absence of a particular shell permission notation means the permission is not given.

In shell permissions, numerical representation can be used which is called Octal Notation and the illustration below shows how each permission are represented numerically:

read (r) -> 4

write (w) -> 2

execute (x) -> 1

none -> 0

Note: 0 (zero) means No permissions.

Here is an illustration using Octal notation:

chmod 777 <file or directory name> -> this means give rwx permissions to all users.

chmod 670 <file or directory name> -> this means give rw permission to user(owner), rwx permission to group and no permission to other user.

chmod 000 <file or directory name> -> this means give no permission to user, group and other user.

Conclusion:

You should be able to understand how to navigate a shell using the ls, cd and pwd commands and manipulate files and directories by creating, modifying and removing them by using the cp, mv and mkdir etc. Also with an understanding of the shell permissions, you will be able to control who should gain access to files and directories.

Additional resources:

If you make it to the end of this article know that am proud of you and I have prepared a good reward for you. Here is a link to a cheat sheet containing more shell commands that are useful both for beginner to advance levels.

Click Here

Thank you for reading this beginner's guide to shell navigation, manipulation and permission.