# LPI Linux Certification/Perform Basic File Management
## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 4
Description: Candidates should be able to use basic Linux commands to manage files and directories.
Key Knowledge Areas:
* Copy, move and remove files and directories individually.
* Copy multiple files and directories recursively.
* Remove files and directories recursively.
* Use simple and advanced wildcard specifications in commands.
* Use find to locate and act on files based on type, size, or time.
* Usage of tar, cpio and dd.
The following is a partial list of the used files, terms and utilities:
* cp
* find
* mkdir
* mv
* ls
* rm
* rmdir
* touch
* tar
* cpio
* dd
* file
* gzip
* gunzip
* bzip2
* xz
* unxz
* file globbing

## Create and Remove directories

To create a directory, use mkdir.
Common options:
Examples:
To delete an empty directory, use rmdir.
Common options:
Examples:

## Copy files and directories

To copy one file to another, or to a directory, use cp.
Source and target can be a file or a directory.
Common options:
The default is to silently clobber the target file. (This does not alter the source.
Examples:

## Move & Rename files

To rename a file or directory or to move a file or directory to another location, use mv.
Source and target can be a file or a directory.
Common options:
The default is to silently clobber the target file.
Examples:

## Listing filenames and information

The command to list files in the current directory is ls.
Common options are:
The ls is equivalent to the dir command on DOS.
Examples of ls output:

## File types

The long format means:
File content and location Linux/Unix does not distinguish file by filename extension, like Windows. To determine the file content use file.
To determine if a command is a built-in shell command or a program, use type, and use which to find its location.

## Creating and using filenames

Filenames can be created with:
* I/O redirection
* An editor, such as vi.
* Many of the Unix utilities
* An application
* The touch command, which creates empty files (or updates the "date modified" of existing files)
The valid filename may have (or be):
* Maximum 255 characters per filename
* Any character except forward '/'
* Recommended alphanumeric characters as well as plus, minus, and underscore characters.
* Case sensitive ('A' and 'a' are treated differently)
Characters to avoid
* Hyphen character.
* White space.
* Most other special characters !@#$%^&*:;"'}{|\<,>.?~`

## Remove files or directories

To remove files or subtree directories, use rm.
Files can be a file or a directory.
Common options:
There is no 'unremove' or 'undelete' command.
Examples:

## Locating files in a subtree directory

To search for a file in a subtree directory, use find.
The command can take multiple conditions and will search recursively in the subtree.
Some possible conditions are:
Some possible actions are:
Examples:
To locate a binary, source file, or man page, use whereis.
Common options:
Examples:
To locate a file located somewhere defined by the PATH variable, use which.
The -a will look for all possible matches in PATH, not just for the first one.

## Exercises

* Compose an interactive command to remove all .tmp files in your home directory. Respond y to every prompt.
* List all the files in the user's home directories ending with .pdf that are bigger than 50 blocks and have not been accessed for a month.
* Create a file file.h that will contain all the filenames ending with .h found in the /usr directory.
* Do a touch on all the c files found in /usr/src/packages directory.
* What are the default permissions when you create a new file and a new directory?
* How would you create a new file or directory that contains a space in the filename? (Example: 'new dir')
* What is the command to remove all the files of types char and block in your home directory?
* How would you find the location of the program find?
* Delete all files in /tmp which are not owned by root and have not been accessed for a week.
* Exercises results