Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Linux File Operations and Commands

Tech May 8 3

Core File Operations in Linux

File Naming Conventions

  • Use descriptive names for files and directories
  • Separate words with underscores (e.g., my_website.html)
  • Ensure unique names within the same directory (Linux is case-sensitive)

Example:

touch 'descriptive_name.txt'
touch project_backup.tar.gz

Directory Operations

  • Create directories: mkdir dir_name
  • Create nested directories: mkdir -p path/to/nested/dir
  • Remove empty directories: rmdir dir_name

Example:

mkdir -p projects/2023/linux/config

File Operations

  • Create files: touch filename
  • Delete files: rm filename
  • Force delete: rm -f filename
  • Recursive delete: rm -rf directory

Example:

touch {report1,report2,report3}.log
rm -f obsolete_file.txt

Copy and Move Operations

  • Copy files: cp source destination
  • Copy directories: cp -r source_dir destination
  • Move/rename: mv old_name new_name

Example:

cp -r /var/log/nginx /backups/
mv old_config.txt new_config.cfg

Compression and Archiving

  • Create tar archive: tar -cvf archive.tar files/
  • Compress with gzip: tar -czvf archive.tar.gz files/
  • Extract archive: tar -xvf archive.tar

Example:

tar -czvf web_backup.tar.gz /var/www/html

File Viewing Commands

  • View entire file: cat filename
  • View with line numbers: cat -n filename
  • View end of file: tail -n 20 filename
  • Follow log changes: tail -f /var/log/syslog

Example:

tail -f /var/log/nginx/access.log

Search Operations

  • Find files by name: find / -name "*.conf"
  • Find files containing text: grep -r "search_term" /path
  • Count lines: wc -l filename

Example:

find /etc -name "*.conf" | xargs grep -l "timeout"

Process and System Monitoring

  • View processes: ps aux
  • Filter processes: ps aux | grep nginx
  • Check ports: netstat -tulnp

Example:

ps aux | grep java
netstat -tulnp | grep :80

Text Editing with Vim

  • Basic commands:
    • Insert mode: i
    • Save and quit: :wq
    • Quit without saving: :q!
    • Copy line: yy
    • Delete line: dd
    • Go to start: gg
    • Go to end: G
    • Undo: u

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.