27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

bash$ mv source_directory target_directory<br />

bash$ ls −lF target_directory<br />

total 1<br />

drwxrwxr−x 2 bozo bozo 1024 May 28 19:20 source_directory/<br />

rm<br />

Delete (remove) a file or files. The −f option forces removal of even readonly files, and is useful for<br />

bypassing user input in a script.<br />

rmdir<br />

mkdir<br />

chmod<br />

When used with the recursive flag −r, this command removes files all the way down<br />

the directory tree.<br />

Remove directory. The directory must be empty of all files, including invisible "dotfiles", [28] for this<br />

command to succeed.<br />

Make directory, creates a new directory. mkdir −p project/programs/December creates<br />

the named directory. The −p option automatically creates any necessary parent directories.<br />

Changes the attributes of an existing file (see Example 11−10).<br />

chmod +x filename<br />

# Makes "filename" executable for all users.<br />

chmod u+s filename<br />

# Sets "suid" bit on "filename" permissions.<br />

# An ordinary user may execute "filename" with same privileges as the file's owner.<br />

# (This does not apply to shell scripts.)<br />

chmod 644 filename<br />

# Makes "filename" readable/writable to owner, readable to<br />

# others<br />

# (octal mode).<br />

chattr<br />

ln<br />

chmod 1777 directory−name<br />

# Gives everyone read, write, and execute permission in directory,<br />

# however also sets the "sticky bit".<br />

# This means that only the owner of the directory,<br />

# owner of the file, and, of course, root<br />

# can delete any particular file in that directory.<br />

Change file attributes. This has the same effect as chmod above, but with a different invocation<br />

syntax, and it works only on an ext2 filesystem.<br />

Creates links to pre−existings files. Most often used with the −s, symbolic or "soft" link flag. This<br />

permits referencing the linked file by more than one name and is a superior alternative to aliasing (see<br />

Example 4−6).<br />

ln −s oldfile newfile links the previously existing oldfile to the newly created link,<br />

newfile.<br />

man, info<br />

These commands access the manual and information pages on system commands and installed<br />

utilities. When available, the info pages usually contain a more detailed description than do the man<br />

pages.<br />

Chapter 12. External Filters, Programs and Commands 150

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!