Download presentation
Presentation is loading. Please wait.
Published byChristiana Roberts Modified over 9 years ago
1
Working with Files Chapter 5
2
Display a Calendar Display a calendar for a specific month – cal 12 2000 Display a calendar for a specific year – cal 2000 What if we want to save the calendar?
3
Creating a file with redirection Most commands send their output to the screen You can change (redirect) where you want the results sent – cal 2000 > 2001 Be careful: output redirection will overwrite the target file if it already exists
4
ls list Displays all files in the current directory. Flags: – -a: shows all the files, including hidden ones – -F: puts a / after directories, an * after executables, and an @ after links – -l: displays a long listing of files – -R: will also list contents of sub-directories – -s: will list the size of the files
5
Viewing the file What if you want to see the contents of a file? Use the cat command – cat [name of file] – cat 2000 Use the more command – more [name of file] – more 2000
6
Chaining files together Use the cat command to see more than one file – cal 6 2000 > june – cal 7 2000 > july – cal 8 2000 > august – cat june july august Send the results to another file – cat june july august > summer2000
7
Appending files Unix allows you to add information to the end of a file rather than overwriting it – This is called appending Command output can be appended ‘>>’ – cal 9 2000 >> summer2000 The output of the cal command is appended to the end of the file summer2000 On file can be appended to the end of another using cat and redirection – cat summer2000 >> myCalendar OR – cat myCalendar summer2000 > myCalendar
8
cp Copies the contents of one file to another – cp [file to copy] [new file name] Flags – -r: will copy directories and all their contents – Without this flag, the directory will not be copied and you will get an error message
9
mv Better name could be the rename command Changes the name of one file to another – mv [old file name] [new file name] Note, if [new file name] is a directory, you will move [old file name] to that directory and keep the original name
10
rm remove Deletes the specified file or files This is destructive! They are gone! They cannot be retrieved! – rm [file name] rm does not work with directories – unless the –r option is used
11
touch Touch creates an empty file – touch [file name] – If the file already exists, touch leaves it contents But it updates the time stamp of the file Used to – Test directory permissions – Create a sample file – Update the time stamp on an existing file
12
lpr print command (stands for “line printer”) This prints the file(s) you specify to the printer you specify – lpr [flags] [file name(s) to print] Flags: – -P: specifies the name of the printer to print to – -w[1-n]: specifies the number of pages to print per page – -h: removes the header page
13
lpq view print queue – lpq stands for “line printer query” When you print a file, it gets sent to a print queue (a line of files waiting to be printed) lpq will show you the names of the files in the print queue Use the -P flag just like in lpr to specify the printer whose queue you wish to view
14
lprm line printer remove Used to remove a file from the print queue Use the lpq to see the file and then use lprm [job number] to remove the specific job You can only remove print jobs that you sent to the printer Use the ‘-’ flag to remove all your files
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.