Essential Linux Commands: A Quick Reference for Shell Operations

Enviado por Chuletator online y clasificado en Inglés

Escrito el en español con un tamaño de 3,4 KB

This comprehensive reference provides a quick overview of fundamental Linux shell commands for managing files, directories, searching content, and utilizing command piping.

1. List Command (ls)

  • List all visible files and directories → ls
  • List all files and directories (including hidden files) → ls -a
  • Long list format → ls -l
  • Human-readable format → ls -lh
  • Combining arguments: human-readable format + hidden files → ls -lah
  • Get more information about the ls command → man ls

2. Files and Directories Management

  • Creating Files

    • Create a new file (without opening it) → touch [name-of-your-file]
    • Create a new file using a text editor → vim [name-of-your-file] OR nano [name-of-your-file]
  • Copying Files

    • Copy a file → cp [source-path-of-your-file] [destination-path-for-your-file]
  • Directory Management

    • Create a new directory → mkdir [new-directory-name]
    • Remove an empty directory → rmdir [name-of-the-directory-you-want-to-remove]

3. Remove Command (rm)

  • Remove a file → rm [name-of-your-file]
  • Recursively remove a directory (use with caution) → rm -rf [name-of-your-directory]

4. Concatenate Command (cat)

  • View a single file → cat [name-of-your-file]
  • View a single file including line numbers → cat -n [name-of-your-file]
  • Copy the content of one file to another file → cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
  • More information about the cat command → man cat

5. Move Command (mv)

  • Move a file → mv [source-path-of-your-file] [destination-path-for-your-file]
  • Rename a file → mv [name-of-your-file] [new-name-of-your-file]

6. Searching with Grep

  • Search for a string within a file → grep [term-to-search] [source-file-to-search]
  • Case-insensitive search within a file → grep -i [term-to-search] [source-file-to-search]
  • Search for non-matching lines within a file → grep -v [term-to-search] [source-file-to-search]
  • Recursive search within a directory → grep -r [term-to-search] [path-to-directory-to-search]
  • Multiple searches within a file → grep -E "[first-term-to-search|second-term-to-search]" [source-file-to-search]
  • Count search results → grep -c [term-to-search] [source-file-to-search]
  • Show the name of matching files → grep -l [term-to-search] [matching-files-to-search]
  • More information about grepman grep

7. Pipes

  • Piping commands → [command 1] | [command 2] | [command n]
  • Piping filtered search results into a new file → ls | grep [term-to-filter] > [path-to-new-file]/[name-for-new-file]
  • Search command history → history | grep "[term-to-search]"

Entradas relacionadas: