Basic Commands

  1. ls
  2. cp
  3. mv
  4. rm
  5. mkdir
  6. rmdir
  7. cat
  8. grep
  9. chmod
  10. kill
  11. passwd
  12. man

ls - list contents of directories

$ ls
file1  file2  file3
  • ls -l
    In addition to the name of each file, print the file type, permissions, number of hard links, owner name, group name, size in bytes, and timestamp (the modification time unless other times are selected).For files with a time that is more than 6 months old or more than 1 hour into the future, the times.
    $ ls -l
    total 3
    -rw-r--r--   1 guest    users           8 Aug  4 15:56 file1
    -rw-r--r--   1 guest    users           8 Aug  5 15:57 file2
    -rw-r--r--   1 guest    users           8 Aug  4 15:57 file3
    
  • ls -lt
    Sort directory contents by timestamp instead of alphabetically, with the newest files listed first.
     $ ls -lt
    total 3
    -rw-r--r--   1 guest    users           8 Aug  5 15:57 file2
    -rw-r--r--   1 guest    users           8 Aug  4 15:57 file3
    -rw-r--r--   1 guest    users           8 Aug  4 15:56 file1
    

    cp - copy files

    cp [options] source dest
    $ ls
    file1  file2  file3
    $ cp file1 file4
    $ ls
    file1  file2  file3  file4
    

    mv - rename files

    mv [options] source dest mv [options] source... directory
    $ ls
    file1  file2  file3  file4
    $ mv file4 /tmp
    $ ls
    file1  file2  file3
    $ cd /tmp
    [guest@linux /tmp]$ ls
    file4
    
    $ ls
    file1  file2  file3  file4
    $ mv file4 file5
    $ ls
    file1  file2  file3  file5
    

    rm - remove files

    $ ls
    file1  file2
    $ rm file2
    $ ls
    file1
    

    mkdir - make directories

    $ ls
    file1
    $ mkdir directory
    $ ls -lt
    total 2
    drwxr-xr-x   2 guest    users        1024 Aug  5 11:40 directory/
    -rw-r--r--   1 guest    users           8 Aug  4 16:04 file1
    

    rmdir - remove empty directories

    $ ls
    directory/  file1
    $ rmdir directory
    $ ls
    file1
    

    cat - concatenate files and print on the standard output

    $ cat file1
    101     3people         2-DK
    102     none            1-room
    201     2people         2-DK
    202     4people         3-LDK
    

    grep - print lines matching a pattern

    grep [-cvn] pattern [file1 file2 ...]
    Options
    -c Suppress normal output; instead print a count of matching lines for each input file. With the -v,-revert-match option (see below), count non-match
    -v Invert the sense of matching, to select non-matching lines.
    -n Prefix each line of output with the line number within its input file.
    $ cat file1
    101     3people         2-DK
    102     none            1-room
    201     2people         2-DK
    202     4people         3-LDK
    
    $ cat file2
    301     4people         4-DK
    302     3people         3-LDK
    401     none            2-DK
    402     2people         2-DK
    
    $ grep LDK *
    file1:202       4people         3-LDK
    file2:302       3people         3-LDK
    

    chmod - change the access permissions of files

    [root@ns public_html]# ls -l
    -rw-------   1 hoge  staff         163 Aug  7 22:39 index.html
    [root@ns public_html]# chmod g+r index.html
    [root@ns public_html]# ls -l
    -rw-r-----   1 hoge  staff         163 Aug  7 22:39 index.html
    [root@ns public_html]# chmod 644 index.html
    [root@ns public_html]# ls -l
    -rw-r--r--   1 hoge  staff         163 Aug  7 22:39 index.html
    

    kill - terminate a process

  • EX1)
    # ps ax | grep dhcpd
      278  ?  S    0:00 /usr/sbin/dhcpd
     7308  p1 S    0:00 grep dhcpd
    # kill 278
    # ps ax | grep dhcpd
     7310  p1 S    0:00 grep dhcpd
    
  • EX2)
    # kill `ps ax | awk '/pppd/ {print $1}'`
    

    passwd - update a user's authentication tokens

    $ passwd
    Changing password for guest
    (current) UNIX password:
    New UNIX password:
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully
    

    man - format and display the on-line manual pages

    man keyword
    $ man ls
    
    LS(1)                                                       LS(1)
    
    NAME
           ls, dir, vdir - list contents of directories
    
    SYNOPSIS
           ls  [-abcdfgiklmnpqrstuxABCFGLNQRSUX1] [-w cols] [-T cols]
           [-I pattern] [--all]  [--escape]  [--directory]  [--inode]
           [--kilobytes]  [--numeric-uid-gid]  [--no-group]  [--hide-
           control-chars] [--reverse] [--size] [--width=cols] [--tab-
           size=cols]  [--almost-all] [--ignore-backups] [--classify]
           [--file-type] [--full-time] [--ignore=pattern] [--derefer-
           ence]     [--literal]     [--quote-name]     [--recursive]
           [--sort={none,time,size,extension}]   [--format={long,ver-
           bose,commas,across,vertical,single-column}]
           [--time={atime,access,use,ctime,status}] [--help]  [--ver-
           sion]  [--color[={yes,no,tty}]]  [--colour[={yes,no,tty}]]
           [name...]
    
    DESCRIPTION
           This documentation is no longer being maintained  and  may
    ......................................
    

    Back
    Google
    Web www.grape-info.com