• Root/
  • Linux/
  • Linux tools
  • Most standard tools are non-interactive (use switches and parameters rather than confirming details of operations with user). Some switches are interchangeable, some are mutually exclusive.

    pwd

    Prints path to current working directory

    Switch Shortcut Description
    --logical -L Use PWD from env
    --physical -P Avoid symlinks

    ls

    Lists files and directories

    Command Description Notes
    ls Shows files and directories in current directory
    ls -l Shows files and directories in current directory as a list
    ls -h Shows files and directories in current directory with sizes in human-readable format

    df

    Reports file system disk space usage

    Command Description Notes
    df Disk space usage
    df -h Disk space usage in human-readable format Human-friendly refers to using KB/MB/GB/TB units
    df -i inode usage Programs can't write to filesystem without free inodes
    df -T Disk space usage with file system type
    df -a Include all filesystems, even inaccessible ones

    du

    Reports file system disk usage

    Command Description Notes
    du Disk usage at specific path
    du -c Disk space at specific path - count sums for directories
    du -h Disk space at specific path - display output in human-friendly format For example, KB/MB/GB/TB
    du -s Disk space sum at specific path

    cp

    Copies files/directories

    Command Description Notes
    cp input output Copy file input to output
    cp -r input output Recursively copy files from input to output This switch is commonly used to copy all subdirectories and files within

    mv

    Moves/renames files/directories

    Command Description Notes
    mv input output Move file input to output Moving one file onto another, existing one will overwrite it

    rm

    Removes files/directories

    Command Description Notes
    rm file Removes file ❗ This is irreversible (without data recovery effort)
    rm -r path Removes files recursively in path ❗ Any rm -r command can quickly erase all data on computer. Certain devices might be even broken using this

    grep

    Searches for string in file(s)

    Command Description Notes
    grep string * Find string in files in current directory
    grep -r string * Find string in files in current directory or its subdirectories
    grep -n string * Find string in files in current directory and display line number
    grep -w string * Find whole-word string in files in current directory
    grep -e string * Find regular expression string in files in current directory

    chown

    changes file owner and group

    Command Description Notes
    chown user file Change file owner to user
    chown user:group file Change file owner to user and group to group
    sudo chown -R user directory Change directory owner to user for directory and its subdirectories

    chmod

    changes file permissions

    Permissions are typically noted by 3 numbers; leftmost being user, middle being group and rightmost being others.

    Number on each position is a sum of desired permissions: 4 (read), 2 (write) and 1 (execute).

    Note that directories require execution permission to be opened!

    Command Description Notes
    chmod +x file Make file executable
    chmod 600 file Change file permissions to 600 (owner only read/write)
    chmod -R 600 directory Recursively change files permissions Caution: this will alter directory permission too - directories cannot be opened without executable permission

    find

    Searches for files or directories

    Command Description Notes
    find -name "*string*" -type f Search for file with string in name
    find -name "*string*" -type d Search for directories with string in name

    sudo

    Allows executing other commands as root. Operating as root is considered a bad practice and can lead to system instability - even without any mistakes!

    Command Description Notes
    sudo Shows sudo usage
    sudo cmd Executes cmd as root ❗ Linux allows you to instantly delete/break stuff. Any command ran as root (prefaced with sudo) can have grave consequences
    sudo -u user_name cmd Executes cmd as user named user_name