Skip to content

Latest commit

 

History

History
433 lines (303 loc) · 12 KB

commands.md

File metadata and controls

433 lines (303 loc) · 12 KB

Here’s a detailed explanation of the commands you requested. These descriptions include their purposes, syntax, common options, and examples.

File and Directory Management Commands

mkdir (Make Directory)

  • Purpose: Creates new directories.
  • Syntax: mkdir [options] [directory_name]
  • Options:
    • -p: Create parent directories as needed (e.g., nested directories).
  • Example:
    • mkdir new_folder → Creates a directory named new_folder.
    • mkdir -p parent/child → Creates parent and child directories if they don’t exist.

touch (Create or Update File)

  • Purpose: Creates empty files or updates timestamps of existing files.
  • Syntax: touch [file_name]
  • Example:
    • touch file.txt → Creates an empty file named file.txt.
    • touch file1 file2 → Creates two empty files, file1 and file2.

cd (Change Directory)

  • Purpose: Changes the current working directory.
  • Syntax: cd [directory_path]
  • Examples:
    • cd /home/user/documents → Moves to the specified directory.
    • cd .. → Moves to the parent directory.
    • cd ~ → Moves to the home directory.

ls (List Directory Contents)

  • Purpose: Lists files and directories in the current or specified directory.
  • Syntax: ls [options] [directory]
  • Options:
    • -l: Detailed list format (permissions, size, modification date).
    • -a: Shows hidden files (files starting with .).
    • -h: Human-readable sizes.
  • Examples:
    • ls → Lists files in the current directory.
    • ls -la → Lists all files (including hidden) in detailed format.

pwd (Print Working Directory)

  • Purpose: Displays the full path of the current directory.
  • Syntax: pwd
  • Example:
    • If you’re in /home/user/documents, pwd outputs /home/user/documents.

rm (Remove Files/Directories)

  • Purpose: Deletes files or directories.
  • Syntax: rm [options] [file/directory]
  • Options:
    • -r: Remove directories and their contents recursively.
    • -f: Force deletion without confirmation.
  • Examples:
    • rm file.txt → Deletes file.txt.
    • rm -rf folder → Deletes folder and all its contents.

cp (Copy Files/Directories)

  • Purpose: Copies files or directories.
  • Syntax: cp [options] [source] [destination]
  • Options:
    • -r: Recursively copy directories.
    • -v: Verbose output (show progress).
  • Examples:
    • cp file1.txt file2.txt → Copies file1.txt to file2.txt.
    • cp -r source_folder target_folder → Copies a directory.

mv (Move or Rename Files/Directories)

  • Purpose: Moves or renames files or directories.
  • Syntax: mv [source] [destination]
  • Examples:
    • mv file.txt /home/user/ → Moves file.txt to the /home/user directory.
    • mv oldname.txt newname.txt → Renames oldname.txt to newname.txt.

File Viewing Commands

cat (Concatenate and View Files)

  • Purpose: Displays the contents of a file or concatenates multiple files.
  • Syntax: cat [file_name(s)]
  • Examples:
    • cat file.txt → Displays the content of file.txt.
    • cat file1.txt file2.txt > combined.txt → Merges file1 and file2 into combined.txt.

less (View Large Files)

  • Purpose: Views file contents one page at a time.
  • Syntax: less [file_name]
  • Examples:
    • less file.txt → Opens file.txt for paginated viewing.
    • Use q to quit, Arrow Keys for navigation.

head (First Lines of a File)

  • Purpose: Displays the first few lines of a file.
  • Syntax: head -n [number] [file_name]
  • Example:
    • head -n 5 file.txt → Shows the first 5 lines of file.txt.

tail (Last Lines of a File)

  • Purpose: Displays the last few lines of a file.
  • Syntax: tail -n [number] [file_name]
  • Example:
    • tail -n 10 file.txt → Shows the last 10 lines of file.txt.

File Editing Commands

nano (Basic Text Editor)

  • Purpose: Edit text files in a terminal.
  • Syntax: nano [file_name]
  • Examples:
    • nano file.txt → Opens file.txt for editing.
    • Use Ctrl + O to save and Ctrl + X to exit.

vim (Advanced Text Editor)

  • Purpose: Edit text files with advanced features.
  • Syntax: vim [file_name]
  • Basics:
    • Press i to enter insert mode.
    • Press Esc, type :wq, and press Enter to save and exit.

Process Management Commands

ps (Process Status)

  • Purpose: Displays running processes.
  • Syntax: ps [options]
  • Options:
    • aux: Shows all processes with detailed info.
  • Example:
    • ps aux → Lists all running processes.

top (Real-Time Process Monitoring)

  • Purpose: Displays real-time information about system processes and resource usage.
  • Syntax: top
  • Usage:
    • Press q to quit.

kill (Terminate Processes)

  • Purpose: Stops a process by its Process ID (PID).
  • Syntax: kill [PID]
  • Examples:
    • kill 1234 → Terminates the process with PID 1234.

killall (Terminate Processes by Name)

  • Purpose: Stops all processes with a specific name.
  • Syntax: killall [process_name]
  • Example:
    • killall firefox → Stops all instances of Firefox.

Shell Utilities

man (Manual Pages)

  • Purpose: Displays help documentation for commands.
  • Syntax: man [command_name]
  • Example:
    • man ls → Displays the manual for ls.

grep (Search Patterns in Files)

  • Purpose: Searches for a specific text pattern.
  • Syntax: grep [pattern] [file_name]
  • Example:
    • grep "error" log.txt → Finds occurrences of "error" in log.txt.

