{"id":125,"date":"2025-10-25T12:00:00","date_gmt":"2025-10-25T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=125"},"modified":"2026-10-30T06:42:24","modified_gmt":"2026-10-30T06:42:24","slug":"linux-file-management","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=125","title":{"rendered":"Linux File Management"},"content":{"rendered":"<h2 class=\"wp-block-heading\">Linux File Management<\/h2><p class=\"wp-block-paragraph\">I&#8217;m learning DevOps and Linux, and I want to share my notes about working with files and folders. I keep things simple because I&#8217;m still learning.<\/p><h3 class=\"wp-block-heading\">What You&#8217;ll Learn<\/h3><ul class=\"wp-block-list\"><li>How the Linux file system works<\/li><li>How to move around folders<\/li><li>How to create, copy, move, and delete files<\/li><li>How to use paths and wildcards<\/li><li>How to read and search file contents<\/li><li>How to use grep to find text<\/li><li>How to compare files<\/li><li>How to work with file editors<\/li><\/ul><h3 class=\"wp-block-heading\">1. The Linux File System<\/h3><p class=\"wp-block-paragraph\">In Linux, everything starts from the root folder \/. It is like C:\\ in Windows, but Linux does not use drive letters.<\/p><p class=\"wp-block-paragraph\">Example structure:<\/p><pre class=\"wp-block-code\"><code>\/\n\u251c\u2500\u2500 home\/\n\u2502   \u251c\u2500\u2500 reza\/\n\u2502   \u2514\u2500\u2500 john\/\n\u251c\u2500\u2500 etc\/\n\u251c\u2500\u2500 var\/\n\u2514\u2500\u2500 usr\/<\/code><\/pre><p class=\"wp-block-paragraph\">Important folders to remember: \u2022 \/home \u2192 user folders like \/home\/reza \u2022 \/root \u2192 admin user&#8217;s home folder (need sudo) \u2022 \/etc \u2192 configuration and system files \u2022 \/var \u2192 logs and temporary data \u2022 \/usr \u2192 programs and libraries \u2022 \/tmp \u2192 temporary files (deleted after restart)<\/p><h3 class=\"wp-block-heading\">2. Moving Around<\/h3><p class=\"wp-block-paragraph\">pwd \u2192 shows where I am now<\/p><pre class=\"wp-block-code\"><code>pwd<\/code><\/pre><p class=\"wp-block-paragraph\">ls \u2192 lists files and folders<\/p><pre class=\"wp-block-code\"><code>ls\nls -l     # long format\nls -a     # show hidden files<\/code><\/pre><p class=\"wp-block-paragraph\">cd \u2192 move to another folder<\/p><pre class=\"wp-block-code\"><code>cd Documents\ncd ..      # go up one level\ncd ~       # go to my home folder<\/code><\/pre><h3 class=\"wp-block-heading\">3. Understanding Paths<\/h3><p class=\"wp-block-paragraph\">Absolute path starts from \/:<\/p><pre class=\"wp-block-code\"><code>cd \/home\/reza\/Documents<\/code><\/pre><p class=\"wp-block-paragraph\">Relative path starts from where I am:<\/p><pre class=\"wp-block-code\"><code>cd Documents\ncd ..\/john<\/code><\/pre><p class=\"wp-block-paragraph\">Special symbols to remember:<\/p><ul class=\"wp-block-list\"><li>. \u2192 current folder<\/li><li>.. \u2192 one level up<\/li><li>~ \u2192 my home folder<\/li><\/ul><h3 class=\"wp-block-heading\">4. Creating Files and Folders<\/h3><p class=\"wp-block-paragraph\">mkdir \u2192 create a new folder<\/p><p class=\"wp-block-paragraph\">The -p option stands for parents. It tells Linux to automatically create all missing folders in the path.<\/p><pre class=\"wp-block-code\"><code>mkdir my_folder\nmkdir -p projects\/web\/react<\/code><\/pre><p class=\"wp-block-paragraph\">touch \u2192 create an empty file<\/p><pre class=\"wp-block-code\"><code>touch file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Add text to a file:<\/p><pre class=\"wp-block-code\"><code>echo \"Hello World\" &gt; file.txt\necho \"More text\" &gt;&gt; file.txt<\/code><\/pre><h3 class=\"wp-block-heading\">5. Copying Files<\/h3><p class=\"wp-block-paragraph\">cp \u2192 copy files<\/p><pre class=\"wp-block-code\"><code>cp file.txt backup.txt\ncp file.txt ~\/Documents\/<\/code><\/pre><p class=\"wp-block-paragraph\">Copy folders (use -r for recursive):<\/p><pre class=\"wp-block-code\"><code>cp -r folder1 folder2<\/code><\/pre><h3 class=\"wp-block-heading\">6. Moving or Renaming<\/h3><p class=\"wp-block-paragraph\">mv \u2192 move or rename files<\/p><pre class=\"wp-block-code\"><code>mv oldname.txt newname.txt\nmv file.txt Documents\/<\/code><\/pre><p class=\"wp-block-paragraph\">No need for -r when moving folders.<\/p><h3 class=\"wp-block-heading\">7. Deleting Files and Folders<\/h3><p class=\"wp-block-paragraph\">rm \u2192 delete files<\/p><pre class=\"wp-block-code\"><code>rm file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">rm -r \u2192 delete folders and everything inside<\/p><pre class=\"wp-block-code\"><code>rm -r folder_name<\/code><\/pre><p class=\"wp-block-paragraph\">Be careful, there&#8217;s no trash bin. Safe way:<\/p><pre class=\"wp-block-code\"><code>rm -i file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">rmdir \u2192 removes empty folders only<\/p><pre class=\"wp-block-code\"><code>rmdir empty_folder<\/code><\/pre><h3 class=\"wp-block-heading\">8. Reading Files<\/h3><h3 class=\"wp-block-heading\">cat &#8211; Show Whole File<\/h3><p class=\"wp-block-paragraph\">The simplest way to see a file:<\/p><pre class=\"wp-block-code\"><code>cat file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Show multiple files:<\/p><pre class=\"wp-block-code\"><code>cat file1.txt file2.txt<\/code><\/pre><ul class=\"wp-block-list\"><li>Good for: Small files<\/li><li>Bad for: Big files (floods the screen!)<\/li><li>Warning: Never use cat on binary files (images, executables) &#8211; it breaks the terminal!<\/li><\/ul><h3 class=\"wp-block-heading\">head &#8211; Show Beginning<\/h3><p class=\"wp-block-paragraph\">See first 10 lines:<\/p><pre class=\"wp-block-code\"><code>head file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">See first 5 lines:<\/p><pre class=\"wp-block-code\"><code>head -n 5 file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">When I use this: Checking log files, seeing file headers<\/p><h3 class=\"wp-block-heading\">tail &#8211; Show End<\/h3><p class=\"wp-block-paragraph\">See last 10 lines:<\/p><pre class=\"wp-block-code\"><code>tail file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">See last 20 lines:<\/p><pre class=\"wp-block-code\"><code>tail -n 20 file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Watch file live (great for logs!):<\/p><pre class=\"wp-block-code\"><code>tail -f \/var\/log\/syslog<\/code><\/pre><p class=\"wp-block-paragraph\">This keeps showing new lines as they&#8217;re added. Press Ctrl+C to stop.<\/p><p class=\"wp-block-paragraph\">When I use this: Watching log files in real-time, checking recent entries<\/p><h3 class=\"wp-block-heading\">less &#8211; View Page by Page<\/h3><p class=\"wp-block-paragraph\">A program to read files page by page. Much better than cat for big files.<\/p><pre class=\"wp-block-code\"><code>less bigfile.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Navigation in less:<\/p><ul class=\"wp-block-list\"><li>Space \u2192 Next page<\/li><li>b \u2192 Previous page<\/li><li>Arrow keys \u2192 Move up\/down<\/li><li>g \u2192 Go to beginning<\/li><li>G \u2192 Go to end<\/li><li>q \u2192 Quit<\/li><\/ul><p class=\"wp-block-paragraph\">Searching in less: Press \/ then type search term:<\/p><pre class=\"wp-block-code\"><code># Inside less:\n\/error        # Find \"error\"\nn            # Next match\nN            # Previous match<\/code><\/pre><p class=\"wp-block-paragraph\">Why I Use less:<\/p><ul class=\"wp-block-list\"><li>Doesn&#8217;t load entire file at once (fast!)<\/li><li>Can search \u2022 Can go back and forth \u2022<\/li><li>Doesn&#8217;t mess up my terminal<\/li><\/ul><h3 class=\"wp-block-heading\">9. Searching in Files with grep<\/h3><h3 class=\"wp-block-heading\">What is grep?<\/h3><p class=\"wp-block-paragraph\">Searches for text patterns in files. Super useful!<\/p><p class=\"wp-block-paragraph\">grep = Global Regular Expression Print<\/p><h3 class=\"wp-block-heading\">Basic Usage<\/h3><pre class=\"wp-block-code\"><code>grep \"search_term\" file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Example:<\/p><pre class=\"wp-block-code\"><code>grep \"error\" logfile.log\n# Shows all lines with \"error\"<\/code><\/pre><h3 class=\"wp-block-heading\">Useful grep Options<\/h3><pre class=\"wp-block-code\"><code>grep -i \"error\" file.txt          # Ignore case (Error, ERROR, error)\ngrep -n \"error\" file.txt          # Show line numbers\ngrep -v \"error\" file.txt          # Show lines WITHOUT \"error\"\ngrep -r \"error\" \/var\/log\/         # Search recursively in folder\ngrep -l \"error\" *.log             # Show only filenames with matches\ngrep -c \"error\" file.txt          # Count matching lines<\/code><\/pre><h3 class=\"wp-block-heading\">Search Multiple Files<\/h3><pre class=\"wp-block-code\"><code>grep \"error\" *.log                # Search all .log files\ngrep \"error\" file1.txt file2.txt  # Search specific files<\/code><\/pre><h3 class=\"wp-block-heading\">Common Patterns I Use<\/h3><pre class=\"wp-block-code\"><code># Find errors in logs\ngrep -i \"error\" \/var\/log\/syslog\n\n# Find my IP address\ngrep \"192.168\" \/etc\/hosts\n\n# Find failed login attempts\ngrep \"Failed password\" \/var\/log\/auth.log\n\n# Count errors\ngrep -c \"error\" application.log<\/code><\/pre><h3 class=\"wp-block-heading\">Advanced grep<\/h3><p class=\"wp-block-paragraph\">Using Regular Expressions:<\/p><pre class=\"wp-block-code\"><code>grep \"^error\" file.txt        # Lines starting with \"error\"\ngrep \"error$\" file.txt        # Lines ending with \"error\"\ngrep \"error.*warning\" file.txt # Lines with error then warning\ngrep \"[0-9]\" file.txt         # Lines with numbers<\/code><\/pre><p class=\"wp-block-paragraph\">Grep with Pipes:<\/p><pre class=\"wp-block-code\"><code>ps aux | grep nginx           # Find nginx processes\nls -la | grep \"txt\"           # Find txt files in listing\ncat file.txt | grep \"error\"   # Same as: grep \"error\" file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Context Lines:<\/p><pre class=\"wp-block-code\"><code>grep -A 3 \"error\" file.txt    # Show 3 lines After match\ngrep -B 2 \"error\" file.txt    # Show 2 lines Before match\ngrep -C 2 \"error\" file.txt    # Show 2 lines of Context (before and after)<\/code><\/pre><h3 class=\"wp-block-heading\">10. Wildcards (Working with Many Files at Once)<\/h3><p class=\"wp-block-paragraph\">Wildcards help you work with many files or folders using one command instead of typing each name. They are very useful when you have many files with similar names.<\/p><h3 class=\"wp-block-heading\">* (Asterisk) \u2013 Matches Anything<\/h3><p class=\"wp-block-paragraph\">The star * means &#8220;any number of characters.&#8221; You can use it anywhere in a file name.<\/p><p class=\"wp-block-paragraph\">Examples:<\/p><pre class=\"wp-block-code\"><code>ls *.txt\n# Shows all files that end with .txt (for example: notes.txt, report.txt, list.txt)\n\nls file*\n# Shows all files that start with \"file\" (for example: file1.txt, fileA.txt, file_backup.log)\n\nrm *.log\n# Deletes all files that end with .log (for example: system.log, app.log, error.log)\n\ncp *.jpg Pictures\/\n# Copies all image files that end with .jpg into the Pictures folder.<\/code><\/pre><h3 class=\"wp-block-heading\">? (Question Mark) \u2013 Matches One Character<\/h3><p class=\"wp-block-paragraph\">The question mark ? replaces only one single character.<\/p><p class=\"wp-block-paragraph\">Examples:<\/p><pre class=\"wp-block-code\"><code>ls file?.txt\n# Matches files like: file1.txt, fileA.txt, fileb.txt\n# But not: file10.txt (because it has two extra characters)\n\nls ???.txt\n# Matches any file name that has exactly three characters before .txt\n# (for example: cat.txt, dog.txt, log.txt)<\/code><\/pre><p class=\"wp-block-paragraph\">Practice Tip: You can test your wildcard command with ls first to make sure it matches what you expect. For example:<\/p><pre class=\"wp-block-code\"><code>ls *.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Then if it looks correct, you can safely run:<\/p><pre class=\"wp-block-code\"><code>rm *.txt<\/code><\/pre><p class=\"wp-block-paragraph\">This helps avoid deleting the wrong files.<\/p><h3 class=\"wp-block-heading\">11. Finding Files (Search Anywhere in Linux)<\/h3><p class=\"wp-block-paragraph\">When your folders have many files, it&#8217;s easy to lose something. The find command helps you search for a file or folder by name, type, or size.<\/p><p class=\"wp-block-paragraph\">The basic format is:<\/p><pre class=\"wp-block-code\"><code>find [where_to_search] [option] [what_to_find]<\/code><\/pre><p class=\"wp-block-paragraph\">For example:<\/p><pre class=\"wp-block-code\"><code>find . -name \"file.txt\"\n# . means start searching in the current folder\n# -name \"file.txt\" means look for a file with this exact name<\/code><\/pre><h3 class=\"wp-block-heading\">Common Examples<\/h3><p class=\"wp-block-paragraph\">Find a file in the current folder and subfolders:<\/p><pre class=\"wp-block-code\"><code>find . -name \"notes.txt\"<\/code><\/pre><p class=\"wp-block-paragraph\">Find all .log files inside \/home:<\/p><pre class=\"wp-block-code\"><code>find \/home -name \"*.log\"<\/code><\/pre><p class=\"wp-block-paragraph\">Find all .txt files (case insensitive):<\/p><pre class=\"wp-block-code\"><code>find . -iname \"*.txt\"\n# -iname ignores upper or lower case (so it matches both FILE.TXT and file.txt)<\/code><\/pre><p class=\"wp-block-paragraph\">Find only files (not folders):<\/p><pre class=\"wp-block-code\"><code>find . -type f -name \"*.sh\"\n# -type f means look for regular files.<\/code><\/pre><p class=\"wp-block-paragraph\">Find only folders:<\/p><pre class=\"wp-block-code\"><code>find . -type d -name \"backup\"\n# -type d means look for directories (folders).<\/code><\/pre><h3 class=\"wp-block-heading\">Advanced Examples<\/h3><p class=\"wp-block-paragraph\">Find large files (more than 10MB):<\/p><pre class=\"wp-block-code\"><code>find . -type f -size +10M\n# +10M means larger than 10 megabytes\n# You can also use -10M for smaller than 10MB<\/code><\/pre><p class=\"wp-block-paragraph\">Find files changed in the last 2 days:<\/p><pre class=\"wp-block-code\"><code>find . -mtime -2\n# -mtime checks when the file was last modified\n# -2 means in the last two days<\/code><\/pre><p class=\"wp-block-paragraph\">Find and delete specific files:<\/p><pre class=\"wp-block-code\"><code>find . -name \"*.tmp\" -delete\n# Deletes all temporary .tmp files under the current folder.\n# Use this carefully, it does not ask for confirmation.<\/code><\/pre><p class=\"wp-block-paragraph\">Practice Tip: When using find, start with small areas like . (current folder) before searching your whole system. Example:<\/p><pre class=\"wp-block-code\"><code>find . -name \"*.log\"<\/code><\/pre><p class=\"wp-block-paragraph\">is faster and safer than<\/p><pre class=\"wp-block-code\"><code>find \/ -name \"*.log\"<\/code><\/pre><p class=\"wp-block-paragraph\">which searches the entire computer.<\/p><h3 class=\"wp-block-heading\">12. Comparing Files<\/h3><h3 class=\"wp-block-heading\">diff &#8211; Compare Two Files<\/h3><p class=\"wp-block-paragraph\">See differences between files:<\/p><pre class=\"wp-block-code\"><code>diff file1.txt file2.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Output symbols:<\/p><ul class=\"wp-block-list\"><li>&lt; = line from first file<\/li><li>&gt; = line from second file<\/li><li>a = added<\/li><li>d = deleted<\/li><li>c = changed<\/li><\/ul><h3 class=\"wp-block-heading\">Side-by-Side View<\/h3><pre class=\"wp-block-code\"><code>diff -y file1.txt file2.txt<\/code><\/pre><h3 class=\"wp-block-heading\">Ignore Case and Whitespace<\/h3><pre class=\"wp-block-code\"><code>diff -i file1.txt file2.txt        # Ignore case\ndiff -w file1.txt file2.txt        # Ignore whitespace<\/code><\/pre><h3 class=\"wp-block-heading\">13. Text Editors in Terminal<\/h3><h3 class=\"wp-block-heading\">nano &#8211; Easy Editor<\/h3><p class=\"wp-block-paragraph\">Simple text editor:<\/p><pre class=\"wp-block-code\"><code>nano file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Controls (shown at bottom):<\/p><ul class=\"wp-block-list\"><li>Ctrl+O = Save (Write Out)<\/li><li>Ctrl+X = Exit<\/li><li>Ctrl+K = Cut line<\/li><li>Ctrl+U = Paste<\/li><li>Ctrl+W = Search<\/li><\/ul><p class=\"wp-block-paragraph\">I use nano when: Quick edits, simple config changes<\/p><h3 class=\"wp-block-heading\">vim &#8211; Advanced Editor<\/h3><p class=\"wp-block-paragraph\">Powerful but harder to learn:<\/p><pre class=\"wp-block-code\"><code>vim file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Two modes:<\/p><ul class=\"wp-block-list\"><li>Normal mode (default) &#8211; for commands<\/li><li>Insert mode &#8211; for typing (press i)<\/li><\/ul><p class=\"wp-block-paragraph\">Basic vim commands:<\/p><ul class=\"wp-block-list\"><li>i = Enter insert mode<\/li><li>Esc = Back to normal mode<\/li><li>:w = Save<\/li><li>:q = Quit<\/li><li>:wq = Save and quit<\/li><li>:q! = Quit without saving<\/li><\/ul><h3 class=\"wp-block-heading\">Quick Comparison<\/h3><ul class=\"wp-block-list\"><li>nano: Easy to learn, usually installed, basic features, my choice for quick edits<\/li><li>vim: Hard to learn, always installed, very powerful, my choice for serious work<\/li><\/ul><h3 class=\"wp-block-heading\">14. File Analysis Tools<\/h3><h3 class=\"wp-block-heading\">file &#8211; Identify File Type<\/h3><pre class=\"wp-block-code\"><code>file document.pdf\n# Output: PDF document\n\nfile image.jpg\n# Output: JPEG image data\n\nfile script.sh\n# Output: Bash script<\/code><\/pre><p class=\"wp-block-paragraph\">Useful when file has wrong extension or no extension.<\/p><h3 class=\"wp-block-heading\">wc &#8211; Word Count<\/h3><pre class=\"wp-block-code\"><code>wc file.txt\n# Output: lines words bytes filename<\/code><\/pre><p class=\"wp-block-paragraph\">Count lines only:<\/p><pre class=\"wp-block-code\"><code>wc -l file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Count words only:<\/p><pre class=\"wp-block-code\"><code>wc -w file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">Count characters:<\/p><pre class=\"wp-block-code\"><code>wc -m file.txt<\/code><\/pre><h3 class=\"wp-block-heading\">Practical Examples<\/h3><pre class=\"wp-block-code\"><code># Count files in directory\nls | wc -l\n\n# Count log entries\ngrep \"error\" app.log | wc -l\n\n# Count lines of code\nfind . -name \"*.py\" | xargs wc -l<\/code><\/pre><h3 class=\"wp-block-heading\">15. Sorting and Unique Lines<\/h3><h3 class=\"wp-block-heading\">sort &#8211; Sort Lines<\/h3><pre class=\"wp-block-code\"><code>sort file.txt               # Sort alphabetically\nsort -r file.txt            # Reverse sort\nsort -n file.txt            # Sort numerically\nsort -u file.txt            # Sort and remove duplicates<\/code><\/pre><h3 class=\"wp-block-heading\">uniq &#8211; Remove Duplicate Lines<\/h3><p class=\"wp-block-paragraph\">Important: File must be sorted first!<\/p><pre class=\"wp-block-code\"><code>sort file.txt | uniq        # Remove duplicates\nsort file.txt | uniq -c     # Count occurrences\nsort file.txt | uniq -d     # Show only duplicates<\/code><\/pre><h3 class=\"wp-block-heading\">Practical Example<\/h3><p class=\"wp-block-paragraph\">Find most common errors in log:<\/p><pre class=\"wp-block-code\"><code>grep \"error\" app.log | sort | uniq -c | sort -rn<\/code><\/pre><p class=\"wp-block-paragraph\">This:<\/p><ol class=\"wp-block-list\"><li>Finds all error lines<\/li><li>Sorts them<\/li><li>Counts duplicates<\/li><li>Sorts by count (highest first)<\/li><\/ol><h3 class=\"wp-block-heading\">16. File Permissions (Basic Idea)<\/h3><p class=\"wp-block-paragraph\">Example:<\/p><pre class=\"wp-block-code\"><code>-rw-r--r-- 1 reza reza 1234 Oct 19 10:30 file.txt<\/code><\/pre><p class=\"wp-block-paragraph\">What it means: \u2022 rw- \u2192 owner can read and write \u2022 r&#8211; \u2192 group can read only \u2022 r&#8211; \u2192 others can read only<\/p><h3 class=\"wp-block-heading\">17. Command Quick Reference<\/h3><h3 class=\"wp-block-heading\">Navigation<\/h3><ul class=\"wp-block-list\"><li>pwd \u2192 Show current folder<\/li><li>ls \u2192 List files<\/li><li>cd folder \u2192 Go to folder<\/li><li>cd .. \u2192 Go up one level<\/li><li>cd ~ \u2192 Go home<\/li><\/ul><h3 class=\"wp-block-heading\">File Actions<\/h3><ul class=\"wp-block-list\"><li>touch file.txt \u2192 Create file<\/li><li>mkdir folder \u2192 Create folder<\/li><li>cp file1 file2 \u2192 Copy file<\/li><li>cp -r dir1 dir2 \u2192 Copy folder<\/li><li>mv old new \u2192 Move or rename<\/li><li>rm file \u2192 Delete file<\/li><li>rm -r folder \u2192 Delete folder<\/li><\/ul><h3 class=\"wp-block-heading\">Reading Files<\/h3><ul class=\"wp-block-list\"><li>cat file.txt \u2192 Show whole file<\/li><li>head file.txt \u2192 Show first 10 lines<\/li><li>tail file.txt \u2192 Show last 10 lines<\/li><li>tail -f file.txt \u2192 Watch file live<\/li><li>less file.txt \u2192 View file page by page<\/li><\/ul><h3 class=\"wp-block-heading\">Searching<\/h3><ul class=\"wp-block-list\"><li>grep &#8220;text&#8221; file \u2192 Find text in file<\/li><li>grep -i &#8220;text&#8221; file \u2192 Case insensitive search<\/li><li>grep -r &#8220;text&#8221; folder\/ \u2192 Search in folder<\/li><li>grep -n &#8220;text&#8221; file \u2192 Show line numbers<\/li><li>grep -v &#8220;text&#8221; file \u2192 Show lines without text<\/li><\/ul><h3 class=\"wp-block-heading\">File Analysis<\/h3><ul class=\"wp-block-list\"><li>wc -l file \u2192 Count lines<\/li><li>diff file1 file2 \u2192 Compare files<\/li><li>file filename \u2192 Show file type<\/li><li>sort file \u2192 Sort lines<\/li><li>uniq file \u2192 Remove duplicates<\/li><\/ul><h3 class=\"wp-block-heading\">What I Learned<\/h3><ol class=\"wp-block-list\"><li>Everything starts from \/<\/li><li>Use pwd, ls, and cd to move around<\/li><li>Use absolute or relative paths<\/li><li>Add -r when copying folders<\/li><li>rm deletes permanently<\/li><li>Wildcards save time<\/li><li>Always check your path before removing files<\/li><li>Use less for large files, cat for small ones<\/li><li>grep is super powerful for searching<\/li><li>tail -f is perfect for watching logs<\/li><li>Always pipe through sort before using uniq<\/li><li>nano for quick edits, vim for power users<\/li><li>Regular expressions make grep even more useful<\/li><\/ol><h3 class=\"wp-block-heading\">Common Commands<\/h3><pre class=\"wp-block-code\"><code># Watch logs\ntail -f \/var\/log\/nginx\/error.log\n\n# Find errors\ngrep -i \"error\" \/var\/log\/syslog | less\n\n# Count errors today\ngrep \"$(date +%Y-%m-%d)\" \/var\/log\/app.log | grep -c \"ERROR\"\n\n# Find config files\nfind \/etc -name \"*.conf\"\n\n# Check file before editing\nless \/etc\/nginx\/nginx.conf\n\n# Quick edit\nvim ~\/.bashrc\n\n# Find large files\nfind . -type f -size +100M\n\n# Most common errors\ngrep ERROR app.log | sort | uniq -c | sort -rn | head\n\n# Test wildcard commands safely\nls *.txt\n\n# Find and count specific file types\nfind . -name \"*.py\" | wc -l<\/code><\/pre><h3 class=\"wp-block-heading\">Tips<\/h3><ul class=\"wp-block-list\"><li>Always check your current folder with pwd.<\/li><li>Use rm -i to confirm before deleting.<\/li><li>Test wildcard commands with ls first.<\/li><li>Practice in test folders before using real files.<\/li><li>Keep backups of important data.<\/li><li>Use less instead of cat for large files.<\/li><li>Learn a few grep patterns, they&#8217;re incredibly useful.<\/li><li>Start with nano for editing, learn vim later.<\/li><li>When in doubt, check the manual with man command.<\/li><\/ul><p class=\"wp-block-paragraph\">That&#8217;s my complete guide to Linux file management! Now I can navigate, create, read, search, and manage files.<\/p>","protected":false},"excerpt":{"rendered":"<p>Linux File Management I&#8217;m learning DevOps and Linux, and I want to share my notes about working with files and folders. I&hellip;<\/p>\n","protected":false},"author":2,"featured_media":127,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"1","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/linux-file-management-reza-chegini-3cbcc\/","footnotes":""},"categories":[10,74],"tags":[78,8,77,76],"series":[75],"class_list":["post-125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-linux","tag-command-line","tag-devops","tag-file-management","tag-linux","series-linux-fundamentals"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/10\/linux-file-management-cover.png","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions\/126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/127"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}