Common Linux Commands

Linux commands are instructions you type into a terminal or shell to interact with the Linux operating system. These commands allow users to perform a variety of tasks, from navigating the file system and managing files to configuring the system and running programs. Linux commands are part of the command-line interface (CLI) and are a fundamental way to control and administer Linux systems.

Informational Class (1XX)

  • ls command

    The ls command lists files and directories.

    ls [options] [path]

    ls /List root directory
    ls ..List parent directory
    ls ~List home directory
    ls -aInclude hidden files
    ls -dOnly directories
    ls --color=always/never/auto
    ls -iList with index number
    ls -lList with long format
    ls -rReverse order
    ls -RRecursively directory tree
    ls -sList file size
    ls -SSort by file size
    ls -XSort by extension name
    ls -laList with long format and hidden files
    ls -lsList with long format and readable file size
    ls -lhList with long format and file size
    ls -ltList with long format and order by datetime

    if you specify a path ls will returns path's content. if you dont specify ls will use current path.

  • pwd command

    The pwd command prints working directory.

    pwd [options]

    pwd -LPrints the symbolic path
    pwd -PPrints the actual path

  • cd command

    The cd command changes working directory in the file system.

    cd [directory]

    cdReturns home directory
    cd ..Moves up directory
    cd -Goes back to the previous directory

  • sudo command

    The sudo command gives root permission for non-root users while running a command.

    sudo [options] command

    -bExecutes in the background.
    -kInvalidates the user's timestamp.
    -pAllows you to customize the password prompt.
    -nAllows to execute command without password prompt.

  • su command

    The su command lets you switch to another user.

    su username

  • whoami command

    The whoami command lets you check current logged in user.

    whoami

  • chmod command

    The chmod command changes the permissions for files or directories.

    chmod [options] [permission] file-or-directory

    Permissions

    rRead Permission
    wWrite Permission
    xExecute permission
    +Add permission
    -Remove permission
    =Set the permissions to the specified values

    Options

    -RApplies the changes as recursively.
    -vDisplays a message for each item processed.
    -cDisplays a message only changes items.

  • chown command

    The chown command changes the ownership of files or directories.

    chown [options] new-owner:new-group file-or-directory

    -cDisplays a message when process is done.
    -vEnables verbose mode.

  • useradd command

    The useradd command creates a new user account.

    useradd [options] new-user

    -pCreates user with a password.
    -uCreates user with a specific user id (UID).
    -gCreates user with a specific group id (GID).
    -MCreates user without a home directory.
    -eCreates user with an expiry date.
    -cCreates user with a comment.

  • passwd command

    The userdel command sets or changes the password.

    passwd new-password

  • userdel command

    The userdel command removes user.

    userdel user-name

  • df command

    The df command checks system disk usage.

    df [options] path

    -aDisplays pseudo, duplicate, and inaccessible file systems.
    -hDisplays human readable format, uses 1024.
    -HDisplays human readable format, uses 1000.
    -lDisplays only local file systems.
    -TDisplays file system type.

  • du command

    The du command checks sizes of directory and its content.

    du [options] path

    -aDisplays with hidden files and directories.
    -hDisplays human readable format.
    -SDisplays only parent directories.

  • top command

    The top command displays all running process.

    top [options]

  • htop command

    The htop command displays all running process.

    htop [options]

  • ps command

    The ps command displays all running process.

    ps [options]

  • kill command

    The kill command terminates a process.

    kill [signal] process-id

    Signals

    SIGHUPIt hangup detected on controlling terminals or death of controlling process.
    SIGINTIt interrupts from keyboard.
    SIGKILLIt kills signal.
    SIGTERMIt terminates signal.

  • shutdown command

    The shutdown command turn off linux system.

    shutdown

  • ping command

    The ping command tests the reachability of a remote server.

    ping [options] remote-server

    -VDisplays ping utility version.
    -cSends number of x packets.
    -sSets packet size.
    -iSets send interval.
    -wSets timeout.

  • wget command

    The wget command downloads file from the internet via HTTP/HTTPS or FPT protpcols.

    wget [options] url

    -vDisplays version.
    -hDisplays available commands.
    -oCreates log file.
    -bRuns in the background.
    -iReads urls from a file.

  • curl command

    The curl command sends or receive data.

    curl [options] url

    -#Displays process.
    --slientSlient mode.
    -XDefines HTTP method like GET, POST.
    -oSave downloaded data to the local.
    -uSets username/password.

  • uname command

    The uname command displays OS information.

    uname [options]

    -aDisplays all available information.
    -sDisplays kernel name.
    -nDisplays network name.

  • hostname command

    The hostname command displays hostname.

    hostname [options]

    -iDisplays ip adress.
    -aDisplays hostname alias.
    -ADisplays fully qualified domain name (FQDN).

  • time command

    The time command displays given command's execution time.

    time command

  • systemctl command

    The systemctl command manages services on the system.

    systemctl command service-name [options]

    Commands

    startStarts a service.
    stopStops a service.
    restartRestarts a service.
    enableEnables a service.
    disableDisables a service.
    reloadReloads a service.
    statusDisplays service status.

  • mkdir command

    The mkdir command creates one or more directories in the file system.

    mkdir [options] directory1 directory2

    mkdir --helpDisplays help.
    mkdir --versionDisplays the version and additional information.
    mkdir --verboseDisplays a message when process done.
    mkdir --pIgnores error message like 'directory already exist'.
    mkdir --m a=rwxGives permission like chmod command.

  • rmdir command

    The rmdir command deletes empty directories in the file system.

    rmdir [options] directory

    rmdir -p directoryForce delete non-empty folders.

    The rmdir command gives exception if the directory doesnt empty. That case you can use -p option.

  • rm command

    The rm command deletes files from a directory.

    rm [options] file1 file2

    rm -r directoryRemoves a folder and it's contents recursively.
    rm -i directoryDisplays a confirmation message before remove.
    rm -f directoryDeactivate the confirmation message.

  • cp command

    The cp command copy files from a directory to another directory.

    cp /source-path/file /target-path/file

    cp -R /source-path /target-pathCopy source direstory to target directory with all content.

  • mv command

    The mv command move files from a directory to another directory.

    mv /source-path/file /target-path/file

  • cat command

    The cat command has a few usages.

    cat file.txt

    Printing content of the file.

    cat > file.txt

    Printing standart output into the file.

    cat file1.txt file2.txt > target.txt

    Concatenate the files into the single file.

  • grep command

    The grep (Global Regular Expression Print) command using for searching text with a specific pattern in the text files.

    grep [options] pattern file.txt

    -cDisplays how many count of the lines matched with specific pattern.
    -hDisplays matched lines without filename.
    -iIgnores case insensitive.
    -lDisplays list of filenames.
    -nDisplays matched lines with line number.
    -vDisplays not matched lines.
    -eSpecifies expression.
    -fTakes patterns from a file.
    -wMatch whole word.
    -oDisplays only the matched parts of the line.

  • sed command

    The sed command using for searching and replacing patterns in the text files.

    sed [options] 'command/current-pattern/new-pattern' file.txt

    -iUpdates the file without printing.
    -nPrints only updated lines.
    -eAllows multiple commands.
    -fTakes commands from a file.
    -rEnables regular expression.

  • awk command

    The awk command using for searching and replacing regular expression patterns in the text files.

    awk '/regex patters/{action}' file.txt

  • sort command

    The sort command rearrange a file's content in a specific order.

    sort [options] file.txt

    -oSpecifies an output file for the rearranged data.
    -rSorts Reverse order.
    -nSorts by number.
    -cChecks file already sorted.
    -uSorts and removed duplicated lines.
    -MSorts by month names.

  • cut command

    The cut command displays specific section from a file.

    cut [options] file.txt

    -bSelects only the specified bytes in the list.
    -cSelects only the specified characters in the list.
    -dSets delimiter.
    -fSelects only the specified fields in the list.

  • diff command

    The diff command displays differences from two files.

    diff [options] file1.txt file2.txt

    -cDifferences in context mode.
    -uDifferences in unified mode.
    -i or --ignore-caseIgnores case insensitive comparison.
    -ignore-all-spaceIgnores white spaces.
    -briefDisplays only files differ or not.
    -recursiveRecursively compare directories.
    -y or --side-by-sideDisplays in a side-by-side.

  • head command

    The head command displays top x lines of the text files.

    head [options] file.txt

    -nDisplays number of lines.
    -cDisplays number of bytes.
    -qDisplays multiple files without quit.
    -vEnables verbose mode.

  • tee command

    The tee command captures standart inputs and write it both standart output and file.

    tee [options] file.txt

    -aAppends the file.

  • locate command

    The locate command searches files and displays its path.

    locate [options] search-keyword

    -rAllows use regex for search keyword.
    -iAllows turn off case insensitive.

  • find command

    The find command searches files with a specific path.

    find /path [options] expression

    -name patternSearches for specific name or pattern.
    -type typeSearches for specified types like f for files and d for directories.
    -size [+/-]nSearches for size like +n finds larger files and -n smaller files.
    -exec command {} \;Executes specific command on each founded file.
    -emptySearches for empty file and folders.
    -deleteDeletes files for matched.

  • tail command

    The tail command displays last x lines of the text files.

    tail [options] file.txt

    -nDisplays number of lines.
    -cDisplays number of bytes.
    -qDisplays multiple files without quit.
    -vEnables verbose mode.
    -fEnables follow file changes.

  • file command

    The file command checks a file's type like txt, sh or other.

    file file.txt

  • touch command

    The touch command creates one or more empty files.

    touch file.txt

    touch -a file.txtChanges the access time.
    touch -c file.txtDeny to creation if it's not exist.
    touch -d file.txtChanges modified time.
    touch -m file.txtChanges the modified time.

  • vim command

    The vim command creates or edit text files.

    vim file.txt

    Opens given file name as edit mode if file exist. If file doesn't exists created an empty one. Vim has lot of command inside the editor like save changes (:w), quit edior (:q).

  • nano command

    The nano command creates or edit text files.

    nano file.txt

    Nano is a text editor and it has specific command.

  • zip command

    The zip command compresses one or multiple files and creates zip file.

    zip [options] file.zip file.txt

    zip -d file.zip file.txtAllows you to remove specific file from a zip file.
    zip -u file.zip file.txtAllows you to update specific file from a zip file.
    zip -m file.zip file.txtAllows you to move specific file from a zip file.
    zip -r directory.zip /directoryAllows you to recursively zip a directory.
    zip -r file.zip -x file.txtAllows you to exclude specific files from being included in the zip archive.
    zip -v directory.zip /directoryEnables verbose mode.

  • unzip command

    The unzip command extract a compressed zip file into a folder.

    unzip file.zip

  • tar command

    The tar command bundles multiple files or directories into an archive without compression or with gzip or bzip2 compression.

    tar [options] file.tar file1.txt file2.txt

    -cCreates an archive file from files or directories
    -xExtract files and directories from an exist archive.
    -fSpecifies the filename of the archive.
    -tDisplays files and directories from an archive.
    -uAdds new files or directories to an exist archive.
    -rAdds new files or directories to an exist archive without recreating the entire archive.
    -vEnables verbose mode.
    -AConcatenates two or more archive files into a archive.
    -zUses gzip compression.
    -jUses bzip2 compression.
    -WVerifies archive file if content is corrupted or not.