Mapa mental
103.3 Perform basic file management
Contenido del mapa
103.3 Perform basic file management
How to Find Files
- find STARTING_PATH OPTIONS EXPRESSION
- find . -name "myfile.txt"
- find /home/frank -name "*.png"
- Using Criteria to Speed Search with find
- -type f archivo plano -type d archivo directorio -type l archivo link
- find . -type d -name "example"
- criterio
- -name
- -iname
- -not
- -maxdepth N
- -type f archivo plano -type d archivo directorio -type l archivo link
- Locating Files by Modification Time
- sudo find / -name "*.conf" -mtime 7
- Locating Files by Size
- sudo find /var -size +2G
- -size 100b
- -size +100k
- -size -20M
- -size +2G
- -size -20M
- -size +100k
- -size 100b
- sudo find /var -size +2G
- find STARTING_PATH OPTIONS EXPRESSION
Acting on the Result Set
- find . -name "*.conf" -exec chmod 644 '{}' \;
Using grep to Filter for Files Based on Content
- find . -type f -exec grep "lpi" '{}' \; -print
- find . -name "*.bak" -delete
- find . -type f -exec grep "lpi" '{}' \; -print
Archiving Files
- The tar Command (Archiving and Compresssion)
- --create (-c)
- --extract (-x)
- --list (-t)
- --verbose (-v)
- --file=archive=name (-f archive-name)
- The tar Command (Archiving and Compresssion)
tar -cvf archive.tar stuff
- -c Create an archive.
- -v Display progress
- -f Allows to specify the filename of the archive.
tar -cvf NAME-OF-ARCHIVE.tar /PATH/TO/DIRECTORY-OR-FILE
- tar -cvf archive.tar stuff1 stuff2
- tar -xvf archive.tar
- tar -xvf archive.tar -C /tmp
Compressing with tar
- tar -czvf name-of-archive.tar.gz stuff
- tar -cjvf name-of-archive.tar.bz stuff
- tar -xzvf archive.tar.gz
gzip FILE-TO-COMPRESS
- gzip
- gunzip
- bzip2
- bunzip2
- gzip
The cpio Command
- ls | cpio -o > archive.cpio
- cpio -id < archive.cpio
The dd Command
- dd if=oldfile of=newfile
- dd if=oldfile of=newfile conv=ucase
- dd if=/dev/sda of=backup.dd bs=4096
Guided Exercises
- find /home/frank/Documents/ -type d
- tar cvzf /home/frank/backup.tar.gz /home/frank/dir1
- find /var -name *.backup
- find /var -name *.backup -size +100M -size -1000M
- find /var -name *.backup -size +100M -size -1000M -delete
- tar -cvf db-first-quarter-2018.backup.tar db-jan-2018.backup db-feb-2018.backup db-march-2018.backup db-apr-2018.backup
- tar -zcvf db-first-quarter-2018.backup.tar.gz db-jan-2018.backup db-feb-2018.backup db-march-2018.backup db-apr-2018.backup
Find Criteria
- -daystart
- -amin, -atime, -cmin, -ctime, -mmin, and -mtime
- -amin n
- File was last accessed n minutes ago.
- +n for greater than n
- -n for less than n
- n for exactly n.
- -atime n
- File was last accessed n*24 hours ago
- -cmin n
- File's status was last changed n minutes ago
- -ctime n
- File's status was last changed n*24 hours ago
- -a : accesado -c:change, -m:modified
- -amin n
- -amin, -atime, -cmin, -ctime, -mmin, and -mtime
- -daystart
Exampes find
- find /tmp -name core -type f -print | xargs /bin/rm -f
- los nombres que contienen comillas simples o dobles, espacios o nuevas líneas no se manejan correctamente
- find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
- los nombres que contienen comillas simples o dobles, espacios o nuevas líneas se manejan correctamente
- -printf0
- Le dice a find que imprima todos los resultados en std, cada uno separado con el carácter ASCII NUL "\ 000"
- -printf0
- xargs -0 Le dice a xargs que la entrada se separará con el carácter ASCII NUL "\ 000"
- los nombres que contienen comillas simples o dobles, espacios o nuevas líneas se manejan correctamente
- find . -type f -exec file '{}' \;
- find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \ \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
- find $HOME -mtime 0
- find /sbin /usr/sbin -executable \! -readable -print
- find . -perm 664
- find . -perm -664
- find . -perm /222
- find . -perm -664
- find . -perm /220 find . -perm /u+w,g+w find . -perm /u=w,g=w
- find . -perm -220 find . -perm -g+w,u+w
- find . -perm -444 -perm /222 \! -perm /111 find . -perm -a+r -perm /a+w \! -perm /a+x
- find -type d -fprint allDirs -o -type f -fprint allFiles
- sudo find . -name \*.php -type f -exec grep -Hn '$test' {} \;
- find . -name \*.php -type f -exec grep -Hn '$test' {} \+
- find . -name \*.php -type f -print0 | xargs -0 -n1 grep -Hn '$test'
- find . -name \*.php -type f -print0 | xargs -0 grep -Hn '$test'
- Si no se especifica -n [int], xargs usa el valor predeterminado de -n5000
- time find . -name \*.php -type f -exec grep -Hn '$test' {} \
- time: determine tiempo de ejecucion
- time find . -name \*.php -type f -exec grep -Hn '$test' {} \+
- time find . -name \*.php -type f -print0 | xargs -0 -n1 grep -Hn '$test'
- time find . -name \*.php -type f -print0 | xargs -0 -grep -Hn '$test'
- time find . -name \*.php -type f -print0 | xargs -0 -n1 grep -Hn '$test'
- -n1 Le dice a xarg que ejecute el comando [cmd] con un solo argumento (en este caso, solo se encuentra un archivo mediante la búsqueda).
- find . -name \*.php -type f -print0 | xargs -0 grep -Hn '$test'
- find . -name \*.php -type f -print0 | xargs -0 -n1 grep -Hn '$test'
- find . -name \*.php -type f -exec grep -Hn '$test' {} \+
- find . -name \*.log -mtime +30 | xargs -n 500 rm
- find . -name \*.log -mtime +30 -print0 | xargs -0 -n 500 rm
- eliminar 1.2 millones de archivos en un directorio de más de 30 días
- find . -name \*.log -mtime +30 -print0 | xargs -0 -n 500 rm
- find . -maxdepth 1 -type f -name "*.txt" -size 1205c -print0 | xargs -0 ls -l
- find . -maxdepth 1 -type f -name "*.txt" -size 1205G -print0 | xargs -0 ls -l
- find /tmp -name core -type f -print | xargs /bin/rm -f
Información
- Descripción
- 103.3 Perform basic file management
- Creado por
- Rolando Martinez
- Visitas
- 13
- Etiquetas
- Valoración