Linux Examples

From MediaWiki

(Difference between revisions)
Jump to: navigation, search
Line 197: Line 197:
Where 100 is number of process.
Where 100 is number of process.
 +
 +
 +
==man command==
 +
 +
If you need more documentation for some command (for example ls) type :
 +
 +
  [ngrkic@ui ~]$ man ls
 +
 +
Where you enter in man reading mode
 +
 +
LS(1)                            User Commands                          LS(1)
 +
 +
NAME
 +
      ls - list directory contents
 +
 +
SYNOPSIS
 +
      ls [OPTION]... [FILE]...
 +
 +
DESCRIPTION
 +
      List  information  about  the  FILEs  (the  current  directory  by
 +
      default).  Sort entries alphabetically if none  of  -cftuvSUX  nor
 +
      --sort.
 +
 +
      Mandatory  arguments  to  long  options  are  mandatory  for short
 +
      options too.
 +
 +
      -a, --all
 +
              do not ignore entries starting with .
 +
 +
      -A, --almost-all
 +
              do not list implied . and ..
 +
 +
      --author
 +
              with -l, print the author of each file
 +
 +
      -b, --escape
 +
              print octal escapes for nongraphic characters
 +
 +
      --block-size=SIZE
 +
              use SIZE-byte blocks
 +
 +
        -B, --ignore-backups
 +
              do not list implied entries ending with ~

Revision as of 22:19, 23 March 2011

This page is dedicted to people who wants to get familiar with basic usage of Linux shell. In this exercise will be demonstrated basic of navigating the file system, standard Linux commands, archive tools, data management, basics of bash script language. For more tutorials and exercise use google.

