CS1101: Systems Organisation Basic File Manipulation II Lecture Overview CS1101: Lecture 5 Basic File Manipulation II
Dr. Barry O’Sullivan ¡ Basic File Manipulation Commands [email protected] – mkdir – rmdir
¡ Two More Abbreviations – ? – * – Example using Wildcards
¡ More Basic File Manipulation Commands – file Course Homepage – more http://www.cs.ucc.ie/˜osullb/cs1101 – cp – mv – rm – lpr
– lpq
¢ Department of Computer Science, University College Cork ¢ Department of Computer Science, University College Cork 1
CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II Basic File Manipulation Commands Making New Directories
Command Action ¡ The mkdir command creates directories; cd moves you to another directory
pwd tells you which directory you are in ¡ It syntax is: mkdir
file ¡ displays the type of a file Suppose your home-directory is /home/fred. more displays the contents of a file You want to create a directory there called cp copies a file/directory cs1101: mv moves a file/directory rm removes a file/directory wisdom.ucc.ie:%> cd lpr prints a file wisdom.ucc.ie:%> mkdir cs1101 lpq checks the printer status wisdom.ucc.ie:%>
Please note that UNIX is case-sensitive!!! ¡ Alternatively, you could simply use the absolute path without changing directories: wisdom.ucc.ie:%> mkdir /home/fred/cs1101 wisdom.ucc.ie:%>
¡ Alternatively, you could simply use the abbreviation
for your home-directory:
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 2 Department of Computer Science, University College Cork 3 CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II wisdom.ucc.ie:%> mkdir ˜/cs1101 wisdom.ucc.ie:%> Removing Directories
¡ rmdir does the opposite of mkdir – it removes directories;
¡ Its syntax is rmdir
¡ Example, to remove a directory called cs1101 in your home-directory you could issue the following command:
wisdom.ucc.ie:%> rmdir ˜/cs1101 wisdom.ucc.ie:%>
¡ Directories must be empty before they can be
deleted using this command.
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 4 Department of Computer Science, University College Cork 5
CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II What Files are in This Directory? Seeing Hidden Files
¡ The ls command tells you what files (and
directories) are in a directory. ¡ Files starting with . are hidden; ¡ The syntax of ls is ls
¡ Example: ¡ Example:
wisdom.ucc.ie:%> ls /var wisdom.ucc.ie:%> ls adm dt mail opt mail cs1101 letters audit log news preserve wisdom.ucc.ie:%> cron lp nis sadm wisdom.ucc.ie:%> ls -a wisdom.ucc.ie:%> . .. .cshrc mail cs1101 letters
¡ If you don’t specify a directory, ls lists the wisdom.ucc.ie:%> contents of the current directory:
wisdom.ucc.ie:%> ls mail cs1101 letters
wisdom.ucc.ie:%>
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 6 Department of Computer Science, University College Cork 7 CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II
Full Information on Files Two More Abbreviations: Wildcards ¡ ¡ ls -l (lowercase “L”) provides more information There are two wildcard characters: * and ? about your files – contents of the directory, who
owns a file, its size, when it was last modified, ¡ These can be used to describe a pattern for
etc file/directory names that you want to access; ¡ Example: ¡ * represents any number of characters in a file/directory name wisdom.ucc.ie:%> ls -l total 3 drwxr-x--- 6 osullb system 512 Oct 5 16:33 bin ¡ ? represents a single character in a -rw-r--r-- 1 osullb system 873 Feb 18 2000 iimb drwxr-x--- 2 osullb system 512 Aug 10 1999 nsmail file/directory name
wisdom.ucc.ie:%>
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 8 Department of Computer Science, University College Cork 9
CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II Examples: Wildcards What Sort of Files Are These?
¡ states is a directory containing files with ¡ names of US states: The file command tells you information about the “type” of a file
¡ Example 1: ¡ Its syntax is file
¡ Example 2: wisdom.ucc.ie:%> ls ˜/states/m*a wisdom.ucc.ie%> file mytextfile.txt minnesota montana mytextfile.txt: ascii text wisdom.ucc.ie:%> wisdom.ucc.ie%> wisdom.ucc.ie%> file myprogram
¡ Example 3: myprogram: Sun demand paged SPARC executable wisdom.ucc.ie:%> ls ˜/states/a?????a wisdom.ucc.ie%> arizona alabama wisdom.ucc.ie:%>
¡ Note Alaska wasn’t found!
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 10 Department of Computer Science, University College Cork 11 CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II
Viewing the contents of files Copying Files and Directories ¡ The more command displays the contents of ¡ The cp command is used; files:
¡ The syntax is: ¡ Its syntax is more
¡ After using cp both the
This is the second line of the file ¡ Examples: wisdom.ucc.ie%> cp georgia georgia.copy cp ˜/myletter ˜/myletter.2
cp ˜/myletter ˜/letters
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 12 Department of Computer Science, University College Cork 13
CS1101: Systems Organisation Basic File Manipulation II CS1101: Systems Organisation Basic File Manipulation II Moving Files and Directories Removing Files
¡ The rm command is used to remove files; ¡ The mv command is used;
¡ The syntax is: ¡ The syntax is: rm
mv
¡ After using mv the
exist any longer; rm myletter myletter2 myletter3 ¡ Examples: ¡ Once a file is removed, you cannot get it back!!! mv georgia ukraine mv ˜/myletter ˜/mynewletter ¡ Use the following version for prompts: mv ˜/myletter ˜/letters rm -i
¡ Directories can also be removed;
¢ ¢ ¢ ¢ Department of Computer Science, University College Cork 14 Department of Computer Science, University College Cork 15 CS1101: Systems Organisation Basic File Manipulation II Printing Files
¡ Use lpr to print out files;
¡ Syntax:
lpr
¡ This command can be used to print postscript files to a postscript-enabled printer;
¡ To print to a named printer:
lpr -P
¡ lpq tells you what jobs are on the printer;
¡ Usage:
lpq
lpq -P