Safety Switch -i

bs11bs11Safety first: the -i switch
• Prompt before overwriting or deleting files
• Use the-i switch
• “cp-i” and “mv-i” will ask you before overwriting files
• “rm -i” will ask before deletion
• Combine it with other options
• cp-Ri
□ rm -ri

Deleting files – rm

Deleting files
■ rm
• Warning: will delete files permanently.
• rm a
• rm a b c
• rm dir/a dir/b
• rm *
• rmdir
• Invocation like rm
• Will remove empty directories only
• rm -r
• Will recursively remove a directory and everything in it


Moving files – mv

Moving files
■ mv
• Warning: will silently overwrite existing files!
• Arguments: a source filename and a target filename
Command New file
mv a b ./b “rename”
mvadir/b dir/b
• Other form: one or more source filenames and a target directory
• Use it to move directories as well
mvabcdir dir/a, dir/b, dir/c
mv dir/a. ./a
mv* dir
Moves all files in current directory


Copy Files – CP


Example of copy command


Macbook-Air:demo reindertS Is -R alice Sherlock
alice.txt wonderland.jpg
holmes.jpg sherlock.txt
Macbook-Air:demo reindertS cp alice/alice.txt .
Macbook-Air:demo reindertS Is alice alice.txt sherlock
Macbook-Air:demo reindertS less alice.txt

Macbook-Air:demo reindertS cp alice/alice.txt book.txt

Macbook-Air:demo reindertS Is
alice alice.txt book.txt sherlock
Macbook-Air:demo reindertS cp ../Downloads/Emacs-24.3-universal-10.6.8.dmg .
Macbook-Air:demo reindertS Is
Emacs-24.3-universal-10.6.8.dmg book.txt
alice sherlock
Macbook-Air:demo reindertS cp alice.txt ../Downloads/^

About filenames with bash

About filenames
Filenames can contain just about anything
• Except/
• Hidden files start with a dot
Case sensitivity
• “hello” vs “Hello”
• Linux filenames are case sensitive
• Mac OS filenames are not
• But these are defaults: it depends on file system