Day 2 of #90DaysOfDevOps

Basavaraj TeliBasavaraj Teli
3 min read

Basics linux commands

  1. sudo - Stands for Super User Do. The sudo command allows you to run commands with the superuser privileges.

  2. whoami - Displays currently logged-in user.

  3. cat - File concatenation and printing are done using the cat command.

    cat <file-name> - displays the contents of the file.

    cat > <file-name> - creates a new file, allows to input content interactively and redirects inputted content to the created file (> redirection operator).

  4. echo - displaying lines of text or string which are passed as arguments on the command line. Can be used to create a file or empty a file.

    echo "Hello" - prints Hello

    echo "Hello" > hello.txt - Creates a file hello.txt with Hello as content in it.

    echo "World" >> hello.txt - appends the content(World) to the file hello.txt

    echo > hello.txt - Empties the content from hello.txt file.

  5. pwd - shows the present working directory (abbr. Print Working Directory).

  6. mkdir - make directory.

    mkdir <dir> - creates the directory.

    mkdir -p /A/B/C/D - creates directories (/A/B/C/D) with its parent directories if it does not exists (-p parent).

  7. ls - list files or directories

    ls -a - list all hidden files and directories

    ls -altrh - lists all files & folders along with hidden files in a formatted manner

    -a all

    -l long listing format

    -t sort by time, newest first

    -r reverse order while sorting

    -h --human-readable with -l and -s, print sizes like 1K 234M 2G etc.

  8. touch - creates an empty file or updates timestamp of the existing file.

    touch <file-name> - creates a single empty file named <file-name>.

    touch -a <file-name> - change only the access time

    touch -m <file-name> - change only the modification time

  9. stat - Display file or file system status. It will display file size and timestamp (access, modify, and change time)

  10. head <file-name> - displays first 10 lines of the file by default.

    head -n 5 <file-name> - displays first 5 lines of the file (-n number).

    head -n -5 <file-name> - print all but the last 5 lines of the file.

  11. tail <file-name> - displays last 10 lines of the file by default.

    tail -n 5 <file-name> OR tail -n -5 <file-name> - displays last 5 lines of the file (-n number).

    tail -n +5 <file-name> - print all lines starting from the line 5.

  12. sort - The sort command sorts the contents of a file, in numeric or alphabetic order, and prints the results to standard output.

    -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)

    -n, --numeric-sort compare according to string numerical value

    -r, --reverse reverse the result of comparisons

  13. rm - remove command.

    rm <file-name> - removes the file.

    rm -d <dir-name> - removes empty directory .

    rm -r <dir-name> - removes files & directories recursively from a directory (-r, -R, --recursive remove directories and their contents recursively).

    rm -rf - force remove the files & directories recursively from a directory (-f force).

  14. cp - copy command.

    cp <src-file/dir> <dest-file/dir> - copy the files and directories from source to destination.

    cp -rp <dir1> <dir2> - copy dir1 directory to dir2 directory recursively

    -r recursive

    -p same as --preserve=mode,ownership,timestamps

  15. mv - move or rename command.

    mv <old-filename> <new-filename> - renames the file to new name.

    mv <filename> <dirname> - moves the file to the directory.

0
Subscribe to my newsletter

Read articles from Basavaraj Teli directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Basavaraj Teli
Basavaraj Teli

Aspiring DevOps engineer, working on DevOps projects to gain practical knowledge. I write technical blog post on DevOps to share my knowledge with fellow tech enthusiasts.