Let`s get started:

Contents

ls command

List folder:

[ngrkic@ui ~]$ ls /tmp

You will get output simular like this:

007-01-22 people                 misanu
c                                 mpi-start
ce_hist                           node11_hist
course                            phpBB-3.0.8.tar.bz2
Epico.iso                         PPROBAMATLAB
fcub                              PROBAMATLAB
gctest                            realtimeoutput
gctest_main.c                     run_gctest.sh
gctest_mcc_component_data.c       run_gctestsing.sh
gctest.prj                        run_magicsquare.sh
gctestsing                        script.sh
gctestsing_main.c                 simulacija

For more details type :

[ngrkic@ui ~]$ ls -las

You will get output simular like this:


total 1011632
     4 drwx------ 38 ngrkic ngrkic       4096 Mar 22 21:18 .
     4 drwxr-xr-x 94 root   root         4096 Mar 21 10:38 ..
    16 -rw-------  1 ngrkic ngrkic      12482 Mar 23 12:01 .bash_history
     4 -rw-r--r--  1 ngrkic ngrkic         24 Jul 31  2009 .bash_logout
     4 -rw-r--r--  1 ngrkic ngrkic        191 Jul 31  2009 .bash_profile
     4 -rw-r--r--  1 ngrkic ngrkic        124 Jul 31  2009 .bashrc
     0 -rw-rw-r--  1 ngrkic ngrkic          0 Mar 22 21:18 c
     8 -rw-r--r--  1 ngrkic ngrkic       5619 Jul 31  2009 .canna
    20 -rw-r--r--  1 ngrkic ngrkic      20224 May  5  2010 ce_hist
     4 drwx------  3 ngrkic ngrkic       4096 Dec 10 15:47 .config
     4 drwxr-xr-x  8 ngrkic ngrkic       4096 Sep  7  2010 course
     4 drwxrwxr-x  4 ngrkic ngrkic       4096 Dec 10 15:43 .eclipse
     4 -rw-r--r--  1 ngrkic ngrkic        383 Jul 31  2009 .emacs
1008604 -rw-r--r--  1 ngrkic ngrkic 1031798784 Nov 25 16:42 Epico.iso
     4 drwxr-xr-x  5 ngrkic ngrkic       4096 Nov 29  2009 fcub
     4 drwxrwxr-x  3 ngrkic ngrkic       4096 Nov 29 10:06 .felix
   156 -rwxrwxr-x  1 ngrkic ngrkic     155129 Sep 20  2010 gctest
     4 -rw-rw-r--  1 ngrkic ngrkic       3513 Sep 20  2010 gctest_main.c
     8 -rw-rw-r--  1 ngrkic ngrkic       6115 Sep 20  2010 gctest_mcc_component_data.c
    28 -rw-rw-r--  1 ngrkic ngrkic      27854 Sep 20  2010 gctest.prj

pwd command

Print name of current/working directory:

[ngrkic@ui ~]$ pwd

You will get something like this:

/home/ngrkic

cd command

To change directory to /tmp type :

[ngrkic@ui ~]$ cd /tmp

Then type just cd :

[ngrkic@ui tmp]$ 

Now you are in your home folder (type pwd if you are not sure). If you want to go one folder back type :

[ngrkic@ui ~]$ cd ..

Now you are in system home folder.

When you want to go to root of filesystem, type :

[ngrkic@ui home]$ cd /

Now you are in / folder. If you want you can type ls to see content.

Now return to your home folder by typing :

[ngrkic@ui ~]$ cd

mkdir command

When you want to make new folder type next:

[ngrkic@ui ~]$ mkdir testdirNikola

touch command

If you want to make empty file, you can do it with touch command like this:

 [ngrkic@ui ~]$ touch testfile

cp command

For copying files type:

[ngrkic@ui ~]$ cp testfile testdirNikola/

For copying folder to /tmp folder type :

[ngrkic@ui ~]$ cp -rf testdirNikola /tmp/

mv command

To move file type :

[ngrkic@ui ~]$ mv testfile testdirNikola/

To move folder :

[ngrkic@ui ~]$ cp -mv testdirNikola /tmp/

rm command

To delete file from folder type:

[ngrkic@ui ~]$ rm  /tmp/testdirNikola/testfile

To delete a folder :

[ngrkic@ui ~]$ rm -rf /tmp/testdirNikola

chmod command

First lets touch testfile:

[ngrkic@ui ~]$ touch testfile

Then list the file like this:

[ngrkic@ui ~]$ ls -ls testfile

You will get this output:

0 -rw-rw-r-- 1 ngrkic ngrkic 0 Mar 23 22:55 testfile

When you want to add or remove perrmision type command in this syntax :

 [ngrkic@ui ~]$ chmod u+x testfile

Now list again and you will get next output:

 0 -rwxrw-r-- 1 ngrkic ngrkic 0 Mar 23 22:56 testfile

top command

When you need information about current status of computer type :

  [ngrkic@ui ~]$ top

ps command

When you need a snapshot of current state of process type :

  [ngrkic@ui ~]$ ps aux

You will get simular output to this one:

kic   19409  0.0  0.0  90136  1852 ?        S    22:39   0:00 sshd: ngrkic@pts/9
ngrkic   19410  0.0  0.0  66220  1684 pts/9    Ss   22:39   0:00 -bash
ngrkic   19600  0.0  0.0  65632   984 pts/9    R+   23:03   0:00 ps aux
root     24045  0.0  0.1  90160  3316 ?        Ss   Mar17   0:00 sshd: zlatko [priv]
zlatko   24047  0.0  0.1  90492  2144 ?        S    Mar17   0:00 sshd: zlatko@notty
zlatko   24048  0.0  0.1  54028  2180 ?        Ss   Mar17   0:00 /usr/libexec/openssh/sftp-server
root     24104  0.0  0.1  90160  3344 ?        Ss   Mar17   0:00 sshd: zlatko [priv]
zlatko   24106  0.0  0.0  90160  1908 ?        S    Mar17   0:00 sshd: zlatko@pts/1
zlatko   24107  0.0  0.0  66228  1652 pts/1    Ss   Mar17   0:00 -bash
zlatko   24166  0.0  0.1  58388  3212 pts/1    S+   Mar17   0:00 ssh n89
root     28045  0.0  0.0  62628  1216 ?        Ss   Mar19   0:00 /usr/sbin/sshd
nobody   30385  0.0  0.1 103000  2316 ?        Ss   Feb10   0:04 /usr/sbin/gmond
root     31963  0.0  0.1  90132  3284 ?        Ss   Mar22   0:00 sshd: igor [priv]
igor     31965  0.0  0.0  90328  2064 ?        S    Mar22   0:00 sshd: igor@pts/3 
igor     31966  0.0  0.0  66232  1656 pts/3    Ss   Mar22   0:00 -bash
igor     32026  0.0  0.1  58524  3348 pts/3    S+   Mar22   0:00 ssh -X n89
root     32247  0.0  0.1  90160  3336 ?        Ss   Mar15   0:00 sshd: jaksa [priv]
jaksa    32249  0.0  0.0  90160  1964 ?        S    Mar15   0:00 sshd: jaksa@pts/8
jaksa    32250  0.0  0.0  66228  1688 pts/8    Ss+  Mar15   0:00 -bash
root     32507  0.0  0.1  90132  3280 ?        Ss   Mar22   0:00 sshd: zeki [priv]
zeki     32509  0.0  0.0  90132  1840 ?        S    Mar22   0:00 sshd: zeki@pts/4 
zeki     32510  0.0  0.0  66228  1748 pts/4    Ss+  Mar22   0:00 -bash


kill command

When you need to end your process type :

[ngrkic@ui ~]$ kill 100

Where 100 is number of process.


man command

If you need more documentation for some command (for example ls) type :

 [ngrkic@ui ~]$ man ls

Where you enter in man reading mode

LS(1) User Commands LS(1)

NAME

      ls - list directory contents

SYNOPSIS

      ls [OPTION]... [FILE]...

DESCRIPTION

      List  information  about  the  FILEs  (the  current  directory  by
      default).  Sort entries alphabetically if none  of  -cftuvSUX  nor
      --sort.
      Mandatory  arguments  to  long  options  are  mandatory  for short
      options too.
      -a, --all
             do not ignore entries starting with .
      -A, --almost-all
             do not list implied . and ..
      --author
             with -l, print the author of each file
      -b, --escape
             print octal escapes for nongraphic characters
      --block-size=SIZE
             use SIZE-byte blocks
       -B, --ignore-backups
              do not list implied entries ending with ~
Personal tools