Getting Around (ls, cd, mkdir, nano, rm, rmdir)

Getting Around (ls, cd, mkdir, nano, rm, rmdir)


To be an Ubuntu power user, you must learn the command line. This is the most powerful part of Ubuntu that you can do almost everything from the terminal without the GUI.

In this tutorial we are going to learn how to use the basic shell commands such as ls, cd, mkdir, nano, rm, rmdir.

This is a step-by-step tutorial on how to use ls, cd, mkdir, nano, rm, rmdir commands on Ubuntu. To follow this tutorial, you need to have the following requirements:

• A computer with Ubuntu operating system installed.
• Basic knowledge of Ubuntu terminal. With basic I mean, how to open a terminal on Ubuntu and how to execute commands.

First open the terminal of your Ubuntu operating system. You can open your terminal by pressing Control, Alt and T at the same time. You can also go to the Unity dashboard and search by the keyword “Terminal” and click on the terminal. Or you can right click on the Desktop and click on “Open Terminal”.

The ‘ls’ command:

‘ls’ command list directory contents. That is, to view what files and folders you have in a directory, you can use the ‘ls’ command.

Let’s see how it’s used.

On the terminal, type ‘ls’ and press Enter.

ls

If you’re on your HOME directory, you will see this.

If we want to see the files and folders in the /etc directory, we can use ls command.

“ls /etc”

There should be a lot of output. A trimmed version of the output is shown in the screenshot.

screenshot

The ‘cd’ command:

The cd command is used for changing directory on an Ubuntu or Linux operating system.

When you open Ubuntu terminal, you’re at the HOME directory. That is /home/your_user_name directory. To change to any other directory, you use the cd command.

For example, let’s say you want to go to the /etc directory. Type the following command,

“cd /etc”

cd-etc

Take a look at the prompt! It changed to the name of the directory. That’s how you know, you’ve changed your current directory with ‘cd’.

The ‘nano’ command:

‘nano’ is a simple text editor. It’s widely used by system administrator and Ubuntu users to edit configuration files of Ubuntu operating system.

Let’s see how that works.

We are going to read a configuration file called /etc/hostname with nano.

To do that, type in the following command,

“nano /etc/hostname”

‘nano’ text editor will open. You just use arrow keys to navigate and change the file.

nano

Once you’re happy with the changes, you just press Ctrl+X and press Y to save changes.

press-y

The ‘mkdir’ command:

‘mkdir’ command is used to create a directory on your Ubuntu operating system from the terminal.

Let’s say I want to create a directory called ‘newdir’ on the current directory of my file system.

To do that, I would run,
“mkdir newdir”

Now to see if the directory is created, run “ls” command.

Here is our newly created directory,

here-is-our-newly-created-directory

The ‘rmdir’ ‘rm’ commands:

The reason I’m covering them all together is because these commands are used to delete files and folder.

‘rmdir’ command is used to delete an empty directory. That is, a directory that don’t have any file inside it.

We just created a new directory recently. If we want to remove it with ‘rmdir’ command, we can run the following,
“rm newdir”

The directory will be removed.

The ‘rm’ command can be used to remove files. For example, let’s say we have a file on our Desktop called ‘removeme.txt’. To remove it, we would run,

“rm ~/Desktop/removeme.txt”

The file should be removed.