Here’s a detailed explanation of the commands you requested. These descriptions include their purposes, syntax, common options, and examples.


File and Directory Management Commands

mkdir (Make Directory)

  • Purpose: Creates new directories.
  • Syntax: mkdir [options] [directory_name]
  • Options:
    • -p: Create parent directories as needed (e.g., nested directories).
  • Example:
    • mkdir new_folder → Creates a directory named new_folder.
    • mkdir -p parent/child → Creates parent and child directories if they don’t exist.

touch (Create or Update File)

  • Purpose: Creates empty files or updates timestamps of existing files.
  • Syntax: touch [file_name]
  • Example:
    • touch file.txt → Creates an empty file named file.txt.
    • touch file1 file2 → Creates two empty files, file1 and file2.

cd (Change Directory)

  • Purpose: Changes the current working directory.
  • Syntax: cd [directory_path]
  • Examples:
    • cd /home/user/documents → Moves to the specified directory.
    • cd .. → Moves to the parent directory.
    • cd ~ → Moves to the home directory.

ls (List Directory Contents)

  • Purpose: Lists files and directories in the current or specified directory.
  • Syntax: ls [options] [directory]
  • Options:
    • -l: Detailed list format (permissions, size, modification date).
    • -a: Shows hidden files (files starting with .).
    • -h: Human-readable sizes.
  • Examples:
    • ls → Lists files in the current directory.
    • ls -la → Lists all files (including hidden) in detailed format.

pwd (Print Working Directory)

  • Purpose: Displays the full path of the current directory.
  • Syntax: pwd
  • Example:
    • If you’re in /home/user/documents, pwd outputs /home/user/documents.

rm (Remove Files/Directories)

  • Purpose: Deletes files or directories.
  • Syntax: rm [options] [file/directory]
  • Options:
    • -r: Remove directories and their contents recursively.
    • -f: Force deletion without confirmation.
  • Examples:
    • rm file.txt → Deletes file.txt.
    • rm -rf folder → Deletes folder and all its contents.

cp (Copy Files/Directories)

  • Purpose: Copies files or directories.
  • Syntax: cp [options] [source] [destination]
  • Options:
    • -r: Recursively copy directories.
    • -v: Verbose output (show progress).
  • Examples:
    • cp file1.txt file2.txt → Copies file1.txt to file2.txt.
    • cp -r source_folder target_folder → Copies a directory.

mv (Move or Rename Files/Directories)

  • Purpose: Moves or renames files or directories.
  • Syntax: mv [source] [destination]
  • Examples:
    • mv file.txt /home/user/ → Moves file.txt to the /home/user directory.
    • mv oldname.txt newname.txt → Renames oldname.txt to newname.txt.

File Viewing Commands

cat (Concatenate and View Files)

  • Purpose: Displays the contents of a file or concatenates multiple files.
  • Syntax: cat [file_name(s)]
  • Examples:
    • cat file.txt → Displays the content of file.txt.
    • cat file1.txt file2.txt > combined.txt → Merges file1 and file2 into combined.txt.

less (View Large Files)

  • Purpose: Views file contents one page at a time.
  • Syntax: less [file_name]
  • Examples:
    • less file.txt → Opens file.txt for paginated viewing.
    • Use q to quit, Arrow Keys for navigation.

head (First Lines of a File)

  • Purpose: Displays the first few lines of a file.
  • Syntax: head -n [number] [file_name]
  • Example:
    • head -n 5 file.txt → Shows the first 5 lines of file.txt.

tail (Last Lines of a File)

  • Purpose: Displays the last few lines of a file.
  • Syntax: tail -n [number] [file_name]
  • Example:
    • tail -n 10 file.txt → Shows the last 10 lines of file.txt.

File Editing Commands

nano (Basic Text Editor)

  • Purpose: Edit text files in a terminal.
  • Syntax: nano [file_name]
  • Examples:
    • nano file.txt → Opens file.txt for editing.
    • Use Ctrl + O to save and Ctrl + X to exit.

vim (Advanced Text Editor)

  • Purpose: Edit text files with advanced features.
  • Syntax: vim [file_name]
  • Basics:
    • Press i to enter insert mode.
    • Press Esc, type :wq, and press Enter to save and exit.

Process Management Commands

ps (Process Status)

  • Purpose: Displays running processes.
  • Syntax: ps [options]
  • Options:
    • aux: Shows all processes with detailed info.
  • Example:
    • ps aux → Lists all running processes.

top (Real-Time Process Monitoring)

  • Purpose: Displays real-time information about system processes and resource usage.
  • Syntax: top
  • Usage:
    • Press q to quit.

kill (Terminate Processes)

  • Purpose: Stops a process by its Process ID (PID).
  • Syntax: kill [PID]
  • Examples:
    • kill 1234 → Terminates the process with PID 1234.

killall (Terminate Processes by Name)

  • Purpose: Stops all processes with a specific name.
  • Syntax: killall [process_name]
  • Example:
    • killall firefox → Stops all instances of Firefox.

Shell Utilities

man (Manual Pages)

  • Purpose: Displays help documentation for commands.
  • Syntax: man [command_name]
  • Example:
    • man ls → Displays the manual for ls.

grep (Search Patterns in Files)

  • Purpose: Searches for a specific text pattern.
  • Syntax: grep [pattern] [file_name]
  • Example:
    • grep "error" log.txt → Finds occurrences of "error" in log.txt.