• +4917626969472
  • info@ur-techpartner.de

Learn Basic Commands for LINUX systems – 01/04

Basic Linux for ROS Drone

Basic Commands for LINUX Systems – 01

Since generally ROS is run on Linux-based systems, it is almost essential to know the basic commands of LINUX. Before starting ROS, we will go through these LINUX commands that you will need while learning ROS.

For executing those commands you will have to use command prompt or Terminal. In LINUX operating system (e.g. Ubuntu), you can open Terminal by right clicking anywhere on desktop.

Navigating through the file system using command “cd”

We already knew that in order to store data we use files, and in order to organize files we use directories or folders.

For moving into or out of any folder (or directory) we use “cd” command.

Using “cd” command on command terminal, we can get into step bey step or go directly to any specific directory.

Here we try some examples,

Open the terminal

if we want to go to the folder “my_example_package”, and we know its path, we can directly go to this folder by using following command line

cd catkin_ws/src/my_example_package/

By pressing enter, we will move into the folder “ my_example_package”

what if we don’t remember the complete path of the folder? No worries, we still can go to our specific folder. Here we can use another command “ls”. This command shows the contents (files and sub-folders) of the current directory. Open a new terminal and run the command “ls”

Here we can see “catkin_ws” is the folder where we want to go.

Wrtie

cd catkin_ws

similarly you can move to next folder by writing

cd src

Another way to see the content of the current folder is, just write

cd

on terminal and press tab twice, the contents of the folders will be displayed, as can be seen in figure above.

To go one step back (to get out of folder) , cd with double .. can be used as followed

cd ..

using “cd ..” we can move back one by one.

But if we want to get out of all folders directly, the command “cd /” is used.

There is also a command to see the current path of the directory, For this, command “pwd” is used.

For example, write

pwd

it will show the path of current directly as

/home/kashif/catkin_ws

we can see the “/home/kashif” is also appeared while checking the path of current directory. Here “/home/kashif” is known as the HOME folder of the user, and kashif is user name.

We can see there is a character ~ before $ sign. This character ~ represent the home folder.

We can alternatively use ~ character instead of “home/user” as we have seen above.

Following two lines will perform same task

cd home/kashif/catkin_ws/src

or

cd ~/catkin_ws/src

 

you can further practice these commands by your own.

Use of “ls” command

We have already seen use of “ls” command which shows the contents of directory.

We can further explore this command. For example simple “ls” command does not show hidden files and folders. To view hidden files and folder, we can use “ls” command with argument as follows

ls -la

it also shows the read/write/execute permission as shown in the first column in the form of drwxr-xr-x (we will discuss it later). The files with the name starting with . are hidden files.

For further arguments just try

ls -- help

Create New Directory using “mkdir” command

“mkdir” is an important command in Linus systems that allows to create a new directory.
Write following commands in terminal

mkdir my_new_folder

ls
cd my_new_folder

you can see a new folder names “my_new_folder” is created.

 

Command “touch”

we may use various code editors to create new files and to write code. However, if we want to create a file through terminal, we have a useful command “touch”.

Go to my_new_folder and run the “touch” command.

cd my_new_folder
touch my_file.txt

This command will create an empty file.

Use of “vi” command

In order to write the data in created file, “vi” command is the default tool for Linux systems.

Write in Terminal

vi my_file.txt

we will see something like this in terminal window

“vi” command has two modes, Command mode and Insert mode.
The file is opened in Command mode.

If we want to write in the file, we should press letter “i” to turn the file into Insert mode.

When you are done with writing, press “Esc” to go back to Command mode.

After that write

:wq

to save the file and exit. (Here w means write and q means quit)

if you want to close file without any change then write

:q

which simply means quit.

However, if you have made changes in the file and now you want to discard changes and quit then add “!” after q, as follows

:q!

you will exit from editor and last changes will be discarded.

We will see more commands in next post. Meanwhile, You should practice these commands by yourself in order to fully grasp the concept.

 

 

No comments