Managing Files Flashcards
(91 cards)
basic skills for managing files
- create
- delete
- move
- rename
- archive
- manipulate via scripts
Restrict non-alphanumeric characters in file naming to…
_
Special use characters for filenames
* ? / \ " `
True or False: Linux filenames are case-insensitive
False
Special filenames
- single dot (.) refers to current directory
- double dot (..) refers to parent directory
wildcard ?
stands for a single character
wildcard *
matches zero or more characters
wildcard []
match any character in the set of characters within the square brackets
wildcard range
match any character within the range
i.e. b[a-z]ck matches back, buck, and other four letter names
common file manipulation commands
- ls
- cp
- mv
- rm
- touch
command ls
syntax: ls [OPTION]… [FILE]…
- displays the names of files in a directory
ls switches
- a displays all files including dot files
- -color produces color-coded listing differentiating directories, symbolic links, files, and more
- d lists only directory name
- l long listing including information such as the file’s permission string owner, group, size, and creation date
- f appends an indicator code to end of each name to display type of file
- r displays sub-contents recursively
command cp
- copies and with wildcards
syntax: cp [OPTION]… SOURCE… DIRECTORY
cp switches
- a archive option similar to -R but preserves ownership and copies links
- f force without prompting
- i prompt before overwrite
- p preserves ownership and permissions if possible
- r copy directories recursively
- u copy only when the SOURCE file is newer than the destination file or when the destination file is missing
command mv
move - commonly used to move files and directories from one location to another or to rename them
syntax: mv [OPTION]… SOURCE… DIRECTORY
mv switches
- b back up destination file like –backup but does not accept an argument
- f do not prompt before overwriting
- i prompt before overwrite
- n do not overwrite an existing file
options which do not apply to mv
- -preserve
- -recursive
- -archive
best practice for mv command
use trailing slash (/) to avoid typos like renaming a file instead of moving to a directory
(i.e.
mv document.doc important/purchases/ moves to directory
mv document.doc important/puchases renames to purchases)
command rm
remove
syntax: rm {options] files
rm switches
- r recursive, will remove each listed directory along with contents
- d remove empty directories
- f force no prompt
note: by default rm does not remove directories.
command touch
set modification and access time to current time
syntax: touch [options] files
touch switches
- a access time
- m modification time
- c do not create file
- t specify a timestamp
common file archiving commands
- tar
- cpio
- Dd
command tar
- tape archiver
- tar [options] Archive File
(i. e. tar cvfz /media/document.tgz /my_archive) - without z, no compression