Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]

Similar presentations


Presentation on theme: "Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]"— Presentation transcript:

1 Linux Lecture #02

2 File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options] [File]... Concatenate FILE(s), or standard input, to standard output. Examples: Display a file: $ cat myfile.txt Concatenate two files: $ cat File1.txt File2.txt > union.txt If you need to combine two files but also eliminate duplicates, this can be done with sort unique: $ sort -u File1.txt File2.txt > unique_union.txtsort Put the contents of a file into a variable $ my_variable=`cat File3.txt` create a new file $cat > filename …. ^Z to save & exit.

3 File Related Commands….. cp Copy one or more files to another location Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. Syntax cp [options]... Source Dest Examples Copy demofile to demofile.bak : $ cp demofile demofile.bak or $ cp demofile{,.bak} Copy demofile.txt to demofile.bak : $ file="demofile.txt" $ cp $file ${file%.*}.bak Copy floppy to home directory: $ cp -f /mnt/floppy/* ~

4 File Related Commands…. mv Move or rename files or directories. SYNTAX mv [options]... Source Dest mv [options]... Source... Directory If the last argument names an existing directory, `mv' moves each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it renames the first as the second. It is an error if the last argument is not a directory and more than two files are given. Examples Rename the file apple as orange.doc: mv apple orange.doc Move orange.doc to the Documents folder: mv orange.doc./Documents/orange.doc

5 File Related Commands….. rm Remove files (delete/unlink) Syntax rm [options]... file... Options -f, --force ignore nonexistent files, never prompt -i Prompt before every removal -r, -R, --recursive Remove directories and their contents recursively -v, --verbose Explain what is being done IMPORTANT: rm does not delete directories without –r option

6 Exercise Create the following tree structure: / gec cseece ABAB CDCD MNMN

7 Wild Card Characters Used for matching patterns: ?Matches with one non empty character *Mather with everything, including blank []Matches with a specific set of characters given in brackets. These characters can be used for multiple file selection in cp, mv or rm commands.

8 Wild Card Characters…… A folder contains the following files: A1, A2, A11, A22, B1, B2 To delete A1, A2, we can use: $ rm A? To delete A1, A2, A11, A22, we can use: $ rm A* To delete A1 and B1, we can use: $ rm ?1


Download ppt "Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]"

Similar presentations


Ads by Google