12
Basic Unix Commands Lecture 3 COP 3363 Fall 2019 September 3, 2019

Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Basic Unix Commands

Lecture 3COP 3363 Fall 2019

September 3, 2019

Page 2: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - clear

clear

The clear command clears the current screen and displays theprompt at the top of the screen.

clear command - before

Page 3: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - clear

clear

The clear command clears the current screen and displays theprompt at the top of the screen.

clear command - after

Page 4: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - pwd

I A Directory is the unix term for a folder.

I Once you log in to your unix account, you will have a specifichome directory, usually identified by your username.

I Usually, the command line prompt, where you start typingcommands, includes the current directory.

I When you log in, the command line prompt will show that youare in your home directory.

I You can create sub-directories in your home directory, andthose can each contain several levels of sub-directories. Youcan organize your work into directories and move throughthem as needed.

I At any point in time, you can ask unix to show you whichdirectory you are currently working in, using the pwdcommand.

Page 5: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - pwd

I pwd - shows the absolute path (from the root) to the presentworking directory (i.e. the directory you are currently in).

I When you log in, you should be located in your own homedirectory. For example, my user name is “jayarama”, and myhome directory is /home/faculty/jayarama

pwd command

Page 6: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - ls

I The ls command lists the contents of a directory.I The listing you see is just a plain and simple listing of the

contents of the current working directory.I This is like opening a folder in Windows and looking inside it.

ls command

Page 7: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - ls

I Some commands have more options, specified as flags afterthe command.

I For example, the ls command has the -l option (longoption) for more information besides filenames.

ls command, long option (ls -l)

Page 8: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - ls

I In the above sample, there are many pieces of information.

I Each line represents one directory or file. The first characterof the line indicates what it is. If the first character is a “d”,the item is a directory. If the first character is a dash “-”,then the item is simply a file.

I Note that the item “arrays.cpp” is a file, while “Fa18” is adirectory.

I The next set of characters indicate file permission bits (whichwill be discussed later).

I Other information includes the owner of the file, any groupthat the file belongs to, the file size, the most recentmodification date and time (last time it was changed), andthe file or directory name itself.

Page 9: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - cd

I To move between directories, we use the cd (changedirectory) command

I If you’re moving to a directory in the current directory, youcan use cd dirname, where “dirname” is the name of thedirectory (case sensitive)

cd command

Page 10: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Unix Commands - cd

I cd by itself, it will take you to your home directory.

I You can specify where you want to go by using an entire pathname. For example, “cd /usr/include” takes you to wherethe C library files are.

I You can also specify where to go from a starting point in yourown home directory by using the ∼ as the first directory entry

I The ∼ is a special symbol that can substitute as your homedirectory.

I “cd ..” will take you back one directory level.

I You can also mix and match, separating directory names. “cd ../next/level” will take you one level back and then tothe directory level, in the next directory. stored:

Page 11: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

Into to vim

I vim is a very versatile text editor. A text editor is a programthat lets you create, open, edit and save text files, amongother things.

I To create a file, type “vim filename” on the prompt. Thiswill open the empty file “filename” on the vim editor.

I This will edit the file in command mode. To add text/edit thefile, press “i”. The file will now enter INSERT mode.

I Once you’re done typing, you can save the file by doing thefollowing:

I Hit Esc to exit Insert modeI Type “:w” to save.I Now type “:q” to quit.

I You can also combine the two. “:wq”

Page 12: Basic Unix Commands - Computer Science, FSUjayarama/introfa19/Slides/UnixComm1.pdfUnix Commands - pwd I A Directory is the unix term for a folder. I Once you log in to your unix account,

g++ compiler

I Once you have saved the file and exited, compile the programby typing “g++ filename” at the prompt.

I If there are no errors, you will get the prompt again. If thereare errors, g++ will list them.

I Once you have compiled the program, and it compiles withouterrors, you can run the executable.

I By default, the executable is called a.out. We can give itanother name by using the -o flag when we compile.