Tux the peliguin

Bash Top 10


Home Page
What is Linux?
Meetings & Events
Documentation
Mailing List
Links
Contact Us

Commonly Used Console Commands

1.) ls - list directory contents

     Command: ls <options> <flags> <path>

     Summary of common 'ls' commands:

     a.) ls      - lists current directory contense
     b.) ls -l   - lists current directory in 'long format' (l)
     c.) ls -lh - lists current directory in 'long format' (l) and 'human readable' (h) form
     d.) ls -a  - lists all files (a) in current directory, including 'dot files' (e.g .. , .)

     Examples:

i.) A simple listing: ls <path>

    doneir@wolf:~$ ls /home/snul
    100NIKON.zip   DSC00088.JPG   DSC00090.JPG   NFS-UD.zip   q3.tgz   quake2.tgz
    doneir@wolf:~$

    'ls' without a following path (as above) will list the directory contense of the "current working directory" (cwd)
   
     doneir@wolf:~$ ls
     GNUstep   armyops200a-linux.bin     box-stats   cyp1.0k.tar  p2.jpg.1   script
     url   IrcLog    bmwm3vspolice3.wmv   cyp   old-bnc     ppp    test
     doneir@wolf:~$

ii.) 'ls -lh' will give a long (l) format in human readable (h) form.

      In order of columns:

    permissions owner   group     size       date       time        name-of-file
    doneir@wolf:~$ ls -lh /home/snul
    total 1.6G
    -rw-r--r--  1   snul      snul     2.3M    May 19    13:56    100NIKON.zip
    -rw-r--r--  1   snul      snul     113K    May 23    14:10    DSC00088.JPG
    -rw-r--r--  1   snul      snul     125K    May 23    14:10    DSC00090.JPG
    -rw-r--r--  1   snul      snul     815M   May 27    08:43    NFS-UD.zip
    -rw-r--r--  1   snul      snul     469M   Feb  5      00:49     q3.tgz
    -rw-r--r--  1   snul      snul     267M   Feb  1      11:29     quake2.tgz
    doneir@wolf:~$

    NOTE: The "total" you see above only lists the combined size of the files
                 in that specific directory, it does not take into account the size of
                 files inside additional directories.
 
     Example:

     doneir@wolf:~/fake$ ls -lh
     total 4.0K
     drwxr-xr-x  2   doneir    doneir    4.0K    May 27    21:08    mydir
     doneir@wolf:~/fake/mydir$ ls -lh
     total 457M
    -rw-r--r--      1   doneir    doneir    456M   May 27    21:10    Tiesto_And_Cor_Fijneman-Just_Be_Release_Party__HMH_Amsterdam-DAB-05-21-2004-MiM_INT.tar
     doneir@wolf:~/fake/mydir$

iii.) List all files (including dot files): ls -a <path>

     doneir@wolf:~$ ls -a /home/snul
      .       .Xauthority       .bashrc   100NIKON.zip    NFS-UD.zip
      ..     .bash_history     .irssi        DSC00088.JPG   q3.tgz
      .BitchX     .bash_profile     .w3m     DSC00090.JPG      quake2.tgz
     doneir@wolf:~$

     Dot files are usually places where user specific data is stored (e.g "preferences").

2.) cd - change directory

    Command: cd <flags> <directory>

    Example:

    doneir@wolf:~$ cd cyp
    doneir@wolf:~/cyp$

3.) pwd - print name of current/working directory

    Command: pwd

    Example:

   doneir@wolf:~$ pwd
   /home/doneir
   doneir@wolf:~$ cd cyp
   doneir@wolf:~/cyp$ pwd
   /home/doneir/cyp
   doneir@wolf:~/cyp$

4.) mv - move (rename) files

    Command: mv <options> <flags> <existing file> <new file>

    Example:

    doneir@wolf:~/fake$ ls
    test
    doneir@wolf:~/fake$ mv test test2
    doneir@wolf:~/fake$ ls
    test2
    doneir@wolf:~/fake$

5.) cp - copy files and directories

     Command: cp <options> <flags> <existing file> <new file>

     Example:

     doneir@wolf:~/fake$ ls
     test2
     doneir@wolf:~/fake$ cp test2 test
     doneir@wolf:~/fake$ ls
     test test2
     doneir@wolf:~/fake$

6.) rm - remove files or directories

     Command: rm <flags> <file>

     Examples:

i.) Removing a file: rm <file>

    doneir@wolf:~/fake$ ls
    test test2
    doneir@wolf:~/fake$ rm test
    doneir@wolf:~/fake$ ls
    test2
    doneir@wolf:~/fake$

ii.) Removing a directory: rm -r <directory>

     doneir@wolf:~/fake$ ls
     mydir test2
     doneir@wolf:~/fake$ rm mydir
     rm: cannot remove `mydir': Is a directory
     doneir@wolf:~/fake$ rm -r mydir
     doneir@wolf:~/fake$ ls
     test2
     doneir@wolf:~/fake$

7.) mkdir - make a directory

     Command: mkdir <flags> <directory name>

     Example:

     doneir@wolf:~/fake$ mkdir mydir
     doneir@wolf:~/fake$ ls
     mydir test2
     doneir@wolf:~/fake$

8.) su - Change user ID or become super-user

    Command: su <flags> - <username> <commands>

    Example:

    doneir@wolf:~/fake$ su - var
    Password:
    var@wolf:~$ id
    uid=1000(var) gid=1000(var) groups=29(audio),1000(var)
    var@wolf:~$ su -
    Password:
    wolf:~# id
    uid=0(root) gid=0(root) groups=0(root)
    wolf:~#

   NOTE: If you do not pass the '-' option, then you will not inherit the users environment
                 variables. The command 'set' will show you your users environment variables.

9.) ps - report a snapshot of the current processes

     Command: ps <flags>

     Summary of common 'ps' commands:

     a.) ps - report/print processes run by this terminal
     b.) ps ux - report/print processes run by this user
     c.) ps aux - report all main processes run on this system
     d.) ps auxw - report all main processes with complete commands

    I won't give any examples as the output would be quite long.

10.) kill - send a signal to a process

      Command: kill <flags> <signal> <process id>

      Summary of common 'kill' commands:

      a.) kill <pid> - nice way of killing a process (TERM)
      b.) kill -9 <pid> - bad way of killing a process, use as last resort (SIGKILL)
      c.) kill -1 <pid> - "restart" the process (HUP)
      d.) kill -BUS <pid> - drive a bus into the process (BUS)

      NOTE: The 'ps' command (e.g ps aux) gives you the PID/Process ID of the main running processes, see the second column of the ps output.

For more information on any of the commands above, please see their 'man' and 'info' pages.
     Commands: man <program>
                          info <program>
                         <program> --help
 
 
RiverLug is a group of users of GNU/Linux, BSD,
Free Software and Open Source Software
located in the Riverland region of South Australia.

Web hosting generously provided by Riverland Internet.

Linux® is a registered trademark of Linus Torvalds.
Page last modified 01 Jun 2004 15:13:08 CST