<<

Basic Commands - 2

Lecture 4 COP 3363 Spring 2021

January 20, 2021 vim - a basic usage guide

We will be using the vim text editor for the course. This is a quick way to get started. I Creating a file: vim filename This will create a file if it doesn’t exists and open the empty file in vim. I Opening an existing file: Type vim filename This will open an existing file in vim with all of it’s previous contents. I vim will open in mode. To enter text press “i”. This will enter insert mode. I Once you have finished typing, go back to command mode by pressing the ESC key. I To Save file: In command mode, type “:” and Enter I To Save file and : In command mode, type “:wq” and Enter I To exit without saving: In command mode, type “:q!” and Enter. Some basic vim settings

vim settings are written into the vimrc file. I To open the file, In Your Home Folder open the file by typing “vim ∼/.vimrc” and Enter. I In that file, please sure you have the following exactly: set expandtab set tabstop=4 set softtabstop=4 set shiftwidth=4 set textwidth=80 syntax on set wrap set laststatus=2 set showmode set showcmd set number set matchpairs+=<:> I Save and Quit vim. Unix Commands -

I The mkdir command stands for “make directory”.

I It is used to create a directory or folder.

I Syntax: mkdir Here, “dirname” is the name of the new directory you want to create.

I This will create a directory with the given name in the current directory. Unix Commands -

I The rmdir command stands for “remove directory”.

I It is used to delete the given (empty) directory.

I Syntax: rmdir dirname Here, “dirname” is the name of the new directory you want to delete.

I This will delete a directory with the given name in the current directory, as long as it is empty. It will fail if the directory contains other files or directories. These files have to be deleted first, before deleting the directory. Combining filenames with paths

I A directory is a series of directories separated by the slash character, like this: ∼jayarama/intro/examples

I A file can be referred to by just its filename, as long as it is in the current working directory

I If you want to refer to a file by name, but you are in a different working directory, then simply attach the filename to the end of the path name, again with a slash as a separator: ∼jayarama/intro/examples/hello.cpp Unix Commands -

I The cp command is used to files.

I Syntax: cp sourcefile destinationfile

I “sourcefile” can refer to the name of the source file alone, or the path and filename of the source file. Either way, this part refers to the original that is being copied or moved.

I “destinationfile” can refer to either a new destination filename, a new destination location ( a different directory), or a combination of both.

I If the destination file does not exist, it will be created. If the file exists, IT WILL BE OVERWRITTEN. Unix Commands -

I The mv command is use to a file.

I Syntax: mv sourcefile destinationfile

I “sourcefile” can refer to the name of the source file alone, or the path and filename of the source file. Either way, this part refers to the original that is being copied or moved.

I “destinationfile” can refer to either a new destination filename, a new destination location ( a different directory), or a combination of both.

I If the destination file does not exist, it will be created. If the file exists, IT WILL BE OVERWRITTEN.

I The mv command REMOVES the file from its original location (unlike cp) keeps a local copy.

I When the source and destination files are in the same directory, it RENAMES the file. Unix Commands -

I The rm command is used to remove (delete) a file.

I Syntax: rm filename. Here, “filename” is thename of the file you want to delete.

I Once the file is deleted, it has been deleted forever, and cannot be recovered.