<<

Review

Commands generally have three Options/Flags parts: command_name [options] [operands]

Review Examples • So far we have discussed command_names and [operands] $ ls temp

• Now we will go through some of the $ cp test1 test2 available for the [options] command_names $ mv pict /home/jsmith/family_pics • All commands have default settings and [options] modify the default behavior of $ grep 'Sally Smith' * these commands. $ diff poem1 poem2

• Note: [options] are also called ‘flags’

Examples

$ ls -l temp $ cp -r test1 test2 ls $ mv -i pict /home/jsmith/family_pics

$ grep -i 'Sally Smith' * -a $ diff - poem1 poem2 -l -p -t

1 ls -a ls -a

“all” • Example: $ ls dir2 • ls -a will list all files address_list final.paper picts cats .txt • Just typing ls will not list entries whose names begin with a period (.) “hidden files”

ls -a ls -l

• Example: “long format” $ ls -a dir2 . .DS_Store cats history.txt • ls -l will list files in long format .. address_list final.paper picts

• The . stands for the itself, and • This will give information about each , the .. stands for the parent directory. such as has permission to read it, These files are created with the when it was made, how large it is, etc. command. (we will cover of this later in class).

ls -l ls -p

• ls -p puts a slash (/) after each • Example: filename if the of file is a directory. $ ls -l dir2 • Remember that in UNIX, everything is a -rw-r--r-- 1 name name 455 Jun 30 22:33 address_list file. Some are regular files and some are drwxrwxr-x 5 name name 512 Jun 30 22:33 cats directory files. There are several other -rw-r--r-- 1 name name 716 Jun 30 22:33 final.paper types of files in UNIX (i.e. devices, links, -rw-r--r-- 1 name name 7091 Jun 30 22:33 history.txt etc.) but all you need to know is how to drwxrwxr-x 2 name name 512 Jun 30 22:33 picts differentiate between regular files and directories.

2 ls -p ls -t

” • Example: $ ls -p dir2 • ls -t will list the files and directories, address_list final.paper picts/ sorted by time modified ( recently cats/ history.txt modified first).

Combining Options ls Practice

• Options can easily be combined.

• If you want to list all files in long format: • What in UNIX_class has been changed most recently? Is it a file or a directory? $ ls -al • This would also give you information $ ls -tp about the current directory and the Poems/ parent directory, because the . and .. are listed with the -a.

ls Practice ls Practice

 How many files and directories are in  List dir2 in long format. Two entries dir2, including hidden files? begin with a ‘d’ - why do you think this is?

$ ls -a $ ls -l . .DS_Store cats history.txt (they are directories) .. address_list final.paper picts

(8 files and directories)

3 cp -i

“interactive”

c p • When you are copying a file or directory, when using cp -i, the -i system will ask you before you -r overwrite a copied file over an existing file.

cp -r cp Practice

“recursive” • Copy dir2, using cp -r. Name the • cp -r specifies that when you copy a new directory dir3. directory, you also copy all the • Verify the files copied as well. subdirectories and files within that directory. $ .. (in UNIX_class) $ cp -r dir2 dir3 $ ls -p $ ls dir3

mv -i

“interactive”

m • When you are moving a file or directory, when using mv -i, the -i system will ask you before you overwrite a moved file over an existing file.

4 rm -i

“interactive”

r m • When you are removing a file or directory, when using rm -i (or -i -i), the system will ask you -r before you delete any file. • The -i option in cp, mv and rm are safety features for you.

rm -r rm Practice

“recursive”  Delete the directory Poems - deleting • Using rm -r will remove a directory all the sonnets the same time. AND all the files and subdirectories within it! $ (verify you are in UNIX_class) (Needless to say, this can be a very $ rm -r Poems bad thing if done accidentally) $ ls

grep -i

“ignore case” grep • grep -i will search and give all results that match, regardless if they -i are in upper or lower case. -l

5 grep -l grep Practice

“list filename” • What file is the string 'ford prefect' in? • grep -l will just list the name of the (in dir2) file that the search string was found in, $ grep -il 'ford prefect' * instead of the entire line. address_list

diff -i

“ignore case” diff • diff -i will ignore differences in upper and lower case between files. -i -w

diff -i diff -w

• Compare the files sonnet1 and “ignore white” sonnet3, first without -i, and then with the flag. • diff -w will ignore spaces and tabs $ cd ../Shakespeare when comparing files. $ diff sonnet1 sonnet3 $ diff -i sonnet1 sonnet3

6 diff -w More Flags & Options

• Compare the files sonnet2 and sonnet5, first without -w, and then with • Check man for a list of available flags the flag. with each command_name. $ diff sonnet2 sonnet5 • These options will differ slightly with different versions of UNIX. $ diff -w sonnet2 sonnet5

The End…

• Next…

Even More Commands

7