Managing Files Flashcards
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
tar switches
- c create a new archive
- v verbose list of processed files
- f following is archive name
- z filter archive through gzip
tarball
files rolled up into one package
command cpio
copy files to and from archives
- cpio [options] archive
(i. e. find ./my-work | cpio -o | gzip > /media/archivename
cpio switches
- o create , copy out mode
- i extract, copy in mode
- p pass-through, combines copy-out and copy-in
command Dd
low level copying program to copy input device file to output file
- dd [options]
backs up entire partition including empty space, which means removed files still remaining on disk are copied (removing a file initially only removes pointer to that file)
dd switches
- if=inputFile
- of=outputFile
links
- links are like shortcuts, giving a file multiple identities
- hard links
- soft links (symbolic links)
command ln
manage links
syntax: ln [options] sourceFile linkName
ln switches
- f force remove any existing files that have the target link name
- i interactive prompt before replacing existing files and links
- s create symbolic link
command mkdir
syntax: mkdir [options] directoryName(s)
mkdir switches
- m mode causes new directory to have a specified permission expressed as an octal number
- p creates parent directories
rmdir
not as good as rm -r