SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
RedHat Enterprise Linux Essential
  Unit 12: Finding and Processing Files
Objectives

Upon completion of this unit, you should be able to:

 Use locate

 Use find

 Use the Gnome Search tool
locate

 Queries a pre-built database of paths to files on the system

    Database must be updated by administrator

    Full path is searched, not just filename


 May only search directories where the user has read and

  execute permission
       locate –help
       head /var/lib/mlocate/mlocate.db
       cat /etc/updatedb.conf
       cat /etc/cron.daily/mlocate.cron
locate Examples

 locate foo
    Search for files with "foo" in the name or path

 locate -r '.foo$‘
    Regex search for files ending in ".foo"

 Useful options
    -i performs a case-insensitive search

    -n X lists only the first X matches
find

 find [directory...] [criteria...]

 Searches directory trees in real-time
    Slower but more accurate than locate

    CWD is used if no starting directory given

    All files are matched if no criteria given

 Can execute commands on found files

 May only search directories where the user has read and
  execute permission
Basic find Examples


 find -name snow.png
   Search for files named snow.png

 find -iname snow.png
   Case-insensitive search for files named snow.png, Snow.png,
    SNOW.PNG, etc

 find -user vmintam -group vmintam
   Search for files owned by the user vmintam and the group vmintam

  Ex: find / -name “*.txt” ; find / -name “.*D.*.txt”

    find / -name “W.*.txt”
find and Logical Operators

 Criteria are ANDed together by default.

 Can be OR'd or negated with -o and -not

 Parentheses can be used to determine logic order, but must be
  escaped in bash.
    find -user vmintam -not -group root

    find -user vmintam -o -user root

    find -not ( -user vmintam -o -user root )
find and Permissions

 Can match ownership by name or id
    find / -user joe -o -uid 500

 Can match octal or symbolic permissions

    find -perm 755            matches if mode is exactly 755

    find -perm +222           matches if anyone can write

    find -perm -222           matches if everyone can write

    find -perm -002           matches if other can write
find and Numeric Criteria

 Many find criteria take numeric values

 find -size 1024k

    Files with a size of exactly 1 megabyte

 find -size +1024k
    Files with a size over 1 megabyte

 find -size -1024k

    Files with a size less than 1 megabyte
find and Access Times

 find can match by inode timestamps
    -atime when file was last read

    -mtime when file data last changed

    -ctime when file data or metadata last changed

 Value given is in days

  find -ctime -10
    Files modified less than 10 days ago
   find / -atime 5;
   find / -atime +5;
   find / -atime -5;
   find / -anewer example.txt   ; try with –cnewer and -newer
Executing Commands with find

 Commands can be executed on found files
    Command must be preceded with -exec or -ok
       • -ok prompts before acting on each file

    Command must end with Space;

    Can use {} as a filename placeholder

    find -size +102400k -ok gzip {} ;

    find -size +100M -exec tar -cvzf /tmp/test.tar.gz {} ;
find Execution Examples

 find -name "*.conf" -exec cp {} {}.orig ;

    Back up configuration files, adding a .orig extension

 find /tmp -ctime +3 -user joe -ok rm {} ;

    Prompt to remove Joe's tmp files that are over 3 days old

 find ~ -type f -exec chmod 644 {} ;

 find ~ -type d -exec chmod 755 {} ;
Unit 12 finding and processing files

Contenu connexe

Tendances

Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
Faisal Aziz
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
ankitamakin
 

Tendances (20)

Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
Operator Overloading In Python
Operator Overloading In PythonOperator Overloading In Python
Operator Overloading In Python
 
Advance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptxAdvance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptx
 
Primitive data types
Primitive data typesPrimitive data types
Primitive data types
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
tmux
tmuxtmux
tmux
 
Unicode
UnicodeUnicode
Unicode
 
Python
PythonPython
Python
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
sl slides-unit-1.pptx
sl slides-unit-1.pptxsl slides-unit-1.pptx
sl slides-unit-1.pptx
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computing
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 

En vedette

Unit 6 bash shell
Unit 6 bash shellUnit 6 bash shell
Unit 6 bash shell
root_fibo
 
Unit 4 user and group
Unit 4 user and groupUnit 4 user and group
Unit 4 user and group
root_fibo
 
Unit 13 network client
Unit 13 network clientUnit 13 network client
Unit 13 network client
root_fibo
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
root_fibo
 
Unit 9 basic system configuration tools
Unit 9 basic system configuration toolsUnit 9 basic system configuration tools
Unit 9 basic system configuration tools
root_fibo
 
Administration 1 sw2012
Administration 1 sw2012Administration 1 sw2012
Administration 1 sw2012
Lin Liyue
 

En vedette (7)

Unit2 help
Unit2 helpUnit2 help
Unit2 help
 
Unit 6 bash shell
Unit 6 bash shellUnit 6 bash shell
Unit 6 bash shell
 
Unit 4 user and group
Unit 4 user and groupUnit 4 user and group
Unit 4 user and group
 
Unit 13 network client
Unit 13 network clientUnit 13 network client
Unit 13 network client
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
 
