Basic Commands for LINUX Systems – 02
Another frequently used command to open and write data into files is “gedit”. This command opens the file in a notepad like editor. As given below
The file can be edited by inserting/deleting/modifying data as required.
Another useful command is “mv” which is used to move files and folders from one location to other.
This command has two arguments as follows
mv <name of file/folder we need to move> <destination path>
if we are at different location (other then where file/folder is located), then we give complete path along with the name of file/folder in first argument.
Let’s try to move folder
we first check which files/folders are available at our current locations
here (as shown in next image), we can see my_new_folder
lets go inside it and see which files it contains
cd my_new_folder ls
it contains two files (my_file_p.py and my_file.txt)
now get out of it and move the folder using “mv” commands
mv my_new_folder catkin_ws
again check if folder is moved using “ls” commands
folder is no more available at current location. Now go inside catkin_ws directory.
cd catking_ws ls
Here “my_new_folder” is present
go inside the folder and see its contents
cd my_new_folder ls
wow! the folder is moved along with its contents to new location. Similarly single file can also be moved.
As you can guess, “cp” command is used to copy file or folder from one location to the other. Same as in case of “mv” command, “cp” command takes two arguments. we can try it here
cp my_new_folder/my_file.txt src cd src ls
we can see that the file “my_file.txt” is copied from “my_new_folder” to “src” folder
Similarly folder can be copied from one location to the other, however for this regular cp command doesn’t work, we have to give an argument “-r” along with “cp” command to copy the folder (and its contents) from one place to the other as follows
if we used only “cp” command, it gave following error
cp src/my_example_package my_new_folder
cp: omitting directory ‘src/my_example_package’
however with argument “-r” the folder is copied to given destination.
cp -r src/my_example_package my_new_folder
The “rm” command is used to remove the file and folder. In order to remove the file (or folder) we should be in the correct location.
First go to correct location
check what files are in this folder
See again if the file is removed (or not)
Cool! File is removed.
Similarly, as in the case of “cp” command, we should add argument “-r” with “rm” command to remove the folder (including sub-folders or files in it)
rm -r my_new_folder