ITSC 1329 Module 4 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

ITSC 1329 Module 4

Description:

Files have been moved to a new location. ... touch Starbucks. ls. ls ~/dir1/coffees/beans. cd. 21. ITSC 1329 - Module 4. Linking to a File ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 23
Provided by: kno83
Category:

less

Transcript and Presenter's Notes

Title: ITSC 1329 Module 4


1
ITSC 1329 Module 4
  • Changing the Solaris OS Directory Contents

2
Module 4 Objectives
  • Copy files and directories
  • Move and rename files and directories
  • Create files and directories
  • Remove files and directories
  • Use symbolic links

3
Copying Files with the cp Command
  • cp command syntax
  • cp option source target
  • The cp command is used to copy a file or files to
    a target file or directory
  • cp file3 feathers
  • cp feathers feathers_6
  • ls

4
Copying Multiple Files
  • To copy multiple files, use the cp command with
    multiple file names for the source and a single
    directory name for the target
  • cp feathers feathers_6 dir1
  • ls dir1
  • To prevent overwriting an existing file, use the
    i option
  • cp i feathers feathers_6

5
Copying Directories
  • The cp command alone will not copy directories
  • cp dir1 dir10
  • The r option will copy a directory and all its
    contents
  • cp r dir1 dir10

6
More on Copying Directories
  • If the target directory does not exist, the cp
    command will create it
  • cp r dir1 dir11
  • ls dir11
  • If the target directory does exist, cp creates a
    directory with the source name inside the target
    directory
  • cp r dir1 dir11
  • ls dir11

7
Moving and Renaming Files and Directories
  • mv command syntax
  • mv option source target
  • The mv command has two uses
  • Moving files and directories
  • Renaming files and directories

8
Renaming Files
  • The mv command can be used to rename files within
    the same directory
  • mv dante dantenew
  • ls
  • It didnt copy, because the source file is gone
  • mv dantenew dante
  • ls

9
The touch Command Revisited
  • The touch command will create an empty file
  • Touch temp1 temp2 temp3 temp4 temp5

10
The cat Command Revisited
  • The cat command can create files by using
    redirection
  • cat gt catfile enter
  • This is a file created by cat. enter
  • ctrld enter
  • Always type ctrld on an empty line

11
More About Redirection
  • To append to an existing file, use two
    greater-than symbols
  • cat gtgt catfile enter
  • Now catfile has two lines. enter
  • ctrld enter
  • cat catfile

12
Moving a File to Another Directory
  • mv can be used to move a file to a different
    directory
  • ls
  • mv catfile dir1
  • ls
  • ls dir1
  • The i option prevents overwrites
  • cp dir1/catfile .
  • mv i catfile dir1/catfile

13
Moving and Renaming Directories
  • The mv command when the source and target are in
    the same directory renames the target
  • mv dir5 dir5new
  • Moving a directory
  • mv dir5new dir1
  • ls dir1
  • mv dir1/dir5new .
  • mv dir5new dir5

14
Creating Directories with mkdir
  • Mkdir command syntax
  • mkdir option directory_name
  • mkdir Reports
  • mkdir Reports/Weekly
  • Creating multiple directories
  • mkdir Once Upon A Time

15
Creating Nested Directories
  • The mkdir command will not create a directory
    inside a subdirectory that does not exist
  • Make them one at a time
  • mkdir one
  • mkdir one/two
  • mkdir one/two/three
  • mkdir one/two/three/four
  • Can be done on one line in order
  • mkdir one one/two one/two/three
    one/two/three/four
  • Or use the p option
  • mkdir p four/five/six/seven

16
Removing (Deleting) Files with rm
  • rm command syntax rm options filename
  • Caution By default, rm will NOT ask Are you
    sure? it will just delete the file
  • rm feathers_6
  • rm temp1 temp2
  • The i option will prompt you for confirmation
  • rm i feathers
  • rm i temp3 temp4 temp5

17
Removing Directories with rmdir
  • rmdir command syntax rmdir directories
  • The rmdir command will only remove empty
    directories
  • rmdir one doesnt work!
  • rmdir one/two/three/four
  • rmdir one/two/three
  • rmdir one/two
  • rmdir one
  • Or with one command
  • rmdir one/two/three/four one/two/three one/two one

18
The Restless Evil of rm r
  • The rm command was created to remove files, not
    directories
  • rm dir10 doesnt work!
  • Using the recursive (- r) option will remove the
    directory and everything inside it without
    prompting you
  • rm r dir10
  • Be very careful with rm r! Throw in i to be
    safe
  • rm ir dir11

19
Symbolic Links
  • Syntax to create a symbolic link
  • ln s source_file target_file
  • Two reasons to use a symbolic link
  • Files have been moved to a new location. The
    symbolic link will allow users who are unaware of
    the move to access the files
  • To provide a more convenient name for a long file
    path

20
Creating Symbolic Links
  • Create a symbolic link to a directory
  • ln s dir1/coffees/beans beans
  • ls l beans
  • ls l dir1/coffees/beans
  • cd beans
  • pwd
  • touch Starbucks
  • ls
  • ls /dir1/coffees/beans
  • cd

21
Linking to a File
  • Create a symbolic link to a file
  • ln s /etc/passwd passwd
  • ls l passwd
  • cat passwd
  • cat /etc/passwd
  • ls l /etc/passwd

22
Review of Module 4 Objectives
  • Copy files and directories
  • Move and rename files and directories
  • Create files and directories
  • Remove files and directories
  • Use symbolic links
Write a Comment
User Comments (0)
About PowerShow.com