Khush Shah

Command Line Utilities in Linux

Khush Shah
  • LS: This command is used for listing contents inside a directory

    It can be called by ls directly or with flags like:

    ls -l Display All Information About Files/Directories

    ls -t Open Last Edited File

    ls -1 One File in Each Line

    ls -h Display File Size in Human Readable Format

    {.preview-image}

  • CAT: This command reads each file parameter in sequence and writes it to standard output.

    It can be called by cat <fileName> directly or with flags like:

    cat -n Number All Output Lines

    cat -b Number Nonempty Output Lines

    cat -s Suppress Repeated Empty Output Lines

    {.preview-image}

  • BAT: bat is a cat clone with Syntax Highlighting and Git Integration.

    To Install Bat on Linux system (with Ubuntu), run command sudo apt install bat.

    It can be called by batcat(in Ubuntu). To check its version run command batcat --version.

    It can be called by batcat <fileName> directly

    {.preview-image}

  • MKDIR: This command is used for creating a new directory.

    It can be called by mkdir <directoryName> directly or with flags like:

    mkdir -v Print a message for each created directory

    {.preview-image}

  • CD: This command is used for changing the current directory.

    It can be called by cd <directoryName> directly to change the directory to the specified directory.

    cd .. (.. as an argument) can be used to change the directory to the parent directory.

    cd (without any argument) can be used to change the directory to the home directory.

    {.preview-image}

  • TOUCH: This command is used for creating a new file.

    touch <fileName>

    {.preview-image}

  • ECHO: This command is used for printing a line of text/string that are passed as an argument.

    echo "This is ECHO command."

    It can also be used to write text to a file by using >(Rewrite) or >>(Append) operator.

    echo "This is a new file." | cat > newFile.txt writes the text "This is a new file." to the newFile.txt file.

    echo "This rewrites the file." | cat > newFile.txt rewrites the newFile.txt file with the text "This rewrites the file."

    echo "This appends a new line in the file." | cat >> newFile.txt appends the text "This appends a new line in the file." to the newFile.txt file.

    {.preview-image}

  • RM: This command is used for deleting a file or directory.

    It can be called by rm <fileName> directly or with flags like:

    rm -v Print a Message for Each Removed File

    rm -i Prompt Before Every Removal

    rm -f Ignore Nonexistent Files and Arguments and Remove Them Forcefully

    rm -d Remove Empty Directories

    rm -r Remove Directories and Their Contents Recursively

    rm -rf Remove Directories and Their Contents Recursively and Forcefully

    {.preview-image}

  • MV: This command is used for moving a file or directory to another location.

    It can be called by mv fileName destinationDirectory directly or with flags like:

    mv -v Print a Message for Each Moved File

    mv -i Prompt Before Overwriting

    mv -f Ignore Nonexistent Files and Arguments and Move Them Forcefully

    mv -n Do Not Overwrite an Existing File

    mv -r Move Directories and Their Contents Recursively

    mv fileName newFileName rename a file/directory

    {.preview-image}

  • CP: This command is used for copying a file or directory to another location.

    It can be called by cp fileName destinationDirectory directly or with flags like:

    cp -v Print a Message for Each Copied File

    cp -i Prompt Before Overwriting

    cp -f Ignore Nonexistent Files and Arguments and Copy Them Forcefully

    cp -n Do Not Overwrite an Existing File

    cp -r Copy Directories and Their Contents Recursively

    {.preview-image}

  • TREE: This command is used for displaying the directory structure in a tree format.

    To Install Tree on Linux system (with Ubuntu), run command sudo apt install tree.

    It can be called by tree(in Ubuntu). To check its version run command tree --version.

    It can be called by tree directly or with flags like:

    tree -a Display All Files and Directories

    tree -d Display Directories Only

    tree -L <level> Display Directory Structure to a Specified Level

    tree -f Display Full Path for Each File

    tree -i Do Not Print Indent Lines

    tree -v SOrt Files and Directories Alphanumerically by Version

    tree -t Sort Files and Directories by Last Modified Time

    tree -h Print the Size of Each File in a Human Readable Format

    tree -Q Quote Each File Name with Double Quotes

    {.preview-image}

  • FIND: This command is used for finding files and directories in a directory hierarchy.

    It can be called by find <directoryName> directly or with flags like:

    find -name <fileName> Find a File by Name

    find -iname <fileName> Find a File by Name (Case Insensitive)

    find -type <fileType> Find a File by Type

    find -empty Find an Empty File or Directory

    {.preview-image}