Monday, November 20, 2017

Learning basic linux command on Lubuntu

Learning basic linux command on Lubuntu

Learning how to use command line is essential if you want to survive in the linux world, if you are a beginner you must learn these basic linux command, it will help you a lot when working with lubuntu.

Moving to another directory

To move from one place to another, you can use the cd command, cd stand for 'change directory'. Let's say currently you are on home directory, to move to Downloads folder which located inside your home directory, simply run this:
cd Downloads
Remember that linux is case sensitive, so you have to enter the folder name correctly, lower case should be lower case and upper case should be upper case.

Now, to move up to the previous path, you simply run cd followed by two dots (..), like this:
cd ..
The command above will take you outside of Downloads folder.

Showing current directory/path

If you forget where you are right now, you can run pwd command, this command will tell you where exactly your current position, what path/directory are you on.
pwd


Showing list of files and directory

You can show list of files and directory using the ls command, like this:
ls

Add -l parameter will give you more detail information
ls -l

Add -a parameter will also show hidden files and folder
ls -la

Creating new directory

To create new directory, you can use the mkdir command followed by the name of the directory you want to create.
mkdir [directory-name]
Example:
mkdir data
mkdir my-files
mkdir whatever

Creating new file

There are a few ways of creating new file on linux command line, depends on what type of file you want to create, but generally you can create file using touch command, but for text file or config file, it's better to use text editor.
Using touch to create a file
touch [filename]
Example:
touch index.php
touch myass
Using leafpad to create a text file
leafpad [filename]
Example:
leafpad readme.txt
leafpad config.cfg


Copying file

To copy a file from one place to another you can use cp command, like this:
cp [old path/ file name] [new path]
Example:
cp readme.txt Documents
cp /home/kernelpanic/test.txt /home/kernelpanic/data/

Moving and rename file

On linux world you can use the same command for moving and renaming file, which is using mv command, mv takes two parameter just like cp, if the path is the same for both parameter that means you are renaming, if not then you are moving file.
mv [parameter1] [parameter2]
Example renaming file:
mv test.txt ready.txt
mv /home/kernelpanic/word.cfg /home/kernelpanic/words.txt
Example moving file:
mv test.txt /home/kernelpanic/data/
mv words.txt /home/kernelpanic/Documents/

Deleting file and folder

You can use rm to delete file  and folder on linux command line, like this:
Delete file
rm [filename]
Example deleting file
rm test.txt
rm /home/kernelpanic/Downloads/words.cfg
Delete folder
rm -rf [foldername]
Example deleting folder
rm -rf data/
rm -rf /home/kernelpanic/mydata/


Running command with root permission

When running a command, sometimes you get an error, like permission denied or something, it means you need to run it under root permission, simply add sudo before the command and you will be asked to enter a password, the password is root password.

sudo [command name]
Example:
sudo rm /var/www/html/project/file.php
sudo touch /var/www/html/info.php

General rules in linux world

  • linux is case sensitive
  • on linux everything is a file
  • the root path on linux is / 
  • every user has home directory such as /home/kernelpanic/, the symbol ~ is shorthand for home directory, so /home/kernelpanic/Downloads is equall with ~/Downloads.
  • use the TAB button on your keyboard for auto complete a command or directory path, type a few letters and then hit TAB button to reveal the complete command/path.
  • you can run graphical application from command line, simply type the name and hit enter

This tutorial/guide is not covering all, but at least this can be use for starting point for learning basic linux command. The best way to learn is to jump-in and just go ahead run some of these command see what's happen. 

No comments:

Post a Comment