Manipulating Files ORAFACT Directory Manipulation Standard manipulation commands

  • Slides: 14
Download presentation
Manipulating Files ORAFACT

Manipulating Files ORAFACT

Directory Manipulation Standard manipulation commands • mkdir - creates directories mkdir [options] directory [.

Directory Manipulation Standard manipulation commands • mkdir - creates directories mkdir [options] directory [. . . ] -m set permission mode -p make parent directories as needed -v print a message for each created directory • rmdir - deletes empty directories rmdir [options] directory_name [. . . ] -p allows the removal of empty parent directories ORAFACT

File Manipulation Standard manipulation commands • cp - copies files and directories cp [options]

File Manipulation Standard manipulation commands • cp - copies files and directories cp [options] source destination cp [options] source 1 source 2 [. . . ] destination_directory -a archive, never follow symbolic links, preserve links, copy directories recursively -f if an existing destination file cannot be opened, remove it and try again -I prompt before overwriting an existing file -r copy directories recursively • mv - moves or renames files and directories mv [options] source destination mv [options] source 1 source 2 [. . . ] destination -f do not prompt before overwriting -i prompt before overwrite -u move only when the source file is newer than the destination file or when the destination file is missing ORAFACT

Deleting and Creating Files rm - removes (deletes) files and directories rm [options] file

Deleting and Creating Files rm - removes (deletes) files and directories rm [options] file [. . . ] -f ignore nonexistent files, never prompt -i prompt before any removal -r | -R remove the contents of directories recursively touch - creates empty files or updates mtime and atime on existing files touch [options] file [. . . ] -a change only the access time -m change only the modification time -t set a specific time ORAFACT

Physical Unix File Structure Block and inode based • blocks hold data • inodes

Physical Unix File Structure Block and inode based • blocks hold data • inodes hold metadata permissions on the file access, modification, and creation times for the file owner of the file size in bytes of the file blocks occupied by the file link count, a number specifying how many names the inode has inode number, a unique number identifying that inode. (Note that inode numbers are unique per filesystem, and not globally) ORAFACT

Filesystem Links Created with ln Hard links - a entry that references the same

Filesystem Links Created with ln Hard links - a entry that references the same inode as another entry $ ln /usr/share/originalfile /home/foo/hardlink • can't span filesystems • can't create hard links to non-existent file • can't reference directories • do not occupy storage space (i. e. blocks) Symbolic links - a file that references another file via path and name $ ln -s /usr/local/originalfile /home/foo/symlink • can reference directories • can span filesystems • can reference non-existent files • occupy space ORAFACT

File Extensions and Content File extensions have no special meaning to the kernel •

File Extensions and Content File extensions have no special meaning to the kernel • file extensions are just part of the file name • the kernel only distinguishes between executable and non-executable (data) files • some applications may care about extensions Apache, file managers like Midnight Commander The file command reports the type of file by examining the file contents ORAFACT

Displaying Files cat - displays entire file(s) more - displays file(s) one screen at

Displaying Files cat - displays entire file(s) more - displays file(s) one screen at a time less - more sophisticated and configurable pager ORAFACT

Previewing Files head - displays first 10 (by default) lines of file tail -

Previewing Files head - displays first 10 (by default) lines of file tail - displays last 10 (by default) lines of file • tail -f to watch a file be appended to Use the -n option to configure how many lines to view ORAFACT

Displaying Binary Files Displaying raw binary data may corrupt the display terminal • reset

Displaying Binary Files Displaying raw binary data may corrupt the display terminal • reset corrects terminal • reset (if carriage-return fails) strings - displays ASCII text inside binary files xxd - displays HEX and ASCII dump of file ORAFACT

Searching the Filesystem find - searches a directory structure for requested files find path

Searching the Filesystem find - searches a directory structure for requested files find path [. . . ] [expression] • First argument(s) are path(s) to start search from; default is current directory • Next arguments specify criteria to search on: file name, size, permissions, type, owner, group, atime, mtime, ctime • Last argument specifies action to perform. -print is the default action and displays matches -ls displays full details on matches -exec allows a command to be run against each matching file. The -ok can be used when a confirmation prompt is desired Examples: 1. search in the /home/ directory for all the regular files ending in. jpg and owned by the user john: # find /home/ -name ‘*. jpg’ -type f -user john 2. Change ownership of all files owned by bob to alice. # find / -user bob -exec chown alice {} ; ORAFACT

Searching the Filesystem 3. Long listing of all files in the current directory and

Searching the Filesystem 3. Long listing of all files in the current directory and down that have changed in the last 30 minutes: $ find. -mmin -30 –ls 4. List of all files in the /data/ directory and down that were created more than 20 days ago: # find /data/ -ctime +20 5. List all empty files and directories owned by the foo group: # find / -empty -group foo 6. Long listing of all files and directories that have any special permission bits set: # find / -perm +7000 –ls 7. List all files in /home/ that are between two and five Kbytes in size: # find /home/ -type f -size +2 k -size -5 k ORAFACT

Alternate Search Method locate - High-speed and low-impact searching • Searches index instead of

Alternate Search Method locate - High-speed and low-impact searching • Searches index instead of actual filesystem • Index updated each night by default • locate won't know about recently added/deleted files until database is rebuilt • Search criteria limited to pattern matching in the pathname and Filename slocate: Secure locate (slocate) is secure in that it stores files' permissions in its database, and therefore will not locate files for users who do not have the right to see them. Building the locate Database # /etc/cron. daily/mlocate. cron locate Packages To use the locate command the proper RPM package (findutils) must be installed. The slocate package is installed by default on Oracle Enterprise Linux. ORAFACT

Producing File Statistics wc - Counts lines, words and characters in text files wc

Producing File Statistics wc - Counts lines, words and characters in text files wc [options] [filename] [. . . ] -c character count only -w word count only -l line count only -L print the length of the longest line • when given multiple files as arguments, produces totals for each file as well as an overall total • can be told to only output total for lines or words or characters • most common usage is to count lines ORAFACT