Unit 9 basic system configuration tools
Unit 9 basic system configuration toolsUnit 9 basic system configuration tools
Unit 9 basic system configuration tools
 
Administration 1 sw2012
Administration 1 sw2012Administration 1 sw2012
Administration 1 sw2012
 

Similaire à Unit 12 finding and processing files

101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
Acácio Oliveira
 

Similaire à Unit 12 finding and processing files (20)

Find and locate
Find and locateFind and locate
Find and locate
 
Find and Locate: Two Commands
Find and Locate: Two CommandsFind and Locate: Two Commands
Find and Locate: Two Commands
 
10 finding files
10 finding files10 finding files
10 finding files
 
Unix Basics Commands
Unix Basics CommandsUnix Basics Commands
Unix Basics Commands
 
Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files
 
Common linux ubuntu commands overview
Common linux  ubuntu commands overviewCommon linux  ubuntu commands overview
Common linux ubuntu commands overview
 
File systems and inodes
File systems and inodesFile systems and inodes
File systems and inodes
 
14.Linux Command
14.Linux Command14.Linux Command
14.Linux Command
 
3.1.a linux commands reference
3.1.a linux commands reference3.1.a linux commands reference
3.1.a linux commands reference
 
Command Line Tools
Command Line ToolsCommand Line Tools
Command Line Tools
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
 
Productivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsProductivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformatics
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Basic linux commands
Basic linux commands Basic linux commands
Basic linux commands
 
Unix for Librarians
Unix for LibrariansUnix for Librarians
Unix for Librarians
 
The Linux Command Cheat Sheet
The Linux Command Cheat SheetThe Linux Command Cheat Sheet
The Linux Command Cheat Sheet
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Linux fundamental - Chap 03 file
Linux fundamental - Chap 03 fileLinux fundamental - Chap 03 file
Linux fundamental - Chap 03 file
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Linux command line
Linux command lineLinux command line
Linux command line
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Unit 12 finding and processing files

  • 1. RedHat Enterprise Linux Essential Unit 12: Finding and Processing Files
  • 2. Objectives Upon completion of this unit, you should be able to:  Use locate  Use find  Use the Gnome Search tool
  • 3. locate  Queries a pre-built database of paths to files on the system  Database must be updated by administrator  Full path is searched, not just filename  May only search directories where the user has read and execute permission locate –help head /var/lib/mlocate/mlocate.db cat /etc/updatedb.conf cat /etc/cron.daily/mlocate.cron
  • 4. locate Examples  locate foo  Search for files with "foo" in the name or path  locate -r '.foo$‘  Regex search for files ending in ".foo"  Useful options  -i performs a case-insensitive search  -n X lists only the first X matches
  • 5. find  find [directory...] [criteria...]  Searches directory trees in real-time  Slower but more accurate than locate  CWD is used if no starting directory given  All files are matched if no criteria given  Can execute commands on found files  May only search directories where the user has read and execute permission
  • 6. Basic find Examples  find -name snow.png  Search for files named snow.png  find -iname snow.png  Case-insensitive search for files named snow.png, Snow.png, SNOW.PNG, etc  find -user vmintam -group vmintam  Search for files owned by the user vmintam and the group vmintam Ex: find / -name “*.txt” ; find / -name “.*D.*.txt” find / -name “W.*.txt”
  • 7. find and Logical Operators  Criteria are ANDed together by default.  Can be OR'd or negated with -o and -not  Parentheses can be used to determine logic order, but must be escaped in bash.  find -user vmintam -not -group root  find -user vmintam -o -user root  find -not ( -user vmintam -o -user root )
  • 8. find and Permissions  Can match ownership by name or id  find / -user joe -o -uid 500  Can match octal or symbolic permissions  find -perm 755 matches if mode is exactly 755  find -perm +222 matches if anyone can write  find -perm -222 matches if everyone can write  find -perm -002 matches if other can write
  • 9. find and Numeric Criteria  Many find criteria take numeric values  find -size 1024k  Files with a size of exactly 1 megabyte  find -size +1024k  Files with a size over 1 megabyte  find -size -1024k  Files with a size less than 1 megabyte
  • 10. find and Access Times  find can match by inode timestamps  -atime when file was last read  -mtime when file data last changed  -ctime when file data or metadata last changed  Value given is in days find -ctime -10  Files modified less than 10 days ago find / -atime 5; find / -atime +5; find / -atime -5; find / -anewer example.txt ; try with –cnewer and -newer
  • 11. Executing Commands with find  Commands can be executed on found files  Command must be preceded with -exec or -ok • -ok prompts before acting on each file  Command must end with Space;  Can use {} as a filename placeholder  find -size +102400k -ok gzip {} ;  find -size +100M -exec tar -cvzf /tmp/test.tar.gz {} ;
  • 12. find Execution Examples  find -name "*.conf" -exec cp {} {}.orig ;  Back up configuration files, adding a .orig extension  find /tmp -ctime +3 -user joe -ok rm {} ;  Prompt to remove Joe's tmp files that are over 3 days old  find ~ -type f -exec chmod 644 {} ;  find ~ -type d -exec chmod 755 {} ;