Basic Linux Commands (revision 140701-r02KI)


List of commands in this tutorial:
  • General Pattern: command space option space target
  • cd [directory_name]: enter directory [directory_name].
    • cd ..: exit one level from current active directory.
  • chmod [option] [target_name]: change file or directory access permit (read, write, execute).
    • *chmod -700 [file_name]: change the file access permit (7 for ourself which means we can read, write and execute, first 0 for group and second 0 for public which means no access at all).
  • ls: list current directory content.
    • ls -al: list current directory content with detailed status.
  • command > [target_file]: do the command, and insert the result to [target_file].
  • mkdir [directory_name]: creates a new directory named [directory_name].
  • more [text_file]: see the content of [text_file].
  • rm [file_name]: delete file [file_name].
  • rmdir [directory_name]: delete directory [directory_name]. This command can't be done if directory has content.
    • rm -rf [directory_name]: delete directory [directory] and all the content.

Basic Linux Tutorial

Do the tutorial in Terminal in Ubuntu. Assumption: in the end of each command, you press Enter key on your keyboard.

  • List your home directory content:
    $ cd
    $ pwd
    $ ls
    $ ls -al

    pwd command is used to see which directory you are now, while ls is used to see the content of your current directory.
  • Create a new folder named your KELAS in your home directory. For example my KELAS is TESTING, replace it with your CLASS. Type:
    $ mkdir TESTING
  • Create three sub-directories in the KELAS directory. One of the directories is your NPM. Type:
    $ mkdir TESTING/1202000818/ TESTING/test1/ TESTING/test2/

    (change 1202000818 with your NPM!).
  • Enter directory KELAS and list the content! Type:
    $ cd kuliahos/
    $ ls -al
  • Delete folder test1 and test2. Type:
    $ rmdir test1/ test2/
  • Please check the rest of the folder content. Type:
    $ ls -al 

  • Go into your NPM directory. For example:
    $ cd 1202000818/
  • Create a new directory named Lab00. Type:
    $ mkdir Lab00
  • Go into directory Lab00.
    $ cd Lab00
  • New let's try to insert ls-al command into a file named dirlist.txt.
    $ ls -al > dirlist.txt
  • See the content of dirlist.txt
    $ cat dirlist.txt
  • Let's learn about access right / permission. In Linux, access right is separated to three big groups, the first group manages access right for the file owner, the second group for users in the same group with the owner, while the third group for global user with no connection to the file owner. Each of these groups has three access rights, which is read, write and execute rights. Let's get back and see the access right for dirlist.txt file:
    $ ls -al

    We can see the access right for dirlist.txt is - rw- r-- r--. The first dash means that it is a file not a directory. If it is a directory the dash will be replaced with d letter. Three next characters (rw-) is the first group of the access right. We have r which means the file is *r*ead-able, w for *w*rite-able while the dash as the third characters means it is not e*x*ecutable. If the file is executable the dash will be replaced with x. The second three characters group is r-- which manages the right for users in the same group with the file owner, and the third group is also r--.
  • In order to be able to modify the access right, we have to remember the connection between decimal and binary numbers. This access right is written based on the binary position, but we type the input based on decimal number. For example, the right rw- (can read, can write, can't execute) when translated to binary numbers in which can means 1 and can't means 0 will translate to number 110. We then can translate this binary number to decimal, which is (1x4)+(1x2)+(0x1)=6. The second example is for the second group r--, if we translate this to binary the number is 100. When we translate it to decimal the number is 4. So to only give read access, we type 4. Now let's try to change the access right of this file.
    $ chmod 222 dirlist.txt
    $ ls -al

    The command chmod means we change the access right to 2,2,2 the first 2 for the file owner (ourselves), the second for the second grup and the third for the third group. This means we input 010 in binary for each groups. This also means all the access right has changed to only writable (- w w w). Now let's prove the access right has changed by trying to read the content of dirlist.txt
    $ cat dirlist.txt

    You will see that instead of seeing the content of the file, the system said that we are not permitted to access the file.
    cat: dirlist.txt: Permission denied
  • Now let's change the access right again to be able to read the content
    $ chmod 755 dirlist.txt
    $ cat dirlist.txt

    Now we can see the content again.
  • Now we will se the IP that is given by Virtual Box and put it in dirlist.txt.
    $ ifconfig
    $ ifconfig eth0 >> dirlist.txt
    $ cat dirlist.txt

This is the end of Basic Linux Commands Tutorial.

  1. Q: Haelp me Superman! I was strolling around directories in Tiny Core and now I'm confused on where my home directory is!
    A: Your home directory is /home/tc/, access it with:
    $ cd /home/tc/

    Or just close the current terminal session and start a new one.

Back to WIKI