Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Mastering Shell Commands On Linux
Mastering Shell Commands On Linux
Mastering Shell Commands On Linux
Ebook244 pages1 hour

Mastering Shell Commands On Linux

Rating: 0 out of 5 stars

()

Read preview

About this ebook

This book is a practical guide to Linux commands for beginner and intermediate users.

 

It focuses on essential skills for file and process management, providing step-by-step instructions for manipulating files and directories, managing running processes, and understanding basic terminal commands.

 

The explanations are clear and accompanied by concrete examples for better understanding.

Whether you are a computer science student or a user looking to improve your file management skills, this book is an indispensable tool for learning Linux commands and increasing your efficiency

LanguageEnglish
PublisherUrko GAlen
Release dateMar 11, 2023
ISBN9798215013786
Mastering Shell Commands On Linux

Related to Mastering Shell Commands On Linux

Related ebooks

Operating Systems For You

View More

Related articles

Reviews for Mastering Shell Commands On Linux

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Mastering Shell Commands On Linux - Urko Galen

    Urko Galen

    Mastering Shell Commands On Linux

    Introduction

    This book is intended for beginners and advanced users who wish to learn and deepen their shell skills under Linux.

    It is accessible even if you have no programming or command line experience. We have included practical examples to better understand each command and its options.

    Thank you for accompanying us on this journey to become experts in Linux shell commands.

    Contents

    1      man apropos help: command help

    1.1      Description

    1.2      Example

    2      ls: list files and folders in a directory

    2.1      Description

    2.2      Example

    3      cp: copy files or folders

    3.1      Description

    3.2      Example

    4      mv: moves a file or directory to another location

    4.1      Description

    4.2      Example

    5      rm: delete a file

    5.1      Description

    5.2      Example

    6      ln: create a symbolic link to a file or directory

    6.1      Description

    6.2      Example

    7      cd: change directory

    7.1      Description

    7.2      Example

    8      basename: change directory

    8.1      Description

    8.2      Example

    9      dirname: display the path of the current directory

    9.1      Description

    9.2      Example

    10      mkdir: create a new directory

    10.1      Description

    10.2      Example

    11      rmdir: delete an empty directory

    11.1      Description

    11.2      Example

    12      pwd: display the path of the current directory

    12.1      Description

    12.2      Example

    13      touch: create a new file

    13.1      Description

    13.2      Example

    14      cat: print the contents of one or more files to standard output

    14.1      Description

    14.2      Example

    15      less: view the contents of a file

    15.1      Description

    15.2      Example

    16      head and tail: Displaying a file

    16.1      Description

    16.2      Example

    17      | (pipe)

    17.1      Description

    17.2      Example

    18      grep: search for a specified pattern in a file or standard output

    18.1      Description

    18.2      Example

    18.3      Exercise - corrected

    19      cut: cut and select columns from a file or standard output

    19.1      Description

    19.2      Example

    19.3      Exercise - corrected

    20      Paste: file merge

    20.1      Description

    20.2      Example

    21      tr: convert characters

    21.1      Description

    21.2      Example

    22      sort: sort the lines of a file or standard output

    22.1      Description

    22.2      Example

    22.3      Exercise – corrected

    23      uniq: remove duplicate lines

    23.1      Description

    23.2      Example

    24      tee: redirect output to a file

    24.1      Description

    24.2      Example

    25      sed: changes to a file or standard output

    25.1      Description

    25.2      Example

    25.3      Exercise – corrected

    26      df: Check disk space size

    26.1      Description

    26.2      Example

    26.3      Exercise – corrected

    27      du: Check directory size

    27.1      Description

    27.2      Example

    27.3      Exercise – corrected

    28      uname: System Information

    28.1      Description

    28.2      Example

    29      who – User information

    29.1      Description

    29.2      Example

    30      crontab: Task scheduler

    30.1      Description

    30.2      Example

    31      nohup: Run script in background

    31.1      Description

    31.2      Example

    32      lsof: list the files used by the system

    32.1      Description

    32.2      Example

    32.3      Exercise – corrected

    33      history: list the history of commands

    33.1      Description

    33.2      Example

    34      echo: On-screen display

    34.1      Description

    34.2      Example

    35      tar archive files and/or directories

    35.1      Description

    35.2      Example

    35.3      Exercise – corrected

    36      gzip and gunzip: Archive/Unarchive zip

    36.1      Description

    36.2      Example

    37      zcat: display the contents of a compressed file

    37.1      Description

    37.2      Example

    38      chmod: change permissions of a file or directory

    38.1      Description

    38.2      Example

    39      awk: word processing tool

    39.1      Description

    39.2      Example

    39.3      Exercise – corrected

    40      diff: compare files

    40.1      Description

    40.2      Example

    41      chown: Change owner or group of a file/directory

    41.1      Description

    41.2      Example

    42      alias: create an alias for a command

    42.1      Description

    42.2      Example

    43      free: RAM

    43.1      Description

    43.2      Example

    43.3      Exercise – corrected

    44      kill: Kills a running process

    44.1      Description

    44.2      Example

    45      ps: Displays the list of running processes

    45.1      Description

    45.2      Example

    45.3      Exercise - corrected

    46      top: Shows running processes

    46.1      Description

    46.2      Example

    46.3      Exercise - corrected

    47      find: search for files and directories

    47.1      Description

    47.2      Example

    47.3      Exercise - corrected

    48      xargs: process the output of a command

    48.1      Description

    48.2      Example

    49      locate : locate a file

    49.1      Description

    49.2      Example

    50      wich : locate a binary

    50.1      Description

    50.2      Example

    51      type : command type

    51.1      Description

    51.2      Example

    52      whereis locate file

    52.1      Description

    52.2      Example

    53      Conditions

    53.1      Description

    53.2      Example

    54      For and while loop

    54.1      Description

    54.2      Example

    54.3      Exercise - corrected

    55      regular expression

    55.1      Description

    55.2      Example

    56      Redirects

    56.1      Redirect standard output

    56.2      Redirect standard input

    56.3      Error output redirection

    56.4      Combination of redirects

    57      Mail sending

    57.1      Description

    57.2      Example

    58      Date: Show date

    58.1      Description

    59      Functions

    59.1      Description

    60      Script: set of commands

    60.1      Description

    60.2      Example

    61      The variables :

    61.1      Description

    61.2      Example

    62      wc: count the number of rows

    62.1      Description

    62.2      Example

    63      Ping: test network connectivity

    63.1      Description

    63.2      Example

    64      Join: file join

    64.1      Description

    64.2      Example

    65      copyright notice

    The help command is used to display built-in help for a specific shell command. It provides information about the command's syntax, available options, and a brief description of how it works. This command is especially useful for beginners who want to learn more about a specific command.

    The man command, on the other hand, is a very powerful documentation tool that can display man pages for various Linux commands. These pages provide detailed information about using a command, including examples, available options, and syntax information. It is also possible to search for information about a specific command using the man -k command.

    Finally, the apropos command allows you to search for commands based on their functionality or description. It uses man pages to find matching commands based on specific keywords. This command is very useful when you know the functionality you want to perform, but you don't know the exact command to use.

    In sum, the help command provides built-in help for a specific command, the man command provides extensive documentation for various Linux commands, and the apropos command helps to find commands based on their functionality or description.

    Here are usage examples for the help, man and apropos commands with partial results

    Help command:

    Suppose you want to view help for the Bash shell builtin cd command. You can enter the following command in the terminal:

    help cd

    This command will display information about the cd command syntax, available options, and usage examples. Here is a partial example result:

    cd [-L|[-P [-e]] [-@]] [dir]

    Change the shell working directory.

    Change the current directory to DIR. The default DIR is the value of the HOME shell variable.

    Options:

    -L       force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..'

    -P       use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances of `..'

    -e       if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status

    man command:

    Suppose you want to view the manual for the ls command which is used to list the contents of a directory. You can enter the following command in the terminal:

    man ls

    This command will display detailed information about the ls command, including syntax, available options, and usage examples. Here is a partial example result:

    LS(1) User Commands LS(1)

    NAME

    ls - list directory contents

    SYNOPSIS

    ls [OPTION]... [FILE]...

    DESCRIPTION

    List information about the FILEs (the current directory by default).

    Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

    Mandatory arguments to long options are mandatory for short options too.

    -a, --all

    do not ignore entries starting with .

    -A, --almost-all

    do not list implied . and ..

    --author

    with -l, print the author of each file

    -b, --escape

    print C-style escapes for nongraphic characters

    ...

    apropos command:

    Suppose you are looking for a command that allows you to find files on your system. You can enter the following command in the terminal:

    apropos find

    This command will display a list of all commands and programs that contain the keyword find in their name or description. Here is a partial example result:

    find (1) - search for files in a directory hierarchy

    findmnt (8) - find a filesystem

    fusermount (1) - unmount FUSE filesystems

    gappletviewer-4.8 (1) - Find and execute the appletviewer script

    gfind4 (1) - find files by name or content

    The ls command lists the files and folders in a directory. It displays the contents of a directory (file names, symbolic link folders). It is used with several options to display more details about files and/or folders.

    ls

    This command without options displays the list of files and folders in the current directory.

    -------------------------------

    ls -lh

    Display the list of files and folders in the current directory with additional information, using an alternate display format.

    -------------------------------

    ls -l

    The -l option displays a detailed list of files and folders, including ownership information, size, date modified, etc.

    ls -al

    The -a and -l options combined display a detailed list including hidden files as well.

    -------------------------------

    ls ~/Documents

    This command displays the list of files and folders in the Documents directory which is in your home directory.

    -------------------------------

    ls -R /etc

    The -R option displays a recursive list of all files and folders under /etc.

    The cp command is used to copy files and/or directories from one location to another.

    The syntax of cp is:

    cp [options] source destination

    The most used options:

    • -f as force: replaces the destination file without asking for confirmation, even if it is a symbolic link to a directory.

    • -i like interactive: ask for confirmation before overwriting an existing file.

    • -a:archive: recursively copies all files and subdirectories, as well as symbolic links, permissions, timestamps, etc.

    • -r as recursive: recursively copies all files and subdirectories.

    • -v like verbose: displays detailed information about the copy operations performed.

    cp file1.txt file2.txt

    This command will copy the contents of file file1.txt into file2.txt. The new file will, in this example, be created in the same directory as the source file.

    If the file file2.txt already exists, its content will be replaced by the file file1.txt.

    Without any options on the command, it only copies the contents of the file and not the attributes of the file such as permissions, ownership, modification date, etc.

    -------------------------------

    If you want to copy the file to another directory, specify the full path of the new file: see example below

    cp file.txt /home/user/documents/newfile.txt

    If you want to keep the attributes of the source file when copying, use the -p option with the cp command, like this

    cp -p file1.txt file2.txt

    This will copy file file1.txt

    Enjoying the preview?
    Page 1 of 1