SlideShare a Scribd company logo
Using UNIX This document gives an overview of how to use UNIX. I don’t know who wrote this, but it’s very useful.
Getting More Help You can get more information about any of the topics discussed here by typing “ man <topic name>”,  for instance,     man ls If you don’t quite remember the name of the command, you can say “ apropos <topic name”, for instance     apropos directory There are also many good books in the library that describe all this.
Remember This Picture? There are many standard applications: file system commands interactive shells text editors compilers text processing Applications Libraries \ Kernel (OS) Hardware
Logging In To log in to a Unix machine you can either: sit at the  console  (the computer itself) access via the net (using telnet, rsh, ssh, kermit, or some other remote access client). The system prompts you for your username and password. Usernames and passwords are case sensitive!
Session Startup Once you log in, your shell will be started and it will display a prompt. When the shell is started it looks in your home directory for some customization files. You can change the shell prompt, your PATH, and a bunch of other things by creating customization files.
Your Home Directory Every Unix process* has a notion of the “current working directory”. Your shell (which is a process) starts with the current working directory set to your home directory.
Interacting with the Shell The shell prints a prompt and waits for you to type in a command. The shell can deal with a couple of types of commands: shell internals - commands that the shell handles directly. External programs - the shell runs a program for you.
Some Simple Commands Here are some simple commands to get you started: ls lists file names (like DOS dir command). who lists users currently logged in. date shows the current time and date. pwd print working directory
The  ls  command The ls command displays the names of some files. If you give it the name of a directory as a  command line parameter  it will list all the files in the named directory.
ls  Command Line Options We can modify the output format of the  ls  program with a  command line option . The ls command support a bunch of options: l  long  format (include file times, owner and permissions) a   all  (shows hidden* files as well as regular files) F   include special char to indicate file types. *hidden files have names that start with &quot;.&quot;
Moving Around in the File System There cd command can change the current working directory: cd   c hange  d irectory The general form is: cd [directoryname]
cd With no parameter, the  cd  command changes the current directory to your home directory. You can also give  cd  a relative or absolute pathname: cd /usr cd ..
Some more commands and command line options ls -R   will list everything in a directory and in all the subdirectories recursively (the entire hierarchy). you might want to know that Ctrl-C will cancel a command (stop the command)! pwd : print working directory df : shows what disk holds a directory.
Copying Files The  cp  command copies files: cp [options] source dest The source is the name of the file you want to copy. dest is the name of the new file. source and dest can be relative or absolute.
Another form of  cp If you specify a dest that is a directory, cp will put a copy of the source in the directory. The filename will be the same as the filename of the source file.  cp [options] source destdir
Deleting (removing) Files The  rm  command deletes files: rm [options] names... rm  stands for &quot;remove&quot;. You can remove many files at once: rm foo /tmp/blah /users/clinton/intern
File attributes Every file has some attributes: Access Times:  when the file was created when the file was last changed when the file was last read Size Owners (user and group) Permissions
File Time Attributes Time Attributes: when the file was last changed ls -l when the file was created* ls -lc when the file was last read (accessed) ls -ul * actually it’s the time the file status last changed.
Other filesystem and file commands mkdir make directory rmdir remove directory touch change file timestamp (can also create a blank file) cat concatenate files and print out to terminal.
Shells Also known as: Unix Command Interpreter
Shell as a user interface A shell is a command interpreter that turns text that you type (at the command line) in to actions: runs a program, perhaps the  ls  program. allows you to edit a  command line . can establish alternative sources of input and destinations for output for programs.
Running a Program You type in the name of a program and some command line options: The shell reads this line, finds the program and runs it, feeding it the options you specified. The shell establishes 3 I/O  channels : Standard Input Standard Output Standard Error
Programs and Standard I/O Program Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR)
Unix Commands Most Unix commands (programs): read something from standard input. send something to standard output (typically depends on what the input is!). send error messages to standard error.
Defaults for I/O When a shell runs a program for you: standard input is your keyboard. standard output is your screen/window. standard error is your screen/window.
Terminating Standard Input If standard input is your keyboard, you can type stuff in that goes to a program. To end the input you press Ctrl-D (^D) on a line by itself, this ends the input  stream . The shell is a program that reads from standard input. What happens when you give the shell ^D?
Popular Shells sh Bourne Shell  ksh  Korn Shell  csh  C Shell bash  Bourne-Again Shell
Customization Each shell supports some customization. User prompt Where to find mail Shortcuts The customization takes place in  startup  files – files that are read by the shell when it starts up
Startup files sh,ksh:  /etc/profile (system defaults)    ~/.profile bash: ~/.bash_profile ~/.bashrc ~/.bash_logout csh: ~/.cshrc ~/.login ~/.logout
Wildcards (metacharacters) for filename abbreviation When you type in a command line the shell treats some characters as special. These special characters make it easy to specify filenames. The shell processes what you give it, using the special characters to replace your command line with one that includes a bunch of file names.
The special character * * matches anything. If you give the shell * by itself (as a command line argument) the shell will remove the * and replace it with all the filenames in the current directory. “ a*b ”  matches all files in the current directory that start with  a  and end with  b .
Understanding * The  echo  command prints out whatever you give it: > echo hi hi Try this: > echo *
* and  ls Things to try: ls * ls –al * ls a* ls *b
Input Redirection The shell can attach things other than your keyboard to standard input. A file (the contents of the file are fed to a program as if you typed it). A pipe (the output of another program is fed as input as if you typed it).
Output Redirection The shell can attach things other than your screen to standard output (or stderr). A file (the output of a program is stored in  file). A pipe (the output of a program is fed as input to another program).
How to tell the shell to redirect things To tell the shell to store the output of your program in a file, follow the command line for the program with the “>” character followed by the filename: ls > lsout the command above will create a file named  lsout  and put the output of the  ls  command in the file.
Input redirection To tell the shell to get standard input from a file, use the “<“ character: sort < nums The command above would sort the lines in the file nums and send the result to stdout.
You can do both! sort < nums > sortednums tr a-z A-Z < letter > rudeletter
Pipes A pipe is a holder for a stream of data. A pipe can be used to hold the output of one program and feed it to the input of another. prog1 prog2 STDOUT STDIN
Asking for a pipe Separate 2 commands with the “|” character. The shell does all the work! ls | sort  ls | sort > sortedls
Shell Variables The shell keeps track of a set of parameter names and values. Some of these parameters determine the behavior of the shell. We can access these variables: set new values for some to customize the shell. find out the value of some to help accomplish a task.
Example Shell Variables sh / ksh / bash PWD   current working directory PATH   list of places to look for commands HOME   home directory of user MAIL   where your email is stored TERM   what kind of terminal you have HISTFILE   where your command history  is saved
Displaying Shell Variables Prefix the name of a shell variable with &quot;$&quot;. The  echo  command will do: echo $HOME echo $PATH You can use these variables on any command line: ls -al $HOME
Setting Shell Variables You can change the value of a shell variable with an assignment command (this is a shell  builtin  command): HOME=/etc PATH=/usr/bin:/usr/etc:/sbin NEWVAR=&quot;blah blah blah&quot;
set  command (shell builtin) The  set  command with no parameters will print out a list of all the shell varibles. You'll probably get a pretty long list… Depending on your shell, you might get other stuff as well...
The  PATH Each time you give the shell a command line it does the following: Checks to see if the command is a shell built-in. If not - tries to find a program whose name (the filename) is the same as the command. The  PATH  variable tells the shell where to look for programs (non built-in commands).
echo  $PATH The  PATH  is a list of &quot;:&quot; delimited directories. The  PATH  is a list and a  search order . You can add stuff to your PATH by changing the shell startup file (on RCS change  ~/.bashrc )
Job Control  The shell allows you to manage  jobs place  jobs  in the  background move a job to the foreground suspend a job kill a job
Background jobs If you follow a command line with &quot;&&quot;, the shell will run the  job  in the background. you don't need to wait for the job to complete, you can type in a new command right away. you can have a bunch of jobs running at once. you can do all this with a single terminal (window). ls -lR > saved_ls &
Listing jobs The command  jobs  will list all background jobs: > jobs [1] Running  ls -lR > saved_ls & > The shell assigns a number to each job (this one is job number 1).
Suspending and Killing the Foreground Job You can suspend the foreground job by pressing ^Z (Ctrl-Z).  Suspend means the job is stopped, but not dead. The job will show up in the  jobs  output. You can  kill  the foreground job by pressing ^C (Ctrl-C).  It's gone...
Quoting - the problem We've already seen that some characters mean something special when typed on the command line:  * ? []   What if we don't want the shell to treat these as special - we really mean *, not all the files in the current directory: echo here is a star *
Quoting - the solution To turn off special meaning - surround a string with double quotes: > echo here is a star &quot;*&quot; > here is a star *
Quoting Exceptions Some  special  characters are  not   ignored even if inside double quotes: $ (prefix for variable names) &quot; the quote character itself \  slash is always something special (\n) you can use \$ to mean $ or \&quot; to mean &quot; echo &quot;This is a quote \&quot; &quot;
Single quotes You can use single quotes just like double quotes. Nothing (except  ' ) is treated special. >  echo 'This is a quote \&quot; ' This is a quote \&quot; >
Backquotes are different! If you surround a string with backquotes the string is replaced with the result of running the command in backquotes: > echo `ls` foo fee file? > PS1=`date` Tue Jan 25 00:32:04 EST 2000 new prompt!
Programming Text editors emacs, vi Can also use any PC editor if you can get at the files from your PC. Compilers – gcc. Debuggers: gdb xxgdb

More Related Content

What's hot (20)

Shell Scripting
Shell Scripting
Gaurav Shinde
 
Unix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
Quick start bash script
Quick start bash script
Simon Su
 
Unix shell scripting basics
Unix shell scripting basics
Manav Prasad
 
Chap06
Chap06
Dr.Ravi
 
Introduction to shell scripting
Introduction to shell scripting
Corrado Santoro
 
Unix Shell Scripting Basics
Unix Shell Scripting Basics
Sudharsan S
 
Linux shell scripting
Linux shell scripting
Mohamed Abubakar Sittik A
 
Unix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Zyxware Technologies
 
Bash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Unix - Shell Scripts
Unix - Shell Scripts
ananthimurugesan
 
Bash shell
Bash shell
xylas121
 
Shell scripting
Shell scripting
Ashrith Mekala
 
Shell scripting
Shell scripting
Geeks Anonymes
 
Shellscripting
Shellscripting
Narendra Sisodiya
 
Intro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scripting
Akshay Siwal
 
Unix shell scripts
Unix shell scripts
Prakash Lambha
 
Unix lab manual
Unix lab manual
Chaitanya Kn
 
Unix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
Quick start bash script
Quick start bash script
Simon Su
 
Unix shell scripting basics
Unix shell scripting basics
Manav Prasad
 
Introduction to shell scripting
Introduction to shell scripting
Corrado Santoro
 
Unix Shell Scripting Basics
Unix Shell Scripting Basics
Sudharsan S
 
Unix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Zyxware Technologies
 
Bash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Bash shell
Bash shell
xylas121
 
Intro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scripting
Akshay Siwal
 

Similar to Using Unix (20)

lec4.docx
lec4.docx
ismailaboshatra
 
(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial
jayaramprabhu
 
21bUc8YeDzZpE
21bUc8YeDzZpE
Aniruddh Tyagi
 
21bUc8YeDzZpE
21bUc8YeDzZpE
aniruddh Tyagi
 
21bUc8YeDzZpE
21bUc8YeDzZpE
aniruddh Tyagi
 
01c shell
01c shell
Kevin Lee
 
Shell intro
Shell intro
Teja Bheemanapally
 
Linux introduction-commands2338
Linux introduction-commands2338
Cam YP Co., Ltd
 
Linux introduction-commands2338
Linux introduction-commands2338
Cam YP Co., Ltd
 
Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
 
Unix
Unix
Sudharsan S
 
58518522 study-aix
58518522 study-aix
homeworkping3
 
linux chapter 5.pptx lesson About introduction to linux
linux chapter 5.pptx lesson About introduction to linux
zakiaxmed534
 
Linux powerpoint
Linux powerpoint
bijanshr
 
intro unix/linux 03
intro unix/linux 03
duquoi
 
8.1.intro unix
8.1.intro unix
southees
 
Linux Basics
Linux Basics
Team-VLSI-ITMU
 
Unixscripting
Unixscripting
Cesar Adolfo Balderas Guzman
 
Unix and Linux - The simple introduction
Unix and Linux - The simple introduction
Amity University Noida
 
Linux
Linux
RittikaBaksi
 
Ad

More from Dr.Ravi (19)

Corporate Overview
Corporate Overview
Dr.Ravi
 
Excel For The Ceo
Excel For The Ceo
Dr.Ravi
 
Project Specs Pf
Project Specs Pf
Dr.Ravi
 
Pf Day5
Pf Day5
Dr.Ravi
 
Assignments Programming Fundamentals
Assignments Programming Fundamentals
Dr.Ravi
 
Hdd Chssc
Hdd Chssc
Dr.Ravi
 
Chssc Day3
Chssc Day3
Dr.Ravi
 
Chssc Day1
Chssc Day1
Dr.Ravi
 
Pf Day3
Pf Day3
Dr.Ravi
 
Ldd Pf
Ldd Pf
Dr.Ravi
 
Chssc Assignments
Chssc Assignments
Dr.Ravi
 
Chssc Day4
Chssc Day4
Dr.Ravi
 
Chssc Day2
Chssc Day2
Dr.Ravi
 
Shell Scripts
Shell Scripts
Dr.Ravi
 
Unix Lec2
Unix Lec2
Dr.Ravi
 
Unix Book
Unix Book
Dr.Ravi
 
Unix Basics 04sp
Unix Basics 04sp
Dr.Ravi
 
Wicked Cool Shell Scripts
Wicked Cool Shell Scripts
Dr.Ravi
 
SAP INTRO
SAP INTRO
Dr.Ravi
 
Corporate Overview
Corporate Overview
Dr.Ravi
 
Excel For The Ceo
Excel For The Ceo
Dr.Ravi
 
Project Specs Pf
Project Specs Pf
Dr.Ravi
 
Assignments Programming Fundamentals
Assignments Programming Fundamentals
Dr.Ravi
 
Hdd Chssc
Hdd Chssc
Dr.Ravi
 
Chssc Day3
Chssc Day3
Dr.Ravi
 
Chssc Day1
Chssc Day1
Dr.Ravi
 
Chssc Assignments
Chssc Assignments
Dr.Ravi
 
Chssc Day4
Chssc Day4
Dr.Ravi
 
Chssc Day2
Chssc Day2
Dr.Ravi
 
Shell Scripts
Shell Scripts
Dr.Ravi
 
Unix Lec2
Unix Lec2
Dr.Ravi
 
Unix Book
Unix Book
Dr.Ravi
 
Unix Basics 04sp
Unix Basics 04sp
Dr.Ravi
 
Wicked Cool Shell Scripts
Wicked Cool Shell Scripts
Dr.Ravi
 
SAP INTRO
SAP INTRO
Dr.Ravi
 
Ad

Recently uploaded (20)

Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 

Using Unix

  • 1. Using UNIX This document gives an overview of how to use UNIX. I don’t know who wrote this, but it’s very useful.
  • 2. Getting More Help You can get more information about any of the topics discussed here by typing “ man <topic name>”, for instance,  man ls If you don’t quite remember the name of the command, you can say “ apropos <topic name”, for instance  apropos directory There are also many good books in the library that describe all this.
  • 3. Remember This Picture? There are many standard applications: file system commands interactive shells text editors compilers text processing Applications Libraries \ Kernel (OS) Hardware
  • 4. Logging In To log in to a Unix machine you can either: sit at the console (the computer itself) access via the net (using telnet, rsh, ssh, kermit, or some other remote access client). The system prompts you for your username and password. Usernames and passwords are case sensitive!
  • 5. Session Startup Once you log in, your shell will be started and it will display a prompt. When the shell is started it looks in your home directory for some customization files. You can change the shell prompt, your PATH, and a bunch of other things by creating customization files.
  • 6. Your Home Directory Every Unix process* has a notion of the “current working directory”. Your shell (which is a process) starts with the current working directory set to your home directory.
  • 7. Interacting with the Shell The shell prints a prompt and waits for you to type in a command. The shell can deal with a couple of types of commands: shell internals - commands that the shell handles directly. External programs - the shell runs a program for you.
  • 8. Some Simple Commands Here are some simple commands to get you started: ls lists file names (like DOS dir command). who lists users currently logged in. date shows the current time and date. pwd print working directory
  • 9. The ls command The ls command displays the names of some files. If you give it the name of a directory as a command line parameter it will list all the files in the named directory.
  • 10. ls Command Line Options We can modify the output format of the ls program with a command line option . The ls command support a bunch of options: l long format (include file times, owner and permissions) a all (shows hidden* files as well as regular files) F include special char to indicate file types. *hidden files have names that start with &quot;.&quot;
  • 11. Moving Around in the File System There cd command can change the current working directory: cd c hange d irectory The general form is: cd [directoryname]
  • 12. cd With no parameter, the cd command changes the current directory to your home directory. You can also give cd a relative or absolute pathname: cd /usr cd ..
  • 13. Some more commands and command line options ls -R will list everything in a directory and in all the subdirectories recursively (the entire hierarchy). you might want to know that Ctrl-C will cancel a command (stop the command)! pwd : print working directory df : shows what disk holds a directory.
  • 14. Copying Files The cp command copies files: cp [options] source dest The source is the name of the file you want to copy. dest is the name of the new file. source and dest can be relative or absolute.
  • 15. Another form of cp If you specify a dest that is a directory, cp will put a copy of the source in the directory. The filename will be the same as the filename of the source file. cp [options] source destdir
  • 16. Deleting (removing) Files The rm command deletes files: rm [options] names... rm stands for &quot;remove&quot;. You can remove many files at once: rm foo /tmp/blah /users/clinton/intern
  • 17. File attributes Every file has some attributes: Access Times: when the file was created when the file was last changed when the file was last read Size Owners (user and group) Permissions
  • 18. File Time Attributes Time Attributes: when the file was last changed ls -l when the file was created* ls -lc when the file was last read (accessed) ls -ul * actually it’s the time the file status last changed.
  • 19. Other filesystem and file commands mkdir make directory rmdir remove directory touch change file timestamp (can also create a blank file) cat concatenate files and print out to terminal.
  • 20. Shells Also known as: Unix Command Interpreter
  • 21. Shell as a user interface A shell is a command interpreter that turns text that you type (at the command line) in to actions: runs a program, perhaps the ls program. allows you to edit a command line . can establish alternative sources of input and destinations for output for programs.
  • 22. Running a Program You type in the name of a program and some command line options: The shell reads this line, finds the program and runs it, feeding it the options you specified. The shell establishes 3 I/O channels : Standard Input Standard Output Standard Error
  • 23. Programs and Standard I/O Program Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR)
  • 24. Unix Commands Most Unix commands (programs): read something from standard input. send something to standard output (typically depends on what the input is!). send error messages to standard error.
  • 25. Defaults for I/O When a shell runs a program for you: standard input is your keyboard. standard output is your screen/window. standard error is your screen/window.
  • 26. Terminating Standard Input If standard input is your keyboard, you can type stuff in that goes to a program. To end the input you press Ctrl-D (^D) on a line by itself, this ends the input stream . The shell is a program that reads from standard input. What happens when you give the shell ^D?
  • 27. Popular Shells sh Bourne Shell ksh Korn Shell csh C Shell bash Bourne-Again Shell
  • 28. Customization Each shell supports some customization. User prompt Where to find mail Shortcuts The customization takes place in startup files – files that are read by the shell when it starts up
  • 29. Startup files sh,ksh: /etc/profile (system defaults) ~/.profile bash: ~/.bash_profile ~/.bashrc ~/.bash_logout csh: ~/.cshrc ~/.login ~/.logout
  • 30. Wildcards (metacharacters) for filename abbreviation When you type in a command line the shell treats some characters as special. These special characters make it easy to specify filenames. The shell processes what you give it, using the special characters to replace your command line with one that includes a bunch of file names.
  • 31. The special character * * matches anything. If you give the shell * by itself (as a command line argument) the shell will remove the * and replace it with all the filenames in the current directory. “ a*b ” matches all files in the current directory that start with a and end with b .
  • 32. Understanding * The echo command prints out whatever you give it: > echo hi hi Try this: > echo *
  • 33. * and ls Things to try: ls * ls –al * ls a* ls *b
  • 34. Input Redirection The shell can attach things other than your keyboard to standard input. A file (the contents of the file are fed to a program as if you typed it). A pipe (the output of another program is fed as input as if you typed it).
  • 35. Output Redirection The shell can attach things other than your screen to standard output (or stderr). A file (the output of a program is stored in file). A pipe (the output of a program is fed as input to another program).
  • 36. How to tell the shell to redirect things To tell the shell to store the output of your program in a file, follow the command line for the program with the “>” character followed by the filename: ls > lsout the command above will create a file named lsout and put the output of the ls command in the file.
  • 37. Input redirection To tell the shell to get standard input from a file, use the “<“ character: sort < nums The command above would sort the lines in the file nums and send the result to stdout.
  • 38. You can do both! sort < nums > sortednums tr a-z A-Z < letter > rudeletter
  • 39. Pipes A pipe is a holder for a stream of data. A pipe can be used to hold the output of one program and feed it to the input of another. prog1 prog2 STDOUT STDIN
  • 40. Asking for a pipe Separate 2 commands with the “|” character. The shell does all the work! ls | sort ls | sort > sortedls
  • 41. Shell Variables The shell keeps track of a set of parameter names and values. Some of these parameters determine the behavior of the shell. We can access these variables: set new values for some to customize the shell. find out the value of some to help accomplish a task.
  • 42. Example Shell Variables sh / ksh / bash PWD current working directory PATH list of places to look for commands HOME home directory of user MAIL where your email is stored TERM what kind of terminal you have HISTFILE where your command history is saved
  • 43. Displaying Shell Variables Prefix the name of a shell variable with &quot;$&quot;. The echo command will do: echo $HOME echo $PATH You can use these variables on any command line: ls -al $HOME
  • 44. Setting Shell Variables You can change the value of a shell variable with an assignment command (this is a shell builtin command): HOME=/etc PATH=/usr/bin:/usr/etc:/sbin NEWVAR=&quot;blah blah blah&quot;
  • 45. set command (shell builtin) The set command with no parameters will print out a list of all the shell varibles. You'll probably get a pretty long list… Depending on your shell, you might get other stuff as well...
  • 46. The PATH Each time you give the shell a command line it does the following: Checks to see if the command is a shell built-in. If not - tries to find a program whose name (the filename) is the same as the command. The PATH variable tells the shell where to look for programs (non built-in commands).
  • 47. echo $PATH The PATH is a list of &quot;:&quot; delimited directories. The PATH is a list and a search order . You can add stuff to your PATH by changing the shell startup file (on RCS change ~/.bashrc )
  • 48. Job Control The shell allows you to manage jobs place jobs in the background move a job to the foreground suspend a job kill a job
  • 49. Background jobs If you follow a command line with &quot;&&quot;, the shell will run the job in the background. you don't need to wait for the job to complete, you can type in a new command right away. you can have a bunch of jobs running at once. you can do all this with a single terminal (window). ls -lR > saved_ls &
  • 50. Listing jobs The command jobs will list all background jobs: > jobs [1] Running ls -lR > saved_ls & > The shell assigns a number to each job (this one is job number 1).
  • 51. Suspending and Killing the Foreground Job You can suspend the foreground job by pressing ^Z (Ctrl-Z). Suspend means the job is stopped, but not dead. The job will show up in the jobs output. You can kill the foreground job by pressing ^C (Ctrl-C). It's gone...
  • 52. Quoting - the problem We've already seen that some characters mean something special when typed on the command line: * ? [] What if we don't want the shell to treat these as special - we really mean *, not all the files in the current directory: echo here is a star *
  • 53. Quoting - the solution To turn off special meaning - surround a string with double quotes: > echo here is a star &quot;*&quot; > here is a star *
  • 54. Quoting Exceptions Some special characters are not ignored even if inside double quotes: $ (prefix for variable names) &quot; the quote character itself \ slash is always something special (\n) you can use \$ to mean $ or \&quot; to mean &quot; echo &quot;This is a quote \&quot; &quot;
  • 55. Single quotes You can use single quotes just like double quotes. Nothing (except ' ) is treated special. > echo 'This is a quote \&quot; ' This is a quote \&quot; >
  • 56. Backquotes are different! If you surround a string with backquotes the string is replaced with the result of running the command in backquotes: > echo `ls` foo fee file? > PS1=`date` Tue Jan 25 00:32:04 EST 2000 new prompt!
  • 57. Programming Text editors emacs, vi Can also use any PC editor if you can get at the files from your PC. Compilers – gcc. Debuggers: gdb xxgdb