File management

1.9 Identify common features and tools of the Linux client/desktop operating system.

📘CompTIA A+ Core 2 (220-1202)


Linux File Management for the CompTIA A+ Exam

Linux is widely used in servers, desktops, and embedded systems. One key skill is managing files and directories using the command line. Here’s what you need to know about the most common commands:


1. ls – List files and directories

  • Purpose: Displays files and folders in the current directory.
  • Basic syntax:
ls
  • Common options:
    • ls -l → Shows detailed info (permissions, owner, size, date modified).
    • ls -a → Shows hidden files (files starting with .).
    • ls -lh → Human-readable sizes in long listing.

IT example:

  • A sysadmin checks what files are in /etc to verify configuration files.
ls -lh /etc

2. pwd – Print Working Directory

  • Purpose: Shows the full path of the current directory you are in.
  • Syntax:
pwd

IT example:

  • You are logged into a remote server and want to confirm your location before editing files.

3. mv – Move or Rename files

  • Purpose: Moves files or directories from one location to another or renames them.
  • Syntax:
mv [source] [destination]

IT examples:

  • Move report.txt to /home/user/docs/
mv report.txt /home/user/docs/
  • Rename oldname.txt to newname.txt
mv oldname.txt newname.txt

4. cp – Copy files or directories

  • Purpose: Copies files or directories to another location.
  • Syntax:
cp [source] [destination]
  • Options:
    • cp -r → Copy directories recursively.
    • cp -i → Ask before overwriting existing files.

IT example:

  • Backup a configuration file before making changes:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

5. rm – Remove files or directories

  • Purpose: Deletes files or directories. Be careful – this is permanent unless using a system with recovery.
  • Syntax:
rm [file]
  • Options:
    • rm -r → Remove directories recursively.
    • rm -f → Force delete without asking.

IT example:

  • Remove an old log file to free disk space:
rm /var/log/oldlog.log

6. chmod – Change file permissions

  • Purpose: Changes the read, write, and execute permissions of files or directories.
  • Syntax:
chmod [permissions] [file]
  • Permissions format:
    • r = read
    • w = write
    • x = execute
  • Numeric method:
    • 4 → read
    • 2 → write
    • 1 → execute
    • Example: chmod 755 script.sh
      • Owner: read/write/execute
      • Group & Others: read/execute

IT example:

  • Make a deployment script executable by all users:
chmod 755 deploy.sh

7. chown – Change file owner or group

  • Purpose: Changes the owner or group of a file/directory.
  • Syntax:
chown [owner][:group] [file]

IT example:

  • Assign a file to a new owner admin and group staff:
chown admin:staff server.log

8. grep – Search for text in files

  • Purpose: Searches for specific text patterns inside files.
  • Syntax:
grep [options] "pattern" [file]
  • Options:
    • -i → Ignore case
    • -r → Search recursively in directories
    • -n → Show line numbers

IT example:

  • Find all lines containing “ERROR” in a log:
grep "ERROR" /var/log/syslog

9. find – Locate files and directories

  • Purpose: Searches for files and directories based on name, type, size, or other attributes.
  • Syntax:
find [path] [criteria]
  • Common examples:
    • find /home -name "*.txt" → Find all .txt files in /home.
    • find /var/log -type f -size +10M → Find files larger than 10 MB in /var/log.

IT example:

  • Locate a backup file created yesterday:
find /backups -name "backup-20260121.tar.gz"

Exam Tips

  1. Understand command purposes – don’t just memorize syntax. Know the difference between mv and cp.
  2. Options matter – most commands have flags like -r or -i. The exam may ask what a command does with certain options.
  3. Permissions & ownershipchmod and chown are frequently tested concepts.
  4. Searching filesgrep and find are essential for troubleshooting logs and configuration in Linux.
Buy Me a Coffee