Mastering Shell Commands On Linux
By Urko Galen
()
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
Related to Mastering Shell Commands On Linux
Related ebooks
Linux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsLinux Commands By Example Rating: 5 out of 5 stars5/5Free Open Source Linux OS For Data Recovery & Data Rescue Bilingual Version Ultimate Rating: 0 out of 5 stars0 ratingsBash Command Line Pro Tips Rating: 5 out of 5 stars5/5Linux Command Line and Shell Scripting Bible Rating: 3 out of 5 stars3/5Easy Linux For Beginners Rating: 2 out of 5 stars2/5Linux: A Comprehensive Guide to Linux Operating System and Command Line Rating: 0 out of 5 stars0 ratingsUbuntu Linux Bible Rating: 0 out of 5 stars0 ratingsThe Linux Command Line Beginner's Guide Rating: 4 out of 5 stars4/5Work with the Command-line: To Manage Files and Directories in Ubuntu Rating: 5 out of 5 stars5/5Linux Shell Scripting Cookbook, Second Edition Rating: 0 out of 5 stars0 ratingsLinux Bible Rating: 0 out of 5 stars0 ratingsLinux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Windows Command Prompt Rating: 0 out of 5 stars0 ratingsI am Linux : Being A Ultra Linux User Rating: 0 out of 5 stars0 ratingsBash for Fun: Bash Programming: Principles and Examples Rating: 0 out of 5 stars0 ratingsLearning Linux Shell Scripting Rating: 4 out of 5 stars4/5Learning Linux Binary Analysis Rating: 4 out of 5 stars4/5Ubuntu Linux Toolbox: 1000+ Commands for Power Users Rating: 4 out of 5 stars4/5Mastering Linux System Administration Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5UNIX for OpenVMS Users Rating: 0 out of 5 stars0 ratingsUNIX Shell Scripting Interview Questions, Answers, and Explanations: UNIX Shell Certification Review Rating: 5 out of 5 stars5/5Debian GNU/Linux : Guide to Installation and Usage Rating: 0 out of 5 stars0 ratingsLPI Linux Certification Questions: LPI Linux Interview Questions, Answers, and Explanations Rating: 4 out of 5 stars4/5Windows Batch File Programming Rating: 2 out of 5 stars2/5
Operating Systems For You
Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Hacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5PowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5The iPadOS 17: The Complete User Manual to Quick Set Up and Mastering the iPadOS 17 with New Features, Pictures, Tips, and Tricks Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5CompTIA Linux+ Study Guide: Exam XK0-004 Rating: 0 out of 5 stars0 ratingsRaspberry Pi Cookbook for Python Programmers Rating: 0 out of 5 stars0 ratingsLinux Bible Rating: 0 out of 5 stars0 ratingsThe Mac Terminal Reference and Scripting Primer Rating: 4 out of 5 stars4/5Learn Windows PowerShell in a Month of Lunches Rating: 0 out of 5 stars0 ratingsWindows 11 For Dummies Rating: 0 out of 5 stars0 ratingsTor Darknet Bundle: Master the Art of Invisibility Rating: 0 out of 5 stars0 ratingsThe Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5Make Your PC Stable and Fast: What Microsoft Forgot to Tell You Rating: 4 out of 5 stars4/5Mastering macOS Programming Rating: 0 out of 5 stars0 ratingsiPhone Unlocked Rating: 0 out of 5 stars0 ratingsWindows Registry Forensics: Advanced Digital Forensic Analysis of the Windows Registry Rating: 4 out of 5 stars4/5Mastering Windows PowerShell Scripting Rating: 4 out of 5 stars4/5Learn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5Linux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Ultimate SwiftUI Handbook for iOS Developers: A complete guide to native app development for iOS, macOS, watchOS, tvOS, and visionOS Rating: 0 out of 5 stars0 ratingsMacs All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsHacking Essentials - The Beginner's Guide To Ethical Hacking And Penetration Testing Rating: 3 out of 5 stars3/5Exploring Windows 10 May 2020 Edition: The Illustrated, Practical Guide to Using Microsoft Windows Rating: 0 out of 5 stars0 ratings
Reviews for Mastering Shell Commands On Linux
0 ratings0 reviews
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