Mastering Command Line Files: Essential Commands and Tips

Command Line Files: A Beginner’s Guide to File Management

What this covers

  • Basic file navigation and inspection
  • Creating, copying, moving, and deleting files and directories
  • Viewing and editing file contents
  • File permissions and ownership basics
  • Searching and filtering files
  • Useful tips and safety precautions

Common commands (Linux/macOS; Windows equivalents noted)

  • ls — list directory contents (Windows: dir)
  • cd — change directory
  • pwd — print working directory (Windows: cd without args)
  • mkdir — create directory
  • rmdir — remove empty directory (Windows: rmdir)
  • rm — remove files or directories (use with care)
  • cp — copy files or directories (Windows: copy / robocopy)
  • mv — move/rename files or directories (Windows: move)
  • touch — create empty file or update timestamp (Windows: type NUL > file)
  • cat — concatenate and display file contents (Windows: type)
  • less / more — view file contents page-by-page
  • head / tail — show beginning or end of files
  • nano / vi / vim — terminal editors (Windows: not usually present)
  • chmod — change permissions
  • chown — change ownership (requires privileges)
  • find — search for files by name, type, or attributes
  • grep — search inside files for patterns
  • du — disk usage summary
  • df — filesystem disk space usage
  • stat — file metadata

Quick examples

  • List files including hidden: ls -la
  • Create directory and enter it: mkdir project && cd project
  • Copy file preserving attributes: cp -a src.txt dest.txt
  • Move and rename: mv oldname.txt newname.txt
  • Delete a file: rm file.txt (use rm -i to prompt)
  • Recursively delete directory: rm -rf folder (dangerous)
  • Find files named “report.pdf” under current dir: find . -name “report.pdf”
  • Search for “TODO” inside files: grep -R “TODO” .
  • Show last 100 lines of a log and follow new entries: tail -n 100 -f /var/log/syslog
  • Change file to be executable: chmod +x script.sh

File permissions (brief)

  • Permissions format: rwxrwxrwx — owner/group/others
  • Numeric example: chmod 644 file → owner read/write, group/others read
  • Make script executable: chmod 755 script.sh

Safety tips

  • Avoid rm -rf unless sure; test with ls first.
  • Use version control (git) for important files.
  • Use –dry-run or interactive flags where available.
  • Keep backups before bulk operations.

Next steps to learn

  1. Practice basic commands in a safe directory.
  2. Learn shell globbing and redirection (>, >>, |).
  3. Explore scripting (bash) to automate file tasks.
  4. Learn version control (git) and file sync tools.

If you want, I can provide a one-week practice plan or a cheat-sheet of the most-used commands.

Comments

Leave a Reply