Unformatted text preview:

File Management Commands• mkdir directory name – create a new directory• touch file name – create a new file with no content or touch an exisiting file• cd directory name – change directory to the one mentionedThe directory name can be relative to where you are or absolute. Suppose you are in thedirectory /home/nolan/stat133, and it contains a directory notes. The next three commandsall change the directory to /home/nolan/stat133/notes.–cd notes – The directory name is relative to the current directory–cd /home/nolan/stat133/notes – Here we have supplied the full pathname to find thedirectory–cd˜/stat133/notes – We use the symbol ˜ to refer to the user’s root directory, which inthis example is /home/nolan.–cd ../ – This relative change is to the directory above the current directory, i.e. to/home/nolan/stat133–cd ../stat205 – This relative change is to the directory at the same level of the tree asthe current directory i.e. /home/nolan/stat205– Typeset by FoilTEX – 1File Management Commands - Ctd• rmdir directory name – remove directory (it must be empty to be removed• pwd – gives you the name of the current (working) directory• cp file1 file2 – copy the first file to the second file• mv file1 file2 – rename (i.e. move) the first file to the second file name• rm filename – remove the file• ls – list the files and directories in the current directory• more filename – shows the contents of a file• tail filename – shows the last lines of a file– Typeset by FoilTEX – 2ExampleLet’s create a system of files and directories that matches the handout from Friday.> mkdir Test> cd TestTest> touch xTest> touch file1.texTest> mkdir ATest> mkdir A/BTest> cd ATest/A> touch file2.texTest/A> touch file3.csvTest/A> mkdir CTest/A> touch C/xTest/A> touch B/file4.docTest/A> touch B/file5.txtTest/A> mkdir B/DTest/A> touch B/D/xTest/A> touch B/D/x2– Typeset by FoilTEX – 3ls – list directory contentsFrom within the Test directory that we set up we see the directory A and the two files x andfile1.tex.> lsA myfile.tex xThe-R option say recurse your way through the tree of subdirectories excuting the lscommand as you go.> ls -R.:A file1.tex x./A:B C file2.tex file3.csv./A/B:D file4.doc file5.txt./A/B/D:x x2./A/C:x– Typeset by FoilTEX – 4Help for commandsman ls – the online manual pages for the ls commandls - -help – abbreviated help on the various options to the ls command.Usage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by default).Sort entries alphabetically if none of -cftuSUX nor --sort.Mandatory arguments to long options are mandatory for short options too.-a, --all do not hide entries starting with .-A, --almost-all do not list implied . and ..--author print the author of each file-b, --escape print octal escapes for nongraphic characters--block-size=SIZE use SIZE-byte blocks-B, --ignore-backups do not list implied entries ending with ˜-c with -lt: sort by, and show, ctime (time of last-C list entries by columns--color[=WHEN] control whether color is used to distinguish file-d, --directory list directory entries instead of contents,-D, --dired generate output designed for Emacs’ dired mode-f do not sort, enable -aU, disable -lst-F, --classify append indicator (one of */=@|) to entries...– Typeset by FoilTEX – 5* – the wild cardThe * symbol matches any number of characters (except the /). It can be quite handy whenlooking for files that have particular type.Below we list only those files with the filetype extension of tex in the subdirectory A:> ls A/*.texA/report.tex> ls -R *.texls: No match.Can you explain why the second command does not find any files with the filetype tex?– Typeset by FoilTEX – 6Piping |We can construct more complex shell commands by piping or sending the output from onecomand to the input of another. Below we pipe the output from thels command to the wccomand.> ls -R | wc33 29 140wc – short for word count, returns the number of newlines, words, and bytes in the input file.Does this mean that there are 33 files in the Example directory?– Typeset by FoilTEX – 7find – search for files in a directory hierarchyThe find command may be better suited to the previous task.> find -name ’*.tex’./A/report.texWe can also do fancier finds, such as all tex files in my home area that have been modifiedwithin the past 21 days.> find /home/nolan/ -mtime +21 -name ’*.tex’ | wc -l2421Or, we can find all those files that do not end with .tex in the working directory.> find . -type f -not -name ’*.tex’– Typeset by FoilTEX – 8grep – print lines matching a patternWith grep we can search for patterns within a file. The syntax isgrep [options] PATTERN [FILE...].Suppose we want to find all files that have the words ”data frame” in them.> grep -lR ’data frame’ *DataTypes/DataTypes.texDataTypes/Assignment.texDataTypes/Lists.texIntroduction/introduction.texShellCmds/.ShellCmds.tex.swpTraffic/traffic.texschedule– Typeset by FoilTEX – 9grep continuedTo invert the match we can use the -v option to the grep command.> grep -lRv ’data frame’ * | moreDataTypes/DataTypes.texDataTypes/htmlPDF.pdfDataTypes/DataTypes.logDataTypes/DataTypes.auxDataTypes/DataTypes.pdfDataTypes/pdfFiles.tex...DataTypes/ExampleLatex2.logDataTypes/ExampleLatex2.auxDataTypes/ExampleLatex2.pdf--More--Here themore command formats the output being sent to the console so that you see onepage at a time, rather than have the whole output go whizzing past.To proceed to the next page of output hit the space bar.To stop displaying the output hitq– Typeset by FoilTEX – 10Other useful aspects of the Shell commands• > and >> – redirectionAt times we want to save the output from a command to a file. We can do this by redirectingthe output to a file. We use the single> to direct the output to a new file (it will alsooverwrite an existing file), and we use the double>> if we want to add the output to anexisting file.• chmod – change permissions on files and directories.In Unix we can define groups of users, such as all student accounts for Stat133, or allfaculty accounts, or all graduate studnet accounts. Thechmod command allows us to setspecific permissions for the owner of the file, the group that the owner belongs to, and forall other accounts. The-l option on the ls command provides the permissions.Test> ls -ltotal 4drwxr-xr-x 4 nolan nolan 4096 Sep 19 11:54


View Full Document
Download File Management Commands
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view File Management Commands and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view File Management Commands 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?