Unix commands - UB-BiomedicalInformatics/BMI_p2p_sessions GitHub Wiki

Table of Contents

Basic Commands

Show pathname of current directory

$ pwd

List files

$ ls

Make a directory

$ mkdir directory-name

Change directory

$ cd directory-name

Change directory back to home directory

$ cd

Copy a file

$ cp old-filename new-filename

View a file

$ cat filename

Edit a file

$ vi filename

Delete a file

$ rm filename

Delete a directory (recursively)

$ rm -R directory-name
  • All files and subdirectories are deleted

Move a file

$ mv old-filename new-filename

Help with Commands

Man Pages

The man command will give usage information for any UNIX command. Press space bar or enter to page through man page. Type q to quit.

$ man ls
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 is specified.

       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 C-style escapes for nongraphic characters

       --block-size=SIZE
              scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes;  see  SIZE
              format below

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with  -lt:  sort  by, and show, ctime (time of last modification of file status information); with -l: show ctime and
              sort by name; otherwise: sort by ctime, newest first
...

Manual page ls(1) line 1 (press h for help or q to quit)

Command help

Most commands offer a quick help (as opposed to the full man page from above).

$ ls --help
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 C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
...

Permissions

Change permissions

$ chmod

Arguments to chmod command: ugo+-rwx

ugo are user, group and other; rwx are read, write and execute

Add execute permission for yourself

$ chmod u+x filename

Remove read, write and execute for group and other from a directory and its contents

$ chmod -R go-rwx directory-name
⚠️ **GitHub.com Fallback** ⚠️