reworking content
All checks were successful
learn org at code.softwareshinobi.com/linux.softwareshinobi.com/pipeline/head This commit looks good

This commit is contained in:
2025-06-19 10:03:08 -04:00
parent 611d0816cc
commit 7d9171c854
192 changed files with 2234 additions and 2362 deletions

View File

@@ -0,0 +1,57 @@
# The `gunzip` command
The `gunzip` command is an antonym command of [`gzip` command](015-the-gzip-command.md). In other words, it decompresses files deflated by the `gzip` command.
`gunzip` takes a list of files on its command line and replaces each file whose name ends with _.gz_, _-gz_, _.z_, _-z_, or *\_z* (ignoring case) and which begins with the correct magic number with an uncompressed file without the original extension. `gunzip` also recognizes the special extensions *.tgz* and *.taz* as shorthands for *.tar.gz* and *.tar.Z* respectively.
### Examples:
1. Uncompress a file
```
gunzip filename.gz
```
2. Recursively uncompress content inside a directory, that match extension (suffix) compressed formats accepted by `gunzip`:
```
gunzip -r directory_name/
```
3. Uncompress all files in the current/working directory whose suffix match *.tgz*:
```
gunzip -S .tgz *
```
4. List compressed and uncompressed sizes, compression ratio and uncompressed name of input compressed file/s:
```
gunzip -l file_1 file_2
```
### Syntax:
```
gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]
```
### Video tutorial about using gzip, gunzip and tar commands:
[This video](https://www.youtube.com/watch?v=OBtG8zfVwuI) shows how to compress and decompress in a Unix shell. It uses `gunzip` as decompression command.
### Additional Flags and their Functionalities:
|**Short Flag**|**Long Flag**|**Description**|
|:---|:---|:---|
|-c|--stdout|write on standard output, keep original files unchanged|
|-h|--help|give help information|
|-k|--keep|keep (don't delete) input files|
|-l|--list|list compressed file contents|
|-q|--quiet|suppress all warnings|
|-r|--recursive|operate recursively on directories|
|-S|--suffix=SUF|use suffix SUF on compressed files|
||--synchronous|synchronous output (safer if system crashes, but slower)|
|-t|--test|test compressed file integrity|
|-v|--verbose|verbose mode|
|-V|--version|display version number|

View File

@@ -0,0 +1,96 @@
# The `gzip` command
The `gzip` command in Linux/Unix is used to compress/decompress data.
# Usage
## Compress a file
**Action:**
--- Compressing a file
**Details:**
--- Reduce the size of the file by applying compression
**Command:**
```
gzip file_name
```
## Decompress a file
**Action:**
--- Decompressing a file
**Details:**
--- Restore the file's original form in terms of data and size
**Command:**
```
gzip -d archive_01.gz
```
## Compress multiple files:
**Action:**
--- Compress multiple files
**Details:**
--- Compress multiple files into multiple archives
**Command:**
```
gzip file_name_01 file_name_02 file_name_03
```
## Decompress multiple files:
**Action:**
--- Decompress multiple files
**Details:**
--- Decompress multiple files from multiple archives
**Command:**
```
gzip -d archive_01.gz archive_02.gz archive_03.gz
```
## Compress a directory:
**Action:**
--- Compress all the files in a directory
**Details:**
--- Compress multiple files under a directory in one single archive
**Command:**
```
gzip -r directory_name
```
## Decompress a directory:
**Action:**
--- Decompress all the files in a directory
**Details:**
--- Decompress multiple files under a directory from one single archive
**Command:**
```
gzip -dr directory_name
```
## Verbose (detailed) output while compressing:
**Action:**
--- Compress a file in a more verbose manner
**Details:**
--- Output more information about the action of the command
**Command:**
```
gzip -v file_name
```

View File

@@ -0,0 +1,76 @@
# The `tar` command
The `tar` command stands for tape archive, is used to create Archive and extract the Archive files. This command provides archiving functionality in Linux. We can use tar command to create compressed or uncompressed Archive files and also maintain and modify them.
### Examples:
1. To create a tar file in abel directory:
```
tar -cvf file-14-09-12.tar /home/abel/
```
2. To un-tar a file in the current directory:
```
tar -xvf file-14-09-12.tar
```
### Syntax:
```
tar [options] [archive-file] [file or directory to be archived
```
### Additional Flags and their Functionalities:
|**Use Flag** |**Description** |
|:---|:---|
|`-c`|Creates Archive |
|`-x`|Extract the archive |
|`-f`|Creates archive with given filename|
|`-t`|Displays or lists files in archived file |
|`-u`|Archives and adds to an existing archive file|
|`-v`|Displays Verbose Information |
|`-A`|Concatenates the archive files |
|`-z`|zip, tells tar command that creates tar file using gzip |
|`-j`|Filter archive tar file using tbzip |
|`w`|Verify a archive file |
|`r`|update or add file or directory in already existed .tar file |
|`-?`|Displays a short summary of the project |
|`-d`|Find the difference between an archive and file system |
|`--usage`|shows available tar options |
|`--version`|Displays the installed tar version |
|`--show-defaults`|Shows default enabled options |
|**Option Flag** |**Description** |
|:---|:---|
|`--check-device`| Check device numbers during incremental archive|
|`-g`|Used to allow compatibility with GNU-format incremental ackups|
|`--hole-detection`|Used to detect holes in the sparse files|
|`-G`| Used to allow compatibility with old GNU-format incremental backups|
|`--ignore-failed-read`|Don't exit the program on file read errors|
|`--level`|Set the dump level for created archives|
|`-n`|Assume the archive is seekable|
|`--no-check-device`|Do not check device numbers when creating archives|
|`--no-seek`|Assume the archive is not seekable|
|`--occurrence=N`|`Process only the Nth occurrence of each file|
|`--restrict`|`Disable use of potentially harmful options|
|`--sparse-version=MAJOR,MINOR`|Set version of the sparce format to use|
|`-S`|Handle sparse files efficiently.|
|**Overwright control Flag** |**Description**|
|:---|:---|
|`-k`|Don't replace existing files|
|`--keep-newer-files`|Don't replace existing files that are newer than the archives version|
|`--keep-directory-symlink`|Don't replace existing symlinks|
|`--no-overwrite-dir`|Preserve metadata of existing directories|
|`--one-top-level=DIR`|Extract all files into a DIR|
|`--overwrite`| Overwrite existing files|
|`--overwrite-dir`| Overwrite metadata of directories|
|`--recursive-unlink`| Recursivly remove all files in the directory before extracting|
|`--remove-files`| Remove files after adding them to a directory|
|`--skip-old-files`| Don't replace existing files when extracting|
|`-u`| Remove each file before extracting over it|
|`-w`| Verify the archive after writing it|

View File

@@ -0,0 +1,44 @@
# The `unzip` command
The `unzip` command extracts all files from the specified ZIP archive to the current directory.
### Examples:
In order to extract the files the syntax would be the following:
```
unzip myZipFile.zip
```
To unzip a ZIP file to a different directory than the current one, don't forget to add the `-d` flag:
```
unzip myZipFile.zip -d /path/to/directory
```
To unzip a ZIP file and exclude specific file or files or directories from being extracted, don't forget to add the `-x` flag:
```
unzip myZipFile.zip -x file1.txt file2.txt
```
### Syntax:
```
unzip zipFileName [OPTION] [PARAMS]
```
### Possible options:
|**Flag** |**Description** |**Params** |
|:---|:---|:---|
|`-d`|Unzip an archive to a different directory.|/path/to/directory|
|`-x`|Extract the archive but do not extract the specified files.|filename(s)|
|`-j`|Unzip without creating new folders, if the zipped archive contains a folder structure.|-|
|`-l`|Lists the contents of an archive file without extracting it.|-|
|`-n`|Do not overwrite existing files; supply an alternative filename instead.|-|
|`-o`|Overwrite files.|-|
|`-P`|Supplies a password to unzip a protected archive file.|password|
|`-q`|Unzips without writing status messages to the standard output.|-|
|`-t`|Tests whether an archive file is valid.|-|
|`-v`|Displays detailed (verbose) information about the archive without extracting it.|-|

View File

@@ -0,0 +1,41 @@
# The `zip` command
The `zip` command is used to compress files and reduce their size.
It outputs an archive containing one or more compressed files or directories.
### Examples:
In order to compress a single file with the `zip` command the syntax would be the following:
```
zip myZipFile.zip filename.txt
```
This also works with multiple files as well:
```
zip multipleFiles.zip file1.txt file2.txt
```
If you are compressing a whole directory, don't forget to add the `-r` flag:
```
zip -r zipFolder.zip myFolder/
```
### Syntax:
```
zip [OPTION] zipFileName filesList
```
### Possible options:
|**Flag** |**Description** |
|:---|:---|
|`-d`|Removes the file from the zip archive. After creating a zip file, you can remove a file from the archive using the `-d` option|
|`-u`|Updates the file in the zip archive. This option can be used to update the specified list of files or add new files to the existing zip file. Update an existing entry in the zip archive only if it has been modified more recently than the version already in the zip archive.|
|`-m`|Deletes the original files after zipping.|
|`-r`|To zip a directory recursively, it will recursively zip the files in a directory. This option helps to zip all the files present in the specified directory.|
|`-x`|Exclude the files in creating the zip|
|`-v`|Verbose mode or print diagnostic version info. Normally, when applied to real operations, this option enables the display of a progress indicator during compression and requests verbose diagnostic info about zip file structure oddities|

View File

@@ -0,0 +1,58 @@
# The `alias` command
The `alias` command lets you create shortcuts for commands or define your own commands.
This is mostly used to avoid typing long commands.
### Examples:
1. To show the list of all defined aliases in the reusable form `alias NAME=VALUE` :
```
alias -p
```
2. To make `ls -A` shortcut:
```
alias la='ls -A'
```
### Syntax:
```
alias [-p] [name[=value]]
```
### Setting Persistent Options:
As with most Linux custom settings for the terminal, any alias you defined is only applied to the current opening terminal session.
For any alias to be active for all new sessions you need to add that command to your rc file to be executed in the startup of every new terminal.
this file can be as follows:
- **Bash**: ~/.bashrc
- **ZSH**: ~/.zshrc
- **Fish** ~/.config/fish/config.fish
you can open that file with your favorite editor as follows:
```
vim ~/.bashrc
```
type your commands one per line, then save the file and exit.
the commands will be automatically applied in the next session.
If you want to apply it in the current session, run the following command:
```
source ~/.bashrc
```
### Opposite command:
To remove predefined alias you can use `unalias` command as follows:
```
unalias alias_name
```
to remove all aliases
```
unalias -a
```

View File

@@ -0,0 +1,56 @@
# The `cd` command
The `cd` command is used to change the current working directory *(i.e., in which the current user is working)*. The "cd" stands for "**c**hange **d**irectory" and it is one of the most frequently used commands in the Linux terminal.
The `cd` command is often combined with the `ls` command (see chapter 1) when navigating through a system, however, you can also press the `TAB` key two times to list the contents of the new directory you just changed to.
### Examples of uses:
1. Change the current working directory:
```
cd <specified_directory_path>
```
2. Change the current working directory to the home directory:
```
cd ~
```
OR
```
cd
```
3. Change to the previous directory:
```
cd -
```
This will also echo the absolute path of the previous directory.
4. Change the current working directory to the system's root directory:
```
cd /
```
### &#x1F4A1; Quick Tips
Adding a `..` as a directory will allow you to move "up" from a folder:
```
cd ..
```
This can also be done multiple times! For example, to move up three folders:
```
cd ../../../
```
### Syntax:
```
cd [OPTIONS] directory
```
### Additional Flags and Their Functionalities
|**Short flag** |**Long flag** |**Description** |
|:---|:---|:---|
|`-L`|<center>-</center>|Follow symbolic links. By default,`cd` behaves as if the `-L` option is specified.|
|`-P`|<center>-</center>|Dont follow symbolic links.|

View File

@@ -0,0 +1,30 @@
# The `clear` command
In linux, the `clear` command is used to clear terminal screen.
## Example
```bash
$ clear
```
## Before:
```bash
$ echo Hello World
Hello World
$ clear
```
## After executing clear command:
```bash
$
```
Screenshot:
![clear command in linux example](https://user-images.githubusercontent.com/21223421/135708520-5fb54205-39ce-4e9c-b376-7569d0c4420d.png)
After running the command your terminal screen will be clear:
![clear command in linux](https://user-images.githubusercontent.com/21223421/135708538-f01de268-3cf6-4f3a-a32b-a14fb67575f1.png)

View File

@@ -0,0 +1,45 @@
# The `echo` command
The `echo` command lets you display the line of text/string that is passed as an argument
### Examples:
1. To Show the line of text or string passed as an argument:
```
echo Hello There
```
2. To show all files/folders similar to the `ls` command:
```
echo *
```
3. To save text to a file named foo.bar:
```
echo "Hello There" > foo.bar
```
4. To append text to a file named foo.bar:
```
echo "Hello There" >> foo.bar
```
### Syntax:
```
echo [option] [string]
```
#### It is usually used in shell scripts and batch files to output status text to the screen or a file.The `-e` used with it enables the interpretation of backslash escapes
### Additional Options and their Functionalities:
|**Option** |**Description** |
|:---|:---|
|`\b`|removes all the spaces in between the text|
|`\c`|suppress trailing new line with backspace interpretor -e to continue without emitting new line.|
|`\n`|creates new line from where it is used|
|`\t`|creates horizontal tab spaces|
|`\r`|carriage returns with backspace interpretor -e to have specified carriage return in output|
|`\v`|creates vertical tab spaces|
|`\a`|alert returns with a backspace interpretor -e to have sound alert|
|`-n`|omits echoing trailing newline .|

View File

@@ -0,0 +1,41 @@
# The `env` command
The `env` command in Linux/Unix is used to either print a list of the current environment variables or to run a program in a custom environment without changing the current one.
## Syntax
```bash
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
```
## Usage
1. Print out the set of current environment variables
```bash
env
```
2. Run a command with an empty environment
```bash
env -i command_name
```
3. Remove variable from the environment
```bash
env -u variable_name
```
4. End each output with NULL
```bash
env -0
```
## Full List of Options
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-i`|`--ignore-environment`|Start with an empty environment|
|`-0`|`--null`|End each output line with NUL, not newline|
|`-u`|`--unset=NAME `|Remove variable from the environment|
|`-C`|`--chdir=DIR`|Change working directory to DIR|
|`-S`|`--split-string=S`|Process and split S into separate arguments. It's used to pass multiple arguments on shebang lines|
|`-v`|`--debug`|Print verbose information for each processing step|
|-|`--help`|Print a help message|
|-|`--version`|Print the version information|

View File

@@ -0,0 +1,10 @@
# The `exit` command
The `exit` command is used to terminate (close) an active shell session
### Syntax:
```
exit
```
***Shortcut:** Instead of typing `exit`, press `ctrl + D`, it will do the same Functionality.*

View File

@@ -0,0 +1,19 @@
# The `history` command
If you type `history` you will get a list of the last 500 commands used. This gives you the possibility to copy and paste commands that you executed in the past.
This is powerful in combination with grep. So you can search for a command in your command history.
### Examples:
1. If you want to search in your history for artisan commands you ran in the past.
```
history | grep artisan
```
2. If you only want to show the last 10 commands you can.
```
history 10
```

View File

@@ -0,0 +1,45 @@
# The `less` command
The less command is a Linux terminal pager which shows a file's content one screen at a time.
Useful when dealing with a large text file because it doesn't load the entire file but accesses it page by page, resulting in fast loading speeds.
## Syntax
```
less [options] file_path
```
## Options
Some popular option flags include:
```
-E less automatically exits upon reaching the end of file.
-f Forces less to open non-regular files (a directory or a device-special file).
-F Exit less if the entire file can be displayed on the first screen.
-g Highlights the string last found using search. By default, less highlights all strings matching the last search command.
-G Removes all highlights from strings found using search.
```
For a complete list of options, refer to the less help file by running:
```
less --help
```
## Few Examples:
1. Open a Text File
```
less /etc/updatedb.conf
```
2. Show Line Numbers
```
less -N /etc/init/mysql.conf
```
3. Open File with Pattern Search
```
less -pERROR /etc/init/mysql.conf
```
4. Remove Multiple Blank Lines
```
less welcome.txt
```
Here I showed you how to use the less command in Linux. Although there are other terminal pagers, such as most and more, but less could be a better choice as it is a powerful tool present in almost every system.
For more details: https://phoenixnap.com/kb/less-command-in-linux#:~:text=The%20less%20command%20is%20a,resulting%20in%20fast%20loading%20speeds.

View File

@@ -0,0 +1,39 @@
# The `man` command
The `man` command is used to display the manual of any command that we can run on the terminal.
It provides information like: DESCRIPTION, OPTIONS, AUTHORS and more.
### Examples:
1. Man page for printf:
```
man printf
```
2. Man page section 2 for intro:
```
man 2 intro
```
3. Viewing the Manual for a Local File (using the -l flag):
```
man -l [LOCAL-FILE]
```
### Syntax:
```
man [SECTION-NUM] [COMMAND NAME]
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-f`|<center>-</center>|Return the sections of an command|
|`-a`|<center>-</center>|Display all the manual pages of an command|
|`-k`|<center>-</center>|Searches the given command with RegEx in all man pages|
|`-w`|<center>-</center>|Returns the location of a given command man page|
|`-I`|<center>-</center>|Searches the command manual case sensitive|

View File

@@ -0,0 +1,40 @@
# The `pwd` command
The `pwd` stands for Print Working Directory. It prints the path of the current working directory, starting from the root.
Example:
```
pwd
```
The output would be your current directory:
```
/home/your_user/some_directory
```
Syntax:
```
pwd [OPTION]
```
Tip:
You can also check this by printing out the `$PWD` variable:
```
echo $PWD
```
The output would be the same as of the `pwd` command.
### Options:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
| `-L` | `--logical` | If the environment variable $PWD contains an absolute name of the current directory with no "." or ".." components, then output those contents, even if they contain symbolic links. Otherwise, fall back to default (-P) behavior. |
| `-P`| `--physical` | Print a fully resolved name for the current directory, where all components of the name are actual directory names, and not symbolic links. |
| ` ` | `--help`| Display a help message, and exit. |
| ` ` | `--version`| Display version information, and exit. |
By default, `pwd' behaves as if `-L' were specified.

View File

@@ -0,0 +1,31 @@
# The `sleep` command
The `sleep` command is used to create a dummy job. A dummy job helps in delaying the execution. It takes time in seconds by default but a small suffix(s, m, h, d) can be added at the end to convert it into any other format. This command pauses the execution for an amount of time which is defined by NUMBER.
Note: If you will define more than one NUMBER with sleep command then this command will delay for the sum of the values.
### Examples :
1. To sleep for 10s
```
sleep 10s
```
2. A more generalized command:
```
sleep NUMBER[SUFFIX]...
```
## Options
It accepts the following options:
1. --help
> display this help and exit
2. --version
> output version information and exit
---

View File

@@ -0,0 +1,29 @@
# The `whereis` command
The `whereis` command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux system. If we compare `whereis` command with find command they will appear similar to each other as both can be used for the same purposes but `whereis` command produces the result more accurately by consuming less time comparatively.
#### Points to be kept on mind while using the whereis command:
Since the `whereis` command uses chdir(change directory 2V) to give you the result in the fastest possible way, the pathnames given with the -M, -S, or -B must be full and well-defined i.e. they must begin with a `/` and should be a valid path that exist in the systems directories, else it exits without any valid result.
`whereis` command has a hard-coded(code which is not dynamic and changes with specification) path, so you may not always find what youre looking for.
### Syntax
```
whereis [options] [filename]
```
### Options
-b : This option is used when we only want to search for binaries.
-m : This option is used when we only want to search for manual sections.
-s : This option is used when we only want to search for source files.
-u: This option search for unusual entries. A source file or a binary file is said to be unusual if it does not have any existence in system as per [-bmsu] described along with “u”. Thus `whereis -m -u * asks for those files in the current directory which have unsual entries.
-B : This option is used to change or otherwise limit the places where whereis searches for binaries.
-M : This option is used to change or otherwise limit the places where whereis searches for manual sections.
-S : This option is used to change or otherwise limit the places where whereis searches for source files.
-f : This option simply terminate the last directory list and signals the start of file names. This must be used when any of the -B, -M, or -S options are used.
-V: Displays version information and exit.
-h: Displays the help and exit.

View File

@@ -0,0 +1,25 @@
# The `yes` command
The `yes` command in linux is used to print a continuous output stream of given _STRING_. If _STRING_ is not mentioned then it prints y. It outputs a string repeatedly unit killed (using something like ctrl + c).
### Examples :
1. Prints hello world infinitely in the terminal until killed :
```
yes hello world
```
2. A more generalized command:
```
yes [STRING]
```
## Options
It accepts the following options:
1. --help
> display this help and exit
2. --version
> output version information and exit

View File

@@ -0,0 +1,50 @@
# The `fdisk` command
The `fdisk` command is used for controlling the disk partition table and making changes to it and this is a list of some of options provided by it : </b>
- Organize space for new drives.
- Modify old drives.
- Create space for new partitions.
- Move data to new partitions.
### Examples:
1. To view basic details about all available partitions on the system:
```
fdisk -l
```
2. To show the size of the partition:
```
fdisk -s /dev/sda
```
3. To view the help message and all options of the command:
```
fdisk -h
```
### Syntax:
```
fdisk [options] device
```
### Some of the command options:
On writing the following command
```
fdisk /dev/sdb
```
the following window appears :
![Options](https://media.geeksforgeeks.org/wp-content/uploads/20190219152451/Screenshot-711.png)
and then you type m which will show you all options you need such as creating new partition and deleting a partition as in the following picture :
![Options](https://media.geeksforgeeks.org/wp-content/uploads/20190219153114/Screenshot-741.png)

View File

@@ -0,0 +1,44 @@
# The `mount` command
The `mount` command is used to mount 'attach' a filesystem and make it accessible by an existing directory structure tree.
### Examples:
1. Displays version information:
```
mount -V
```
2. Attaching filesystem found on device and of type type at the directory dir:
```
mount -t type device dir
```
### Syntax Forms:
```
mount [-lhV]
```
```
mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
```
```
mount [-fnrsvw] [-t fstype] [-o options] device dir
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-h`|<center>`--help`</center>|Dispaly a help message and exists|
|`-n`|<center>`--no-mtab`</center>|Mount without writing in /etc/mtab|
|`-a`|<center>`--all`</center>|Mount all filesystems (of the given types) mentioned in fstab|
|`-r`|`--read-only`|Mount the filesystem read-only|
|`-w`|`--rw`|Mount the filesystem as read/write.|
|`-M`|`--move`|Move a subtree to some other place.|
|`-B`|`--bind`|Remount a subtree somewhere else *(so that its contents are available in both places)*.|

View File

@@ -0,0 +1,75 @@
# The `parted` command
The `parted` command is used to manage hard disk partitions on Linux. It can be used to add, delete, shrink and extend disk partitions along with the file systems located on them.
You will need root access to the system to run `parted` commands.
**NOTE:** Parted writes the changes immediately to your disk, be careful when you are modifying the disk partitions.
### Examples:
1. Displays partition layout of all block devices:
```
sudo parted -l
```
2. Display partition table of a specific `disk`
```
sudo parted disk print
```
Examples of `disk` are /dev/sda, /dev/sdb
3. Create a new disk label of `label-type` for a specific disk
```
sudo parted mklabel disk label-type
```
`label-type` can take values "aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac", "msdos", "pc98", or "sun" <br />
4. Create a new partition in a specific `disk` of type `part-time`, file system is `fs-type` and of size `size` Mb.
```
sudo parted disk mkpart part-time fs-type 1 size
```
`part-time` can take values "primary", "logical", "extended".<br />
`fs-type` is optional. It can take values "btrfs", "ext2", "ext3", "ext4", "fat16", "fat32", "hfs", "hfs+", "linux-swap", "ntfs", "reiserfs", "udf", or "xfs"<br />
`size` has to less than the total size of the specified disk. To create a partition of size 50Mb, <size> will take the value of 50
5. `parted` can also be run in an interactive format. Operations to manage the disk partitions can be performed by entering appropriate commands in the interactive session.
`help` command in the interactive session shows a list of all possible disk management operations which can be performed.
```
$ sudo parted
GNU Parted 3.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print # prints the partition table of the default selected disk - /dev/sda
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 53.7GB 53.7GB primary ext4 boot
(parted) select /dev/sdb # change the current disk on which operations have to be performed
Using /dev/sdb
(parted) quit # exit the interactive session
```
### Syntax Forms:
```
parted [options] [device [command [options...]...]]
```
### Options:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|-h|--help|displays a help message listing all possible `commands [options]`|
|-l|--list|lists partition layout on all block devices|
|-m|--machine|displays machine parseable output|
|-v|--version|displays the version|
|-a|--align|set alignment type for newly created partition. It can take the following values:<br /> `none`: Use the minimum alignment allowed by the disk type<br /> `cylinder`: Align partitions to cylinders<br /> `minimal`: Use minimum alignment as given by the disk topology information<br /> `optimal`: Use optimum alignment as given by the disk topology information|

View File

@@ -0,0 +1,153 @@
# The `cat` command
---
The `cat` command allows us to create single or multiple files, to view the content of a file or to concatenate files and redirect the output to the terminal or files.
The "cat" stands for 'concatenate.' and it's one of the most frequently used commands in the Linux terminal.
### Examples of uses:
1. To display the content of a file in terminal:
```
cat <specified_file_name>
```
2. To display the content of multiple files in terminal:
```
cat file1 file2 ...
```
3. To create a file with the cat command:
```
cat > file_name
```
4. To display all files in current directory with the same filetype:
```
cat *.<filetype>
```
5. To display the content of all the files in current directory:
```
cat *
```
6. To put the output of a given file into another file:
```
cat old_file_name > new_file_name
```
7. Use cat command with `more` and `less` options:
```
cat filename | more
cat filename | less
```
8. Append the contents of file1 to file2:
```
cat file1 >> file2
```
9. To concatenate two files together in a new file:
```
cat file1_name file2_name merge_file_name
```
10. Some implementations of cat, with option -n, it's possible to show line numbers:
```
cat -n file1_name file2_name > new_numbered_file_name
```
### Syntax:
```
cat [OPTION] [FILE]...
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-A`| `--show-all` |equivalent to -vET|
|`-b`| `--number-nonblank` |number nonempty output lines, overrides -n|
|`-e`|<center>-</center>| equivalent to -vE|
|`-T`|<center>-</center>|Display tab separated lines in file opened with ```cat``` command.|
|`-E`|<center>-</center>|To show $ at the end of each file.|
|`-E`|<center>-</center>|Display file with line numbers.|
|`-n`| `--number`|number all output lines|
|`-s`| `--squeeze-blank`|suppress repeated empty output lines|
|`-u`|<center>-</center>|(ignored)|
|`-v`| `--show-nonprinting`|use ^ and M- notation, except for LFD and TAB|
|<center>-</center>|`--help` |display this help and exit|
|<center>-</center>|`--version`|output version information and exit|
---
# The `tac` command
`tac` is a Linux command that allows you to view files line-by-line, beginning from the last line. (tac doesn't reverse the contents of each individual line, only the order in which the lines are presented.) It is named by analogy with `cat`.
### Examples of uses:
1. To display the content of a file in terminal:
```
tac <specified_file_name>
```
2. This option attaches the separator before instead of after.
```
tac -b concat_file_name tac_example_file_name
```
3. This option will interpret the separator as a regular expression.
```
tac -r concat_file_name tac_example_file_name
```
4. This option uses STRING as the separator instead of newline.
```
tac -s concat_file_name tac_example_file_name
```
5. This option will display the help text and exit.
```
tac --help
```
6. This option will give the version information and exit.
```
tac --version
```
### Syntax:
```
tac [OPTION]... [FILE]...
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-b`|`--before`|attach the separator before instead of after|
|`-r`| `--regex`|interpret the separator as a regular expression|
|`-s`| `--separator=STRING`|use STRING as the separator instead of newline|
|<center>-</center>|`--help`|display this help and exit|
|<center>-</center>|`--version`|output version information and exit|

View File

@@ -0,0 +1,103 @@
# The `cp` command
The `cp` is a command-line utility for copying files and directory.
`cp` stands for copy. This command is used to copy files or group of files or directory. It creates an exact image of a file on a disk with different file name. The cp command requires at least two filenames in its arguments.
### Examples:
1. To copy the contents of the source file to the destination file.
```
cp sourceFile destFile
```
If the destination file doesn't exist then the file is created and the content is copied to it. If it exists then the file is overwritten.
2. To copy a file to another directory specify the absolute or the relative path to the destination directory.
```
cp sourceFile /folderName/destFile
```
3. To copy a directory, including all its files and subdirectories
```
cp -R folderName1 folderName2
```
The command above creates the destination directory and recursively copies all files and subdirectories from the source to the destination directory.
If the destination directory already exists, the source directory itself and its content are copied inside the destination directory.
4. To copy only the files and subdirectories but not the source directory
```
cp -RT folderName1 folderName2
```
### Syntax:
The general syntax for the cp command is as follows:
```
cp [OPTION] SOURCE DESTINATION
cp [OPTION] SOURCE DIRECTORY
cp [OPTION] SOURCE-1 SOURCE-2 SOURCE-3 SOURCE-n DIRECTORY
```
The first and second syntax is used to copy Source file to Destination file or Directory.
The third syntax is used to copy multiple Sources(files) to Directory.
#### Some useful options
1. `-i` (interactive)
`i` stands for Interactive copying. With this option system first warns the user before overwriting the destination file. cp prompts for a response, if you press y then it overwrites the file and with any other option leave it uncopied.
```
$ cp -i file1.txt fileName2.txt
cp: overwrite 'file2.txt'? y
```
2. `-b`(backup)
-b(backup): With this option cp command creates the backup of the destination file in the same folder with the different name and in different format.
```
$ ls
a.txt b.txt
$ cp -b a.txt b.txt
$ ls
a.txt b.txt b.txt~
```
3. `-f`(force)
If the system is unable to open destination file for writing operation because the user doesn't have writing permission for this file then by using -f option with cp command, destination file is deleted first and then copying of content is done from source to destination file.
```
$ ls -l b.txt
-r-xr-xr-x+ 1 User User 3 Nov 24 08:45 b.txt
```
User, group and others doesn't have writing permission.
Without `-f` option, command not executed
```
$ cp a.txt b.txt
cp: cannot create regular file 'b.txt': Permission denied
```
With -f option, command executed successfully
```
$ cp -f a.txt b.txt
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-i`|<center>--interactive</center>|prompt before overwrite|
|`-f`|<center>--force</center>|If an existing destination file cannot be opened, remove it and try again|
|`-b`|<center>-</center>|Creates the backup of the destination file in the same folder with the different name and in different format.|
|`-r or -R`|`--recursive`|**cp** command shows its recursive behavior by copying the entire directory structure recursively.|
|`-n`|`--no-clobber`|do not overwrite an existing file (overrides a previous -i option)|
|`-p`|<center>-</center>|preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all|

View File

@@ -0,0 +1,48 @@
# The `diff/sdiff` command
This command is used to display the differences in the files by comparing the files line by line.
### Syntax:
```
diff [options] File1 File2
```
### Example
1. Lets say we have two files with names a.txt and b.txt containing 5 Indian states as follows-:
```
$ cat a.txt
Gujarat
Uttar Pradesh
Kolkata
Bihar
Jammu and Kashmir
$ cat b.txt
Tamil Nadu
Gujarat
Andhra Pradesh
Bihar
Uttar pradesh
```
On typing the diff command we will get below output.
```
$ diff a.txt b.txt
0a1
> Tamil Nadu
2,3c3
< Uttar Pradesh
Andhra Pradesh
5c5
Uttar pradesh
```
### Flags and their Functionalities
|**Short Flag** |**Description** |
|--|--|
| `-c`|To view differences in context mode, use the -c option. |
| `-u`|To view differences in unified mode, use the -u option. It is similar to context mode |
|`-i`|By default this command is case sensitive. To make this command case in-sensitive use -i option with diff. |
|`-version`|This option is used to display the version of diff which is currently running on your system. |

View File

@@ -0,0 +1,44 @@
# The `dir` command
The `dir` command lists the contents of a directory(_the current directory by default_). **It differs from ls command in the format of listing the content**. By default, the dir command lists the files and folders in columns, sorted vertically and special characters are represented by backslash escape sequences.
### Syntax:
```[linux]
dir [OPTIONS] [FILE]
```
### Examples:
1. To list files in the current directory:
```[linux]
dir
```
2. To list even the hidden files in the current directory:
```[linux]
dir -a
```
3. To list the content with detailed information for each entry
```[linux]
dir -l
```
### Additional Flags and their Functionalities:
| **Short Flag** | **Long Flag** | **Description** |
| :----------------- | :-------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| `-a` | `--all` | It displays all the hidden files(starting with `.`) along with two files denoted by `.` and `..` |
| `-A` | `--almost-all` | It is **similar to -a** option except that it _does not display files that signals the current directory and previous directory._ |
| `-l` | <center>-</center> | Display detailed information for each entry |
| `-s` | `--size` | Print the allocated size of each file, in blocks File |
| `-h` | `--human-readable` | Used with with -l and -s, to print sizes like in human readable format like 1K, 2M and so on |
| `-F` | <center>-</center> | Classifies entries into their type based on appended symbol (`/`, `*`, `@`, `%`, `=`) |
| `-v` | `--verbose` | Print source and destination files |
| <center>-</center> | `--group-directories-first` | To group directories before files |
| `-R ` | `--recursive` | To List subdirectories recursively. |
| `-S ` | <center>-</center> | sort by file size, display largest first |

View File

@@ -0,0 +1,37 @@
# The `du` command
The `du` command, which is short for `disk usage` lets you retrieve information about disk space usage information in a specified directory. In order to customize the output according to the information you need, this command can be paired with the appropriate options or flags.
### Examples:
1. To show the estimated size of sub-directories in the current directory:
```
du
```
2. To show the estimated size of sub-directories inside a specified directory:
```
du {PATH_TO_DIRECTORY}
```
### Syntax:
```
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
```
### Additional Flags and their Functionalities:
*Note: This does not include an exhaustive list of options.*
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-a`|`--all`|Includes information for both files and directories|
|`-c`|`--total`|Provides a grand total at the end of the list of files/directories|
|`-d`|`--max-depth=N`|Provides information up to `N` levels from the directory where the command was executed|
|`-h`|`--human-readable`|Displays file size in human-readable units, not in bytes|
|`-s`|`--summarize`|Display only the total filesize instead of a list of files/directories|

View File

@@ -0,0 +1,70 @@
# The `find` command
The `find` command lets you **search for files in a directory hierarchy**
- Search a file with specific name.
- Search a file with pattern
- Search for empty files and directories.
### Examples:
1. Search a file with specific name:
```[linux]
find ./directory1 -name sample.txt
```
2. Search a file with pattern:
```[linux]
find ./directory1 -name '*.txt'
```
3. To find all directories whose name is test in / directory.
```[linux]
find / -type d -name test
```
4. Searching empty files in current directory
```[linux]
find . -size 0k
```
### Syntax:
```[linux]
find [options] [paths] [expression]
```
**In Simple words**
```[linux]
find [where to start searching from]
[expression determines what to find] [-options] [what to find]
```
### Additional Flags and their Functionalities:
Commonly-used primaries include:
- `name` pattern - tests whether the file name matches the shell-glob pattern given.
- `type` type - tests whether the file is a given type. Unix file types accepted include:
| **options** | **Description** |
| :------------- | :-------------------------------------------------------------------------------------------------------- |
| `b` | block device (buffered) |
| `d` | directory |
| `f` | regular file |
| `l` | Symbolic link |
| `-print` | always returns true; prints the name of the current file plus a newline to the stdout. |
| `-mtime n` | find's all the files which are modified n days back. |
| `-atime n` | find's all the files which are accessed 50 days back. |
| `-cmin n` | find's all the files which are modified in the last 1 hour.|
| ` -newer file` | find's file was modified more recently than file.|
| `-size n` | File uses n units of space, rounding up.|
### Help Command
Run below command to view the complete guide to `find` command or [click here](https://en.wikipedia.org/wiki/Find_(Unix)).
```[linux]
man find
```

View File

@@ -0,0 +1,62 @@
# The `grep` command
The `grep` filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern.
grep stands for globally search for regular expression and print out. The pattern that is searched in the file is referred to as the regular expression.
### Examples:
1. To search the contents of the destination.txt file for a string("KeY") case insensitively.
```
grep -i "KeY" destination.txt
```
2. Displaying the count of number of matches
```
grep -c "key" destination.txt
```
3. We can search multiple files and only display the files that contains the given string/pattern.
```
grep -l "key" destination1.txt destination2.txt destination3.xt destination4.txt
```
4. To show the line number of file with the line matched.
```
grep -n "key" destination.txt
```
5. If you want to grep the monitored log files, you can add the `--line-buffered` to search them in real time.
```
tail -f destination.txt | grep --line-buffered "key"
```
### Syntax:
The general syntax for the grep command is as follows:
```
grep [options] pattern [files]
```
### Additional Flags and their Functionalities:
| **Short Flag** | **Long Flag** | **Description** |
| :------------- | :--------------------- | :---------------------------------------------------------------------------------------------- |
| `-c` | `--count` | print a count of matching lines for each input file |
| `-h` | `--no-filename` | Display the matched lines, but do not display the filenames |
| `-i` | `--ignore-case` | Ignores, case for matching |
| `-l` | `--files-with-matches` | Displays list of a filenames only. |
| `-n` | `--line-number` | Display the matched lines and their line numbers. |
| `-v` | `--invert-match` | This prints out all the lines that do not matches the pattern |
| `-e` | `--regexp=` | Specifies expression with this option. Can use multiple times |
| `-f` | `--file=` | Takes patterns from file, one per line. |
| `-F` | `--fixed-strings=` | Interpret patterns as fixed strings, not regular expressions. |
| `-E` | `--extended-regexp` | Treats pattern as an extended regular expression (ERE) |
| `-w` | `--word-regexp` | Match whole word |
| `-o` | `--only-matching` | Print only the matched parts of a matching line, with each such part on a separate output line. |
| | `--line-buffered` | Force output to be line buffered. |

View File

@@ -0,0 +1,41 @@
# The `head` command
The `head` command prints the first ten lines of a file.
Example:
```
head filename.txt
```
Syntax:
```
head [OPTION] [FILENAME]
```
### Get a specific number of lines:
Use the `-n` option with a number (should be an integer) of lines to display.
Example:
```
head -n 10 foo.txt
```
This command will display the first ten lines of the file `foo.txt`.
Syntax:
```
head -n <number> foo.txt
```
### Additional Flags and their Functionalities
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-c`|`--bytes=[-]NUM`|Print the first NUM bytes of each file; <br>with the leading '-', <br>print all but the last NUM bytes of each file|
|`-n`|`--lines=[-]NUM`|Print the first NUM lines instead of the first 10;<br> with the leading '-', <br>print all but the last NUM lines of each file|
|`-q`|`--quiet, --silent`|Never print headers giving file names|
|`-v`|`--verbose`|Always print headers giving file names|
|`-z`|`--zero-terminated`|Line delimiter is NUL, not newline|
|` `|`--help`| Display this help and exit|
|` `|`--version`|Output version information and exit|

View File

@@ -0,0 +1,71 @@
# The `ls` command
The `ls` command lets you see the files and directories inside a specific directory *(current working directory by default)*.
It normally lists the files and directories in ascending alphabetical order.
### Examples:
1. To show the files inside your current working directory:
```
ls
```
2. To show the files and directory inside a specific Directory:
```
ls {Directory_Path}
```
### Syntax:
```
ls [-OPTION] [DIRECTORY_PATH]
```
### Interactive training
In this interactive tutorial, you will learn the different ways to use the `ls` command:
[The ls command by Tony](https://devdojo.com/tnylea/ls-command)
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-l`|<center>-</center>|Show results in long format|
|`-S`|<center>-</center>|Sort results by file size|
|`-t`|<center>-</center>|Sort results by modification time|
|`-r`|`--reverse`|Show files and directories in reverse order *(descending alphabetical order)*|
|`-a`|`--all`|Show all files, including hidden files *(file names which begin with a period `.`)*|
|`-la`|<center>-</center>|Show long format files and directories including hidden files|
|`-lh`|<center>-</center>|list long format files and directories with readable size|
|`-A`|`--almost-all`|Shows all like `-a` but without showing `.`(current working directory) and `..` (parent directory)|
|`-d`|`--directory`|Instead of listing the files and directories inside the directory, it shows any information about the directory itself, it can be used with `-l` to show long formatted information|
|`-F`|`--classify`|Appends an indicator character to the end of each listed name, as an example: `/` character is appended after each directory name listed|
|`-h`|`--human-readable`|like `-l` but displays file size in human-readable unit not in bytes|
### Setting Persistent Options:
Customizing command behavior in Linux is easy using the `alias` command. To make these changes permanent, follow these steps:
1. **Create the Alias**: Define your alias with the desired options. For example, to enhance the `ls` command:
```bash
alias ls="ls --color=auto -lh"
```
2. **Persistence**: This alias is effective only for the current session. To make it permanent, add the alias to your shell's configuration file:
- **Bash**: Append the alias to `~/.bashrc`:
```bash
echo 'alias ls="ls --color=auto -lh"' >> ~/.bashrc
source ~/.bashrc
```
3. **Verification**: Open a new terminal session, and the `ls` command will display files as configured.

View File

@@ -0,0 +1,44 @@
# The `mkdir` command
The `mkdir` command in Linux/Unix is used to create a directory.
## Syntax
```bash
$ mkdir [-m=mode] [-p] [-v] [-Z=context] directory [directory ...]
```
## Examples
1. Make a directory named **myfiles**.
```bash
$ mkdir myfiles
```
2. Create a directory named **myfiles** at the home directory:
```bash
$ mkdir ~/myfiles
```
3. Create the **mydir** directory, and set its file mode (`-m`) so that all users (`a`) may read (`r`), write (`w`), and execute (`x`) it.
```bash
$ mkdir -m a=rwx mydir
```
You can also create sub-directories of a directory. It will create the parent directory first, if it doesn't exist.
If it already exists, then it move further to create the sub-directories without any error message.
For directories, this means that any user on the system may view ("read"), and create/modify/delete ("write") files in the directory. Any user may also change to ("execute") the directory, for example with the `cd` command.
4. Create the directory **/home/test/src/python**. If any of the parent directories **/home**, **/home/test**, or **/home/test/src** do not already exist, they are automatically created.
```bash
$ mkdir -p /home/test/src/python
```
## Options
|**Short Flags**|**Long Flags**|**Descriptions**|
|:-|:-|:-|
|`-m`|`--mode=MODE`|Set file mode (as in chmod), not `a=rwx - umask`.|
|`-p`|`--parents`|No error if existing, make parent directories as needed.|
|`-v`|`--verbose`|Print a message for each created directory.|
|`-Z`|`--context=CTX`|Set the SELinux security context of each created directory to CTX.|
|<center>-</center>|`--help`|Display a help message and exit.|
|<center>-</center>|`--version`|Output version information and exit.|

View File

@@ -0,0 +1,46 @@
# The `mv` command
The `mv` command lets you **move one or more files or directories** from one place to another in a file system like UNIX.
It can be used for two distinct functions:
- To rename a file or folder.
- To move a group of files to a different directory.
_**Note:** No additional space is consumed on a disk during renaming, and the mv command doesn't provide a prompt for confirmation_
### Syntax:
```[linux]
mv [options] source (file or directory) destination
```
### Examples:
1. To rename a file called old_name.txt:
```[linux]
mv old_name.txt new_name.txt
```
2. To move a file called _essay.txt_ from the current directory to a directory called _assignments_ and rename it _essay1.txt_:
```[linux]
mv essay.txt assignments/essay1.txt
```
3. To move a file called _essay.txt_ from the current directory to a directory called _assignments_ without renaming it
```[linux]
mv essay.txt assignments
```
### Additional Flags and their Functionalities:
| **Short Flag** | **Long Flag** | **Description** |
| :------------- | :-------------- | :-------------------------------------------------------------------------------------------------------- |
| `-f` | `--force` | Force move by overwriting destination file without prompt |
| `-i` | `--interactive` | Interactive prompt before overwrite |
| `-u` | `--update` | Move only when the source file is newer than the destination file or when the destination file is missing |
| `-n` | `--no-clobber` | Do not overwrite an existing file |
| `-v` | `--verbose` | Print source and destination files |
| `-b` | `--backup` | Create a Backup of Existing Destination File |

View File

@@ -0,0 +1,51 @@
# The `nano` command
The `nano` command lets you create/edit text files.
### Installation:
Nano text editor is pre-installed on macOS and most Linux distros. It's an alternative to `vi` and `vim`. To check if it is installed on your system type:
```
nano --version
```
If you don't have `nano` installed you can do it by using the package manager:
Ubuntu or Debian:
```
sudo apt install nano
```
### Examples:
1. Open an existing file, type `nano` followed by the path to the file:
```
nano /path/to/filename
```
2. Create a new file, type `nano` followed by the filename:
```
nano filename
```
3. Open a file with the cursor on a specific line and character use the following syntax:
```
nano +line_number,character_number filename
```
### Overview of some Shortcuts and their Functionalities:
|**Shortcut** |**Description** |
|:---|:---|
|`Ctrl + S`|Save current file|
|`Ctrl + O`|Offer to write file ("Save as")|
|`Ctrl + X`|Close buffer, exit from nano|
|`Ctrl + K`|Cut current line into cutbuffer|
|`Ctrl + U`|Paste contents of cutbuffer|
|`Alt + 6`|Copy current line into cutbuffer|
|`Alt + U`|Undo last action|
|`Alt + E`| Redo last undone action|

View File

@@ -0,0 +1,36 @@
# The `rm` command
`rm` which stands for "remove" is a command used to remove *(delete)* specific files. It can also be used to remove directories by using the appropriate flag.
### Example:
```
rm filename.txt
```
### Syntax
```
rm [OPTION] [FILE|DIRECTORY]
```
### Flags and their Functionalities:
|Short Flag|Long Flag|Description|
|:---|:---|:---|
|`-f`|`--force`|Ignore nonexistance of files or directories, never prompt|
|`-i`|<center>-</center>|Prompt before every removal|
|`-I`|<center>-</center>|Prompt once before removal of more than 3 files, or when removing recursively|
|`-d`|`--dir`|remove empty directories|
|`-v`|`--verbose`|explain what is being done|
|`-r` or `-R`|`--recursive`|remove directories and their contents recursively|
|<center>-</center>|`--help`|Display help then exit|
|<center>-</center>|`--version`|First, Print version Information, Then exit|
|<center>-</center>|`--no-preserve-root`|do not treat `/` specially|
|<center>-</center>|`-preserve-root[=all]`|do not remove `/` (default) <br>with 'all', reject any command line argument on a separate device from its parent|
|<center>-</center>|`--interactive[=WHEN]`|prompt according to WHEN, never, once `-I`, or always `-i`, without WHEN, prompt always|
|<center>-</center>|` --one-file-system`|when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument0|
***IMPORTANT NOTICE:***
1. `rm` doesn't remove directories by default, so use `-r`, `-R`, `--recursive` options to remove each listed directory, along with all of its contents.
2. To remove a file whose name starts with `-` such as `-foo`, use one of the following commands:
- `rm -- -foo`
- `rm ./-foo`
3. To ensure that files/directories being deleted are truly unrecoverable, consider using the `shred` command.

View File

@@ -0,0 +1,56 @@
# The `tail` command
The `tail` command prints the last ten lines of a file.
Example:
```
tail filename.txt
```
Syntax:
```
tail [OPTION] [FILENAME]
```
### Get a specific number of lines with `tail`:
Use the `-n` option with a number(should be an integer) of lines to display.
Example:
```
tail -n 10 foo.txt
```
This command will display the last ten lines of the file `foo.txt`.
### Refresh the output on any new entry in a file
It is possible to let tail output any new line added to the file you are looking into. So, if a new line is written to the file, it will immediately be shown in your output. This can be done using the `--follow` or `-f` option. This is especially useful for monitoring log files.
Example:
```
tail -f foo.txt
```
Syntax:
```
tail -n <number> foo.txt
```
### Additional Flags and their Functionalities
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-c`|`--bytes=[+]NUM`|Output the last NUM bytes;<br> or use -c +NUM to <br>output starting with byte NUM of each file|
|`-f`|<code>--follow[={name&#124;descriptor}]</code>|Output appended data as the file grows;<br>an absent option argument means 'descriptor'|
|`-F`||Same as --follow=name --retry|
|`-n`|`--lines=[+]NUM`|Output the last NUM lines, instead of the last 10;<br>or use -n +NUM to output starting with line NUM|
||`--max-unchanged-stats=N`|with --follow=name, reopen a FILE which has not<br>changed size after N (default 5) iterations<br>to see if it has been unlinked or rename<br>(this is the usual case of rotated log files);<br>with inotify, this option is rarely useful|
||`--pid=PID`|with -f, terminate after process ID, PID dies|
|`-q`|`--quiet, --silent`|Never output headers giving file names|
|``|`--retry`|keep trying to open a file if it is inaccessible|
|`-s`|`--sleep-interval=N`|With -f, sleep for approximately N seconds<br>(default 1.0) between iterations;<br>with inotify and --pid=P, check process P at<br>least once every N seconds|
|`-v`|`--verbose`|Always output headers giving file names|
|`-z`|`--zero-terminated`|Line delimiter is NUL, not newline|
||`--help`|Display this help and exit|
||`--version`|Output version information and exit|

View File

@@ -0,0 +1,59 @@
# The `touch` Command
The `touch` command modifies a file's timestamps. If the file specified doesn't exist, an empty file with that name is created.
### Syntax
```
touch [OPTION]... FILE...
```
### Options
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-a`|<center>-</center>|Change only the access time.|
|`-c`|`--no-create`|Do not create any files.|
|`-d` STRING|`--date=STRING`|Parse *STRING* and use it instead of the current time.|
|`-f`|<center>-</center>|(Ignored) This option does nothing but is accepted to provide compatibility with BSD versions of the `touch` command.|
|`-h`|`--no-dereference`|Affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink). This option implies `-c`, nothing is created if the file does not exist.|
|`-m`|<center>-</center>|Change only the modification time.|
|`-r=FILE`|`--reference=FILE`|Use this file's times instead of the current time.|
|`-t STAMP`|<center>-</center>|Use the numeric time *STAMP* instead of the current time. The format of *STAMP* is [[**CC**]**YY**]**MMDDhhmm**[**.ss**].|
|<center>-</center>|`--time=WORD`|An alternate way to specify which type of time is set (e.g. *access*, *modification*, or *change*). This is equivalent to specifying `-a` or `-m`.
- WORD is `access`, `atime`, or `use`: equivalent to `-a`.
- WORD is `modify` or `mtime`: equivalent to `-m`.
An alternate way to specify what type of time to set (as with **-a** and **-m**).|
|<center>-</center>|`--help`|Display a help message, and exit.|
|<center>-</center>|`--version`|Display version information, and exit.|
### Examples
1. If **file.txt** exists, set all of its timestamps to the current system time. If **file.txt** doesn't exist, create an empty file with that name.
```
touch file.txt
```
2. If **file.txt** exists, set its times to the current system time. If it does not exist, do nothing.
```
touch -c file.txt
```
3. Change the *access* time of **file.txt**. The *modification* time is not changed. The *change* time is set to the current system time. If **file.txt** does not exist, it is created.
```
touch -a file.txt
```
4. Change the times of file **symboliclink**. If it's a symbolic link, change the times of the symlink, ***NOT*** the times of the referenced file.
```
touch -h symboliclink
```
5. Change the *access* and *modification* times of **file-b.txt** to match the times of **file-a.txt**. The *change* time will be set to the current system time. If **file-b.txt** does not exist, it is not created. Note, **file-a.txt** must already exist in this context.
```
touch -cr file-a.txt file-b.txt
```
6. Set the *access* time and *modification* time of **file.txt** to ***February 1st*** of the current year. The *change* time is set to the current system time.
```
touch -d "1 Feb" file.txt
```

View File

@@ -0,0 +1,106 @@
# The `vim` command
The [vim](https://www.vim.org/) is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface).
Vim text editor is developed by [Bram Moolenaar](https://en.wikipedia.org/wiki/Bram_Moolenaar). It supports most file types and the vim editor is also known as a programmer's editor. It is mainly because it can be managed entirely without menus or a mouse with a keyboard.
**Note:** Do not confuse `vim` with `vi`. `vi`, which stands for "Visual", is a text editor that was developed by [Bill Joy](https://en.wikipedia.org/wiki/Bill_Joy) in 1976. `vim` stands for "Vi Improved", and is an improved clone of the `vi` editor.
### The most searched question about ```vim``` :
``How to exit vim editor?``
The most searched question about vim editor looks very funny but it's true that the new user gets stuck at the very beginning when using vim editor.
The command to save the file and exit vim editor: ```:wq```
The command to exit vim editor without saving the file: ```:q!```
#### Fun reading:
Here's a [survey](https://stackoverflow.blog/2017/05/23/stack-overflow-helping-one-million-developers-exit-vim/) for the same question, look at this and do not think to quit the vim editor.
### Installation:
First check if vim is already installed or not, enter the following command:
```
vim --version
```
If it is already installed it will show its version, else we can run the below commands for the installations:
On Ubuntu/Debian:
```
sudo apt-get install vim
```
On CentOS/Fedora:
```
sudo yum install vim
```
If you want to use advanced features on CentOS/Fedora, you'll need to install enhanced vim editor, to do this run the following command:
```
sudo yum install -y vim-enhanced
```
### Syntax:
```
vim [FILE_PATH/FILE_NAME]
```
### Examples:
1. To open the file named "demo.txt" from your current directory:
```
vim demo.txt
```
2. To open the file in a specific directory:
```
vim {File_Path/filename}
```
3. To open the file starting on a specific line in the file:
```
vim {File_Path/filename} +LINE_NUMBER
```
### Modes in vim editor:
There are some arguments as to how many modes that vim has, but the modes you're most likely to use are ```command mode``` and ```insert mode```. These [modes](https://www.freecodecamp.org/news/vim-editor-modes-explained/) will allow you to do just about anything you need, including creating your document, saving your document, and doing advanced editing, including taking advantage of search and replace functions.
### Workflow of `vim` editor:
1. Open a new or existing file with ```vim filename```.
2. Type ```i``` to switch into insert mode so that you can start editing the file.
3. Enter or modify the text of your file.
4. When you're done, press the ```Esc``` key to exit insert mode and back to command mode.
5. Type :w or :wq to save the file or save and exit from the file respectively.
### Interactive training
In this interactive tutorial, you will learn the different ways to use the `vim` command:
[The Open vim Tutorial](https://www.openvim.com/)
### Additional Flags and their Functionalities:
|**Flags/Options** |<center>**Description**</center> |
|:---|:---|
|`-e`|Start in Ex mode (see [Ex-mode](http://vimdoc.sourceforge.net/htmldoc/intro.html#Ex-mode))|
|`-R`|Start in read-only mode|
|`-R`|Start in read-only mode|
|`-g`|Start the [GUI](http://vimdoc.sourceforge.net/htmldoc/gui.html#GUI)|
|`-eg`|Start the GUI in Ex mode|
|`-Z`|Like "vim", but in restricted mode|
|`-d`|Start in diff mode [diff-mode](http://vimdoc.sourceforge.net/htmldoc/diff.html#diff-mode)|
|`-h`|Give usage (help) message and exit|
|`+NUMBER`|Open a file and place the cursor on the line number specified by NUMBER|
### Read more about vim:
vim can not be learned in a single day, use in day-to-day tasks to get hands-on in vim editor.
To learn more about ```vim``` follow the given article:
[Article By Daniel Miessler](https://danielmiessler.com/study/vim/)

View File

@@ -0,0 +1,90 @@
# The `xargs` command
`xargs` is used to build and execute command lines from standard input
Some commands like grep can accept input as parameters, but some commands accepts arguments, this is place where xargs came into picture.
### Syntax:
```
xargs [options] [command [initial-arguments]]
```
### Options:
```
-0, --null
```
Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes.
```
-a file, --arg-file=file
```
Read items from file instead of standard input. If you use this option, stdin remains unchanged when commands are run. Otherwise, stdin is redirected
from /dev/null.
```
-o, --open-tty
```
Reopen stdin as /dev/tty in the child process before executing the command. This is useful if you want xargs to run an interactive application.
```
--delimiter=delim, -d delim
```
Input items are terminated by the specified character. The specified delimiter may be a single character, a C-style character escape such as \n, or an
octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte characters are not supported.
When processing the input, quotes and backslash are not special; every character in the input is taken literally. The -d option disables any end-of-file
string, which is treated like any other argument. You can use this option when the input consists of simply newline-separated items, although it is al
most always better to design your program to use --null where this is possible.
```
-p, --interactive
```
Prompt the user about whether to run each command line and read a line from the terminal. Only run the command line if the response starts with `y' or
`Y'. Implies -t.
### Examples:
```
find /tmp -name core -type f -print | xargs /bin/rm -f
```
Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines or
spaces.
```
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
```
Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing spaces or new
lines are correctly handled.
```
find /tmp -depth -name core -type f -delete
```
Find files named core in or below the directory /tmp and delete them, but more efficiently than in the previous example (because we avoid the need to use fork(2)
and exec(2) to launch rm and we don't need the extra xargs process).
```
cut -d: -f1 < /etc/passwd | sort | xargs echo
```
Generates a compact listing of all the users on the system.
### Help Command
Run below command to view the complete guide to `xargs` command.
```
man xargs
```

View File

@@ -0,0 +1,37 @@
# Home
You want to manage linux servers. Get results. Stop drowning in useless commands and ditch the theory.
!["Shinobi Academy Linux"](/../cover.png)
## About
I've run critical systems for the Feds for years. There are the few battle tested commands I *actually* use.
I've stripped the fluff, cut the fat, and distilled the chaos into your essential arsenal. Your direct path to mastery.
## Server Sectors
Broken down into actionable categories, so you can start **dominating:**
* **Core:** Your foundational power. The commands you'll live in, every single day, to navigate and interact.
* **Files:** Master your data. Create, move, edit, and find anything. This is where you own your content.
* **Monitor:** See the heartbeat of your system. Diagnose problems, track performance, and stay ahead of trouble.
* **Network:** Command your connections, communicate like a boss. From basic pings to secure remote access.
* **Process:** Take control. Understand what's running, manage tasks, and keep your system lean and efficient.
* **Software:** Install, update, and manage your applications. The tools to keep your system armed and ready.
* **System:** Deep dives into the machine itself. Configure, reboot, shutdown, and understand your hardware.
* **Users:** Secure your access. Manage permissions, create users, and control who does what on your system.
* **Archive:** Compress, extract, and protect your data. Keep things tight and organized.
* **Disk:** Understand your storage. Manage partitions, check space, and keep your drives optimized.
Learn what matters. **Win.**

View File

@@ -0,0 +1,105 @@
# The `df` command
The `df` command in Linux/Unix is used to show the disk usage & information.
`df` is an abbreviation for "disk free".
`df` displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown.
### Syntax
```
df [OPTION]... [FILE]...
```
### Options
|**Short Flag**|**Long Flag**|**Description**|
|:--|:--|:--|
|`-a`|`--all`|Include pseudo, duplicate, inaccessible file systems.|
|`-B`|`--block-size=SIZE`|Scale sizes by SIZE before printing them; e.g., `-BM` prints sizes in units of 1,048,576 bytes; see SIZE format below.|
|`-h`|`--human-readable`|Print sizes in powers of 1024 (e.g., 1023M).|
|`-H`|`--si`|Print sizes in powers of 1000 (e.g., 1.1G).|
|`-i`|`--inodes`|List inode information instead of block usage.|
|`-k`|<center>-</center>|Like `--block-size=1K`.|
|`-l`|`--local`|Limit listing to local file systems.|
|<center>-</center>|`--no-sync`|Do not invoke `sync` before getting usage info (default).|
|<center>-</center>|`--output[=FIELD_LIST]`|Use the output format defined by `FIELD_LIST`, or print all fields if FIELD_LIST is omitted.|
|`-P`|`--portability`|Use the `POSIX` output format|
|<center>-</center>|`--sync`|Invoke sync before getting usage info.|
|<center>-</center>|`--total`|Elide all entries insignificant to available space, and produce a grand total.|
|`-t`|`--type=TYPE`|Limit listing to file systems of type `TYPE`.|
|`-T`|`--print-type`|Print file system type.|
|`-x`|`--exclude-type=TYPE`|Limit listing to file systems not of type `TYPE`.|
|`-v`|<center>-</center>|Ignored; included for compatibility reasons.|
|<center>-</center>|`--help`|Display help message and exit.|
|<center>-</center>|`--version`|Output version information and exit.|
### Examples:
1. Show available disk space
**Action:**
--- Output the available disk space and where the directory is mounted
**Details:**
--- Outputted values are not human-readable (are in bytes)
**Command:**
```
df
```
2. Show available disk space in human-readable form
**Action:**
--- Output the available disk space and where the directory is mounted
**Details:**
--- Outputted values ARE human-readable (are in GBs/MBs)
**Command:**
```
df -h
```
3. Show available disk space for the specific file system
**Action:**
--- Output the available disk space and where the directory is mounted
**Details:**
--- Outputted values are only for the selected file system
**Command:**
```
df -hT file_system_name
```
4. Show available inodes
**Action:**
--- Output the available inodes for all file systems
**Details:**
--- Outputted values are for inodes and not available space
**Command:**
```
df -i
```
5. Show file system type
**Action:**
--- Output the file system types
**Details:**
--- Outputted values are for all file systems
**Command:**
```
df -T
```
6. Exclude file system type from the output
**Action:**
--- Output the information while excluding the chosen file system type
**Details:**
--- Outputted values are for all file systems EXCEPT the chosen file system type
**Command:**
```
df -x file_system_type
```

View File

@@ -0,0 +1,92 @@
# The `top/htop` command
`top` is the default command-line utility that comes pre-installed on Linux distributions and Unix-like operating systems. It is used for displaying information about the system and its top CPU-consuming processes as well as RAM usage.
`htop` is interactive process-viewer and process-manager for Linux and Unix-like operating system based on ncurses. If you take top and put it on steroids, you get htop.
## Comparison between top and htop:
|**Feature** |**top** |**htop** |
|:---|:---|:---|
|Type|Interactive system-monitor, process-viewer and process-manager|Interactive system-monitor, process-viewer and process-manager|
|Operating System|Linux distributions, macOS |Linux distributions, macOS |
|Installation|Built-in and is always there. Also has more adoption due to this fact.|Doesn't come preinstalled on most Linux distros. Manual installation is needed|
|User Interface|Basic text only|Colorful and nicer text-graphics interface|
|Scrolling Support|No|Yes, supports horizontal and vertical scrolling|
|Mouse Support|No|Yes|
|Process utilization|Displays processes but not in tree format|Yes, including user and kernel threads|
|Scrolling Support|No|Yes, supports horizontal and vertical scrolling|
|Mouse Support|No|Yes|
|Process utilization|Displays processes but not in tree format|Yes, including user and kernel threads|
|Network Utilization|No|No|
|Disk Utilization|No|No|
|Comments|Has a learning curve for some advanced options like searching, sending messages to processes, etc. It is good to have some knowledge of top because it is the default process viewer on many systems.|Easier to use and supports vi like searching with `/`. Sending messages to processes (kill, renice) is easier and doesn't require typing in the process number like top.|
## Examples:
### `top`
1. To display dynamic real-time information about running processes:
```
top
```
2. Sorting processes by internal memory size (default order - process ID):
```
top -o mem
```
3. Sorting processes first by CPU, then by running time:
```
top -o cpu -O time
```
4. Display only processes owned by given user:
```
top -user {user_name}
```
### `htop`
1. Display dynamic real-time information about running processes. An enhanced version of `top`.
```
htop
```
2. displaying processes owned by a specific user:
```
htop --user {user_name}
```
3. Sort processes by a specified `sort_item` (use `htop --sort help` for available options):
```
htop --sort {sort_item}
```
## Syntax:
```
top [OPTIONS]
```
```
htop [OPTIONS]
```
## Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-a`|<center>-</center>|Sort by memory usage.|
|`-b`|<center>-</center>|Batch mode operation. Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.|
|`-h`|<center>-</center>|`top --user {user_name}` Only display processes owned by user.|
|`-U`|<center>-user</center>|Help.|
|`-u`|<center>-</center>|This is an alias equivalent to: -o cpu -O time.|

View File

@@ -0,0 +1,118 @@
# The ``lsblk`` command
## Summary
The ``lsblk`` command displays the block and loop devices on the system. It is especially useful when you want to format disks, write filesystems, check the filesystem and know the mount point of a device.
## Examples
1. Basic usage is fairly simple - just execute 'lsblk' sans any option.
```
lsblk
```
2. Make lsblk display empty devices as well
```
lsblk -a
```
3. Make lsblk print size info in bytes
```
lsblk -b
```
4. Make lsblk print zone model for each device
```
lsblk -z
```
5. Make lsblk skip entries for slaves
```
lsblk -d
```
6. Make lsblk use ascii characters for tree formatting
```
lsblk -i
```
7. Make lsblk display info about device owner, group, and mode
```
lsblk -m
```
8. Make lsblk output select columns
```
lsblk -o NAME,SIZE
```
## Syntax
```
lsblk [options] [<device> ...]
```
## Reading information given by ``lsblk``
On running ``lsblk`` with no flags or command-line arguments, it writes general disk information to the STDOUT.
Here is a table that interpretes that information:
| Column Name | Meaning | Interpretation |
|:-----------:|:----------------------------------|:------------------------------------------------------------|
| NAME | Name of the device. | Shows name of the device. |
| RM | Removable. | Shows 1 if the device is removable, 0 if not. |
| SIZE | Size of the device. | Shows size of the device. |
| RO | Read-Only. | Shows 1 if read-only, 0 if not. |
| TYPE | The type of block or loop device. | Shows ``disk`` for entire disk and ``part`` for partitions. |
| MOUNTPOINTS | Where the device is mounted. | Shows where the device is mounted. Empty if not mounted. |
## Reading information of a specific device
``lsblk`` can display information of a specific device when the device's absolute path is passed to it.
For example, ``lsblk`` command for displaying the information of the ``sda`` disk is:
```
lsblk /dev/sda
```
## Useful flags for ``lsblk``
Here is a table that show some of the useful flags that can be used with lsblk
| **Short Flag** | **Long Flag** | **Description** |
|:--------------------------:|:-----------------------|:---------------------------------------------|
| ``-a`` | ``--all`` | `lsblk` does not list empty devices by default. This option disables this restriction. |
| ``-b`` | ``--bytes`` | Print the SIZE column in bytes rather than in human-readable format. |
| ``-d`` | ``--nodeps`` | Don't print device holders or slaves. |
| ``-D`` | ``--discard`` | Print information about the discard (TRIM, UNMAP) capabilities for each device. |
| ``-E`` | ``--dedup column`` | Use column as a de-duplication key to de-duplicate output tree. If the key is not available for the device, or the device is a partition and parental whole-disk device provides the same key than the device is always printed.|
| ``-e`` | ``--exclude list`` | xclude the devices specified by a comma-separated list of major device numbers. Note that RAM disks (major=1) are excluded by default. The filter is applied to the top-level devices only.|
| ``-f`` | ``--fs`` | Displays information about filesystem. |
| ``-h`` | ``--help`` | Print a help text and exit.|
| ``-l`` | ``--include list`` | Displays all the information in List Format. |
| ``-J`` | ``--json`` | Displays all the information in JSON Format. |
| ``-l`` | ``--list`` | Displays all the information in List Format. |
| ``-m`` | ``--perms`` | Displays info about device owner, group and mode. |
| ``-M`` | ``--merge`` | Group parents of sub-trees to provide more readable output for RAIDs and Multi-path devices. The tree-like output is required.|
| ``-n`` | ``--noheadings`` | Do not print a header line. |
| ``-o`` | ``--output list`` | Specify which output columns to print. Use `--help` to get a list of all supported columns. |
| ``-O`` | ``--output-all`` | Displays all available columns. |
| ``-p`` | ``--paths`` | Displays absolute device paths. |
| ``-P`` | ``--pairs`` | Use key="value" output format. All potentially unsafe characters are hex-escaped (\x<code>) |
| ``-r`` | ``--raw`` | Use the raw output format. All potentially unsafe characters are hex-escaped (\x<code>) in NAME, KNAME, LABEL, PARTLABEL and MOUNTPOINT columns.|
| ``-S`` | ``--scsi`` | Output info about SCSI devices only. All partitions, slaves and holder devices are ignored.|
| ``-s`` | ``--inverse`` | Print dependencies in inverse order. |
| ``-t`` | ``--topology`` | Output info about block device topology. This option is equivalent to "-o NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE".|
| ``-T`` | ``--tree[=column]`` | Displays all the information in Tree Format. |
| ``-V`` | ``--version`` | Output version information and exit. |
| ``-w`` | ``--width`` |pecifies output width as a number of characters. The default is the number of the terminal columns, and if not executed ona terminal, then output width is not restricted at all by default.|
| ``-x`` | ``--sort [column]`` | Sort output lines by column. This option enables `--list` output format by default. It is possible to use the option `--tree` to force tree-like output and than the tree branches are sorted by the column.|
| ``-z`` | ``--zoned`` | Print the zone model for each device. |
| ``-`` | ``--sysroot directory``| Gather data for a Linux instance other than the instance from which the lsblk command is issued. The specified directory is the system root of the Linux instance to be inspected.|
## Exit Codes
Like every Unix / Linux Program, ``lslbk`` returns an exit code to the environment.
Here is a table of all the exit codes.
| Exit Code | Meaning |
|:---------:|:-----------------------------------------------------------|
| 0 | Exit with success. |
| 1 | Exit with failure. |
| 32 | Specified device(s) not found. |
| 64 | Some of the specified devices were found while some not. |

View File

@@ -0,0 +1,60 @@
# The `netstat` command
The term `netstat` stands for Network Statistics. In laymans terms, netstat command displays the current network connections, networking protocol statistics, and a variety of other interfaces.
Check if you have `netstat` on your PC:
```
netstat v
```
If you don't have `netstat` installed on your PC, you can install it with the following command:
```
sudo apt install net-tools
```
### You can use `netstat` command for some use cases given below:
- `Netstat` command with `-nr` flag shows the routing table detail on the terminal.
Example:
```
netstat -nr
```
- `Netstat` command with `-i` flag shows statistics for the currently configured network interfaces.
This command will display the first 10 lines of file `foo.txt` .
Example:
```
netstat -i
```
- `Netstat` command with `-tunlp` will gives a list of networks, their current states, and their associated ports.
Example:
```
netstat -tunlp
```
- You can get the list of all TCP port connection by using `-at` with `netstat`.
```
netstat -at
```
- You can get the list of all UDP port connection by using `-au` with `netstat`.
```
netstat -au
```
- You can get the list of all active connection by using `-l` with `netstat`.
```
netstat -l
```

View File

@@ -0,0 +1,54 @@
# The `ps` command
The `ps` command is used to identify programs and processes that are running on the system and the resources they are using.
Its frequently [pipelined](<https://en.wikipedia.org/wiki/Pipeline_(Unix)>) with other commands like `grep` to search for a program/process or `less`
so that the user can analyze the output one page at a time.
Let's say you have a program like openshot which is notorious for hogging system resources when exporting a video, and you want to close it, but the GUI has become unresponsive.
### Example
1. You want to find the PID of openshot and kill it.
```
ps aux | grep openshot
kill - <openshot PID>
```
2. To Show all the running processes:
```
ps -A
```
### Syntax
`ps [options]`
When run without any options, it's useless and will print: `CMD` - the executable processes/(program) running, their `PID` - process ID, `TTY` - terminal type and `Time` - How long the process has utilized the CPU or thread.
### Common Option
If you are going to remember only one thing from this page let it be these three letter `aux`:
`a` - which displays all processes running, including those being run by other users.
`u` - which shows the effective user of a process, i.e. the person whose file access permissions are used by the process.
`x` - which shows processes that do not have a `TTY` associated with them.
### Additional Options:
|**Option** |**Description** |
|:---|:---|
|`a`|Shows list all processes with a terminal (tty)|
|`-A`|Lists all processes. Identical to `-e`|
|`-a`|Shows all processes except both session leaders and processes not associated with a terminal|
|`-d`|Select all processes except session leaders|
|`--deselect`|Shows all processes except those that fulfill the specified conditions. Identical to `-N`|
|`-e`|Lists all processes. Identical to `-A`|
|`-N`|Shows all processes except those that fulfill the specified conditions. Identical to `-deselect`|
|`T`|Select all processes associated with this terminal. Identical to the `-t` option without any argument|
|`r`|Restrict the selection to only running processes|
|`--help simple`|Shows all the basic options|
|`--help all`|Shows every available options|
Another useful command which give a realtime snapshot of the processes and the resources they are using about every ten seconds is `top`.

View File

@@ -0,0 +1,92 @@
# The `top/htop` command
`top` is the default command-line utility that comes pre-installed on Linux distributions and Unix-like operating systems. It is used for displaying information about the system and its top CPU-consuming processes as well as RAM usage.
`htop` is interactive process-viewer and process-manager for Linux and Unix-like operating system based on ncurses. If you take top and put it on steroids, you get htop.
## Comparison between top and htop:
|**Feature** |**top** |**htop** |
|:---|:---|:---|
|Type|Interactive system-monitor, process-viewer and process-manager|Interactive system-monitor, process-viewer and process-manager|
|Operating System|Linux distributions, macOS |Linux distributions, macOS |
|Installation|Built-in and is always there. Also has more adoption due to this fact.|Doesn't come preinstalled on most Linux distros. Manual installation is needed|
|User Interface|Basic text only|Colorful and nicer text-graphics interface|
|Scrolling Support|No|Yes, supports horizontal and vertical scrolling|
|Mouse Support|No|Yes|
|Process utilization|Displays processes but not in tree format|Yes, including user and kernel threads|
|Scrolling Support|No|Yes, supports horizontal and vertical scrolling|
|Mouse Support|No|Yes|
|Process utilization|Displays processes but not in tree format|Yes, including user and kernel threads|
|Network Utilization|No|No|
|Disk Utilization|No|No|
|Comments|Has a learning curve for some advanced options like searching, sending messages to processes, etc. It is good to have some knowledge of top because it is the default process viewer on many systems.|Easier to use and supports vi like searching with `/`. Sending messages to processes (kill, renice) is easier and doesn't require typing in the process number like top.|
## Examples:
### `top`
1. To display dynamic real-time information about running processes:
```
top
```
2. Sorting processes by internal memory size (default order - process ID):
```
top -o mem
```
3. Sorting processes first by CPU, then by running time:
```
top -o cpu -O time
```
4. Display only processes owned by given user:
```
top -user {user_name}
```
### `htop`
1. Display dynamic real-time information about running processes. An enhanced version of `top`.
```
htop
```
2. displaying processes owned by a specific user:
```
htop --user {user_name}
```
3. Sort processes by a specified `sort_item` (use `htop --sort help` for available options):
```
htop --sort {sort_item}
```
## Syntax:
```
top [OPTIONS]
```
```
htop [OPTIONS]
```
## Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-a`|<center>-</center>|Sort by memory usage.|
|`-b`|<center>-</center>|Batch mode operation. Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.|
|`-h`|<center>-</center>|`top --user {user_name}` Only display processes owned by user.|
|`-U`|<center>-user</center>|Help.|
|`-u`|<center>-</center>|This is an alias equivalent to: -o cpu -O time.|

View File

@@ -0,0 +1,51 @@
# The `curl` command
In linux, `curl` is a tool to transfer data from or to a server, using one of the supported protocols(DICT, FILE ,FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP).
## Example :
```bash
$ curl example.com
```
The command will print the source code of the example.com homepage in the terminal window.
## The syntax of the `curl` command is :
```bash
$ curl [options...] <url>
```
## Options :
Options start with one or two dashes. Many of the options require an additional value next to them.
The short "single-dash" form of the options, `-d` for example, may be used with or without a space between it and its value, although a space is a recommended separator. The long "double-dash" form, `-d`, `--data` for example, requires a space between it and its value.
Short version options that don't need any additional values can be used immediately next to each other, like for example you can specify all the options `-O`, `-L` and `-v` at once as `-OLv`.
In general, all boolean options are enabled with `--option` and yet again disabled with `--no-option`. That is, you use the exact same option name but prefix it with `no-`. However, in this list we mostly only list and show the `--option` version of them. (This concept with `--no` options was added in 7.19.0. Previously most options were toggled on/off through repeated use of the same command line option.)
## Installation:
The curl command comes with most of the Linux distributions. But, if the system does not carry the curl by default. You need to install it manually. To install the curl, execute the following commands:
Update the system by executing the following commands:
```bash
$ sudo apt update
$ sudo apt upgrade
```
Now, install the curl utility by executing the below command:
```bash
$ sudo apt install curl
```
Verify the installation by executing the below command:
```bash
$ curl -version
```
The above command will display the installed version of the curl command.

View File

@@ -0,0 +1,101 @@
# The `ifconfig` command
`ifconfig` is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.
If no arguments are given, `ifconfig` displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.
### Syntax:
```
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options
```
### Examples:
1. To display the currently active interfaces:
```
ifconfig
```
2. To show all interfaces which are currently active, even if down:
```
ifconfig -a
```
3. To show all the error conditions:
```
ifconfig -v
```
4. To show a short list:
```
ifconfig -s
```
5. To display details of the specific network interface (say `eth0`):
```
ifconfig eth0
```
6. To activate the driver for a interface (say `eth0`):
```
ifconfig eth0 up
```
7. To deactivate the driver for a interface (say `eth0`):
```
ifconfig eth0 down
```
8. To assign a specific IP address to a network interface (say `eth0`):
```
ifconfig eth0 10.10.1.23
```
9. To change MAC(Media Access Control) address of a network interface (say `eth0`):
```
ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF
```
10. To define a netmask for a network interface (say `eth0`):
```
ifconfig eth0 netmask 255.255.255.224
```
11. To enable promiscous mode on a network interface (say `eth0`):
```
ifconfig eth0 promisc
```
In normal mode, when a packet is received by a network card, it verifies that it belongs to itself. If not, it drops the packet normally. However, in the promiscuous mode, it accepts all the packets that flow through the network card.
12. To disable promiscous mode on a network interface (say `eth0`):
```
ifconfig eth0 -promisc
```
13. To set the maximum transmission unit to a network interface (say `eth0`):
```
ifconfig eth0 mtu 1000
```
The MTU allows you to set the limit size of packets that are transmitted on an interface. The MTU is able to handle a maximum number of octets to an interface in one single transaction.
14. To add additional IP addresses to a network interface, you can configure a network alias to the network interface:
```
ifconfig eth0:0 10.10.1.24
```
Please note that the alias network address is in the same subnet mask of the network interface. For example, if your eth0 network ip address is `10.10.1.23`, then the alias ip address can be `10.10.1.24`. Example of an invalid IP address is `10.10.2.24` since the interface subnet mask is `255.255.255.224`
15. To remove a network alias:
```
ifconfig eth0:0 down
```
Remember that for every scope (i.e. same net with address/netmask combination) all aiases are deleted, if you delete the first alias.
### Help Command
Run below command to view the complete guide to `ifconfig` command.
```
man ifconfig
```

View File

@@ -0,0 +1,46 @@
# The `nslookup` command
The `nslookup` command is a network administration command-line tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or any other specific DNS record.
## Syntax
```
nslookup [options] [host]
```
## Options
Some popular option flags include:
```
-domain=[domain-name] Change the default DNS name.
-debug Show debugging information.
-port=[port-number] Specify the port for queries. The default port number is 53.
-timeout=[seconds] Specify the time allowed for the server to respond.
-type=a View information about the DNS A address records.
-type=any View all available records.
-type=hinfo View hardware-related information about the host.
-type=mx View Mail Exchange server information.
-type=ns View Name Server records.
-type=ptr View Pointer records. Used in reverse DNS lookups.
-type=soa View Start of Authority records.
```
## Few Examples:
1. Query DNS Server
```
nslookup www.google.com
```
2. Specify a port to query
```
nslookup -port=53 www.google.com
```
3. Get the MX Record
```
nslookup -type=mx google.com
```
Here I showed you how to use the nslookup command in Linux. Although there are other DNS lookup tools, such as dig, nslookup could be a better choice as it is a powerful tool present in almost every system.
For more details: [Nslookup on Wikipedia](https://en.wikipedia.org/wiki/Nslookup)

View File

@@ -0,0 +1,59 @@
# The `ping` command
The `ping` (Packet Internet Groper) command is a network utility used to check network connectivity between a host and a server or another host. It sends ICMP (Internet Control Message Protocol) echo requests to a specified IP address or URL and measures the time it takes to receive a response. This time delay is referred to as "latency." Ping is a fundamental tool for network troubleshooting and monitoring.
## Understanding Latency
Latency, in the context of networking, is the time delay between sending a packet and receiving a response.
When you use the `ping` command, it measures the latency by sending a series of packets to the target host and calculating the time it takes for each packet to complete the round trip. The latency is typically measured in milliseconds (ms). Understanding latency is essential because:
- **Network Performance**: Lower latency means faster data transmission and more responsive network connections, which is critical for real-time applications.
- **Troubleshooting**: High latency can indicate network congestion, packet loss, or connectivity issues that need attention.
- **Quality of Service (QoS)**: Service providers and network administrators use latency metrics to ensure that network services meet quality standards.
The basic ping syntax includes ping followed by a hostname, a name of a website, or the exact IP address.
```
ping [option] [hostname] or [IP address]
```
### Examples:
1. To get ping version installed on your system.
```
sudo ping -v
```
2. To check whether a remote host is up, in this case, google.com, type in your terminal:
```
ping google.com
```
3. Controlling the number of packets to send:
Earlier we did not define the number of packets to send to the server/host by using -c option we can do so.
```
ping -c 5 google.com
```
4. Controlling the size of the packet:
Earlier a default sized packets were sent to a host but we can send light and heavy packet by using
-s option.
```
ping -s 40 -c 5 google.com
```
5. Changing the time interval between ping packets:
By default ping wait for 1 sec to send next packet we can change this time by using -i option.
```
ping -i 2 google.com
```

View File

@@ -0,0 +1,86 @@
# The `ssh` command
The `ssh` command in Linux stands for "Secure Shell". It is a protocol used to securely connect to a remote server/system. ssh is more secure in the sense that it transfers the data in encrypted form between the host and the client. ssh runs at TCP/IP port 22.
### Examples:
1. Use a Different Port Number for SSH Connection:
```
ssh test.server.com -p 3322
```
2. -i ssh to remote server using a private key?
```
ssh -i private.key user_name@host
```
3. -l ssh specifying a different username
```
ssh -l alternative-username sample.ssh.com
```
### Syntax:
```
ssh user_name@host(IP/Domain_Name)
```
```
ssh -i private.key user_name@host
```
```
ssh sample.ssh.com ls /tmp/doc
```
### Additional Flags and their Functionalities:
|**Flag** |**Description** |
|:---|:---|
|`-1`|Forces ssh to use protocol SSH-1 only.|
|`-2`|Forces ssh to use protocol SSH-2 only.|
|`-4`|Allows IPv4 addresses only.|
|`-A`|Authentication agent connection forwarding is enabled..|
|`-a`|Authentication agent connection forwarding is disabled.|
|`-B bind_interface`|Bind to the address of bind_interface before attempting to connect to the destination host. This is only useful on systems with more than one address.|
|`-b bind_address`|Use bind_address on the local machine as the source address of the connection. Only useful on systems with more than one address.
|`-C`|Compresses all data (including stdin, stdout, stderr, and data for forwarded X11 and TCP connections) for a faster transfer of data.|
|`-c cipher_spec`|Selects the cipher specification for encrypting the session.|
|`-D [bind_address:]port`|Dynamic application-level port forwarding. This allocates a socket to listen to port on the local side. When a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine.|
|`-E log_file`|Append debug logs instead of standard error.|
|`-e escape_char`|Sets the escape character for sessions with a pty (default: ~). The escape character is only recognized at the beginning of a line. The escape character followed by a dot (.) closes the connection; followed by control-Z suspends the connection; and followed by itself sends the escape character once. Setting the character to “none” disables any escapes and makes the session fully transparent.|
|`-F configfile`|Specifies a per-user configuration file. The default for the per-user configuration file is ~/.ssh/config.|
|`-f`|Requests ssh to go to background just before command execution.|
|`-G`|Causes ssh to print its configuration after evaluating Host and Match blocks and exit.|
|`-g`|Allows remote hosts to connect to local forwarded ports.|
|`-I pkcs11`|Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing keys.|
|`-i identity_file`|A file from which the identity key (private key) for public key authentication is read.|
|`-J [user@]host[:port]`|Connect to the target host by first making a ssh connection to the pjump host[(/iam/jump-host) and then establishing a TCP forwarding to the ultimate destination from there.|
|`-K`|Enables GSSAPI-based authentication and forwarding (delegation) of GSSAPI credentials to the server.|
|`-k`|Disables forwarding (delegation) of GSSAPI credentials to the server.|
|`-L [bind_address:]port:host:hostport`, `-L [bind_address:]port:remote_socket`, `-L local_socket:host:hostport`, `-L local_socket:remote_socket`|Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side. This works by allocating a socket to listen to either a TCP port on the local side, optionally bound to the specified bind_address, or to a Unix socket. Whenever a connection is made to the local port or socket, the connection is forwarded over the secure channel, and a connection is made to either host port hostport, or the Unix socket remote_socket, from the remote machine.|
|`-l login_name`|Specifies the user to log in as on the remote machine.|
|`-M`|Places the ssh client into “master” mode for connection sharing. Multiple -M options places ssh into “master” mode but with confirmation required using ssh-askpass before each operation that changes the multiplexing state (e.g. opening a new session).|
|`-m mac_spec`|A comma-separated list of MAC (message authentication code) algorithms, specified in order of preference.|
|`-N`|Do not execute a remote command. This is useful for just forwarding ports.|
|`-n`|Prevents reading from stdin.|
|`-O ctl_cmd`|Control an active connection multiplexing master process. When the -O option is specified, the ctl_cmd argument is interpreted and passed to the master process. Valid commands are: “check” (check that the master process is running), “forward” (request forwardings without command execution), “cancel” (cancel forwardings), “exit” (request the master to exit), and “stop” (request the master to stop accepting further multiplexing requests).|
|`-o`|Can be used to give options in the format used in the configuration file. This is useful for specifying options for which there is no separate command-line flag.|
|`-p`, `--port PORT`|Port to connect to on the remote host.|
|`-Q query_option`|Queries ssh for the algorithms supported for the specified version 2. The available features are: cipher (supported symmetric ciphers), cipher-auth (supported symmetric ciphers that support authenticated encryption), help (supported query terms for use with the -Q flag), mac (supported message integrity codes), kex (key exchange algorithms), kex-gss (GSSAPI key exchange algorithms), key (keytypes), key-cert (certificate key types), key-plain (non-certificate key types), key-sig (all keytypes and signature algorithms), protocol-version (supported SSH protocol versions), and sig (supported signature algorithms). Alternatively, any keyword from ssh_config(5) or sshd_config(5) thattakes an algorithm list may be used as an alias for the corresponding query_option.|
|`-q`| Qiet mode. Causes most warning and diagnostic messages to be suppressed.|
|`-R [bind_address:]port:host:hostport, -R [bind_address:]port:local_socket, -R remote_socket:host:hostport, -R remote_socket:local_socket, -R [bind_address:]port`|Specifies that connections to the given TCP port or Unix socket on the remote (server) host are to be forwarded to the local side.|
|`-S ctl_path`|Specifies the location of a control socket for connection sharing, or the string “none” to disable connection sharing.|
|`-s`|May be used to request invocation of a subsystem on the remote system. Subsystems facilitate the use of SSH as a secure transport for other applications (e.g. sftp(1)). The subsystem is specified as the remote command.|
|`-T`| Disable pseudo-terminal allocation.|
|`-t`|Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
|`-V`|Display the version number.|
|`-v`|Verbose mode. It echoes everything it is doing while establishing a connection. It is very useful in the debugging of connection failures.|
|`-W host:port`|Requests that standard input and output on the client be forwarded to host on port over the secure channel. Implies -N, -T, ExitOnForwardFailure and ClearAllForwardings, though these can be overridden in the configuration file or using -o command line options.|
|`-w local_tun[remote_tun]`|Requests tunnel device forwarding with the specified tun devices between the client (local_tun) and the server (remote_tun). The devices may be specified by numerical ID or the keyword “any”, which uses the next available tunnel device. If remote_tun is not specified, it defaults to “any”. If the Tunnel directive is unset, it will be set to the default tunnel mode, which is “point-to-point”. If a different Tunnel forwarding mode it desired, then it should be specified before -w.|
|`-X`|Enables X11 forwarding (GUI Forwarding).|
|`-x`|Disables X11 forwarding (GUI Forwarding).|
|`-Y`|Enables trusted X11 Forwarding.|
|`-y`|Send log information using the syslog system module. By default this information is sent to stderr.|

View File

@@ -0,0 +1,51 @@
# The `wget` command
The `wget` command is used for downloading files from the Internet. It supports downloading files using HTTP, HTTPS and FTP protocols. It allows you to download several files at once, download in the background, resume downloads, limit the bandwidth, mirror a website, and much more.
## Syntax
The `wget` syntax requires you to define the downloading options and the URL the to be downloaded file is coming from.
```bash
$ wget [options] [URL]
```
### Examples
In this example we will download the Ubuntu 20.04 desktop iso file from different sources. Go over to your terminal or open a new one and type in the below `wget`. This will stat the download. The download may take a few minutes to complete.
1. Starting a regular download
```bash
wget https://releases.ubuntu.com/20.04/ubuntu-20.04.3-desktop-amd64.iso
```
2. You can resume a download using the `-c` option
```bash
wget -c https://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu-releases/20.04.3/ubuntu-20.04.3-desktop-amd64.iso
```
3. To download in the background, use the `-b` option
```bash
wget -b https://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu-releases/20.04.3/ubuntu-20.04.3-desktop-amd64.iso
```
## More options
On top of downloading, `wget` provides many more features, such as downloading multiple files, dowloading in the background, limiting download bandwith and resuming stopped downloads. View all `wget` options in its man page.
```bash
man wget
```
### Additional Flags and their Functionalities
| **Short Flag** | **Description** |
| -------------- | ----------------------------------------------------------------------------- |
| `-v` | prints version of the wget available on your system |
| `-h` | print help message displaying all the possible options |
| `-b` | This option is used to send a process to the background as soon as it starts. |
| `-t` | This option is used to set number of retries to a specified number of times |
| `-c` | This option is used to resume a partially downloaded file |

View File

@@ -0,0 +1,89 @@
# The `kill` command
`kill` command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. The `kill` command sends a signal to a process which terminates the process. If the user doesnt specify any signal which is to be sent along with kill command then default _TERM_ signal is sent that terminates the process.
Signals can be specified in three ways:
- **By number (e.g. -5)**
- **With SIG prefix (e.g. -SIGkill)**
- **Without SIG prefix (e.g. -kill)**
### Syntax
```
kill [OPTIONS] [PID]...
```
### Examples:
1. To display all the available signals you can use below command option:
```
kill -l
```
2. To show how to use a _PID_ with the _kill_ command.
```
$kill pid
```
3. To show how to send signal to processes.
```
kill {-signal | -s signal} pid
```
4. Specify Signal:
- using numbers as signals
```
kill -9 pid
```
- using SIG prefix in signals
```
kill -SIGHUP pid
```
- without SIG prefix in signals
```
kill -HUP pid
```
### Arguments:
The list of processes to be signaled can be a mixture of names and PIDs.
pid Each pid can be expressed in one of the following ways:
n where n is larger than 0. The process with PID n is signaled.
0 All processes in the current process group are signaled.
-1 All processes with a PID larger than 1 are signaled.
-n where n is larger than 1. All processes in process group n are signaled.
When an argument of the form '-n' is given, and it is meant to denote a
process group, either a signal must be specified first, or the argument must
be preceded by a '--' option, otherwise it will be taken as the signal to
send.
name All processes invoked using this name will be signaled.
### Options:
-s, --signal signal
The signal to send. It may be given as a name or a number.
-l, --list [number]
Print a list of signal names, or convert the given signal number to a name. The
signals can be found in /usr/include/linux/signal.h.
-L, --table
Similar to -l, but it will print signal names and their corresponding numbers.
-a, --all
Do not restrict the command-name-to-PID conversion to processes with the same UID
as the present process.
-p, --pid
Only print the process ID (PID) of the named processes, do not send any signals.
--verbose
Print PID(s) that will be signaled with kill along with the signal.

View File

@@ -0,0 +1,129 @@
# The `killall` command
`killall` sends a signal to **all** processes running any of the specified commands. If no signal name is specified, `SIGTERM` is sent. In general, `killall` command kills all processes by knowing the name of the process.
Signals can be specified either by name (e.g. `-HUP` or `-SIGHUP`) or by number (e.g. `-1`) or by option `-s`.
If the command name is not a regular expression (option `-r`) and contains a slash (`/`), processes executing that particular file will be selected for killing, independent of their name.
`killall` returns a zero return code if at least one process has been killed for each listed command, or no commands were listed and at least one process matched the `-u` and `-Z` search criteria. `killall` returns non-zero otherwise.
A `killall` process never kills itself (but may kill other `killall` processes).
### Examples:
1. Kill all processes matching the name `conky` with `SIGTERM`:
```sh
killall conky
# OR
killall -SIGTERM conky
# OR
kilall -15 conky
```
I was able to kill Wine ( which are Windows exe files running on Linux ) applications this way too.
```sh
killall TQ.exe
```
2. List all the supported signals:
```sh
$ killall -l
HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
```
As for the numbers.
```sh
$ for s in $(killall -l); do echo -n "$s " && kill -l $s; done
HUP 1
INT 2
QUIT 3
ILL 4
TRAP 5
ABRT 6
BUS 7
FPE 8
KILL 9
USR1 10
SEGV 11
USR2 12
PIPE 13
ALRM 14
TERM 15
STKFLT 16
CHLD 17
CONT 18
STOP 19
TSTP 20
TTIN 21
TTOU 22
URG 23
XCPU 24
XFSZ 25
VTALRM 26
PROF 27
WINCH 28
POLL 29
PWR 30
SYS 31
```
3. Ask before killing, to prevent unwanted kills:
```sh
$ killall -i conky
Kill conky(1685) ? (y/N)
```
4. Kill all processes and wait until the processes die.
```sh
killall -w conky
```
5. Kill based on time:
```sh
# Kill all firefox younger than 2 minutes
killall -y 2m firefox
# Kill all firefox older than 2 hours
killall -o 2h firefox
```
### Syntax:
```sh
killall [OPTION]... [--] NAME...
killall -l, --list
killall -V, --version
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-e`|`--exact`|require an exact match for very long names|
|`-I`|`--ignore-case`|case insensitive process name match|
|`-g`|`--process-group`|kill process group instead of process|
|`-y`|`--younger-than`|kill processes younger than TIME|
|`-o`|`--older-than`|kill processes older than TIME|
|`-i`|`--interactive`|ask for confirmation before killing|
|`-l`|`--list`|list all known signal names|
|`-q`|`--quiet`|don't print complaints|
|`-r`|`--regexp`|interpret NAME as an extended regular expression|
|`-s`|`--signal SIGNAL`|send this signal instead of SIGTERM|
|`-u`|`--user USER`|kill only process(es) running as USER|
|`-v`|`--verbose`|report if the signal was successfully sent|
|`-w`|`--wait`|wait for processes to die|
|`-n`|`--ns PID`|match processes that belong to the same namespaces as PID
|`-Z`|`--context`|REGEXP kill only process(es) having context (must precede other arguments)
### Related commands
[kill](/ebook/en/content/034-the-kill-command.md), `pidof`

View File

@@ -0,0 +1,18 @@
# The `nohup` command
When a shell exits (maybe while logging out of an SSH session), the HUP ('hang up') signal is send to all of its child processes, causing them to terminate. If you require a long-running process to continue after exiting shell, you'll need the `nohup` command. Prefixing any command with `nohup` causes the command to become _immune_ to HUP signals. Additionally, STDIN is being ignored and all output gets redirected to local file `./nohup.out`.
### Examples:
1. Applying nohup to a long-running debian upgrade:
```
nohup apt-get -y upgrade
```
### Syntax:
```
nohup COMMAND [ARG]...
nohup OPTION
```

View File

@@ -0,0 +1,80 @@
# The `apt` command
`apt` (Advantage package system) command is used for interacting with `dpkg` (packaging system used by debian). There is already the `dpkg` command to manage `.deb` packages. But `apt` is a more user-friendly and efficient way.
In simple terms `apt` is a command used for installing, deleting and performing other operations on debian based Linux.
You will be using the `apt` command mostly with `sudo` privileges.
### Installing packages:
`install` followed by `package_name` is used with `apt` to install a new package.
##### Syntax:
```
sudo apt install package_name
```
##### Example:
```
sudo apt install g++
```
This command will install g++ on your system.
### Removing packages:
`remove` followed by `package_name` is used with `apt` to remove a specific package.
##### Syntax:
```
sudo apt remove package_name
```
##### Example:
```
sudo apt remove g++
```
This command will remove g++ from your system.
### Searching for a package:
`search` followed by the `package_name` used with apt to search a package across all repositories.
##### Syntax:
```
apt search package_name
```
note: sudo not required
##### Example:
```
apt search g++
```
### Removing unused packages:
Whenever a new package that depends on other packages is installed on the system, the package dependencies will be installed too. When the package is removed, the dependencies will stay on the system. This leftover packages are no longer used by anything else and can be removed.
##### Syntax:
```
sudo apt autoremove
```
This command will remove all unused from your system.
### Updating package index:
`apt` package index is nothing but a database that stores records of available packages that are enabled on your system.
##### Syntax:
```
sudo apt update
```
This command will update the package index on your system.
### Upgrading packages:
If you want to install the latest updates for your installed packages you may want to run this command.
##### Syntax:
```
sudo apt upgrade
```
The command doesn't upgrade any packages that require removal of installed packages.
If you want to upgrade a single package, pass the package name:
##### Syntax:
```
sudo apt upgrade package_name
```
This command will upgrade your packages to the latest version.

View File

@@ -0,0 +1,61 @@
# The `yum` command
The `yum`command is the primary package management tool for installing, updating, removing, and managing software packages in Red Hat Enterprise Linux. It is an acronym for _`Yellow Dog Updater, Modified`_.
`yum` performs dependency resolution when installing, updating, and removing software packages. It can manage packages from installed repositories in the system or from .rpm packages.
### Syntax:
```[linux]
yum -option command
```
### Examples:
1. To see an overview of what happened in past transactions:
```[linux]
yum history
```
2. To undo a previous transaction:
```[linux]
yum history undo <id>
```
3. To install firefox package with 'yes' as a response to all confirmations
```[linux]
yum -y install firefox
```
4. To update the mysql package it to the latest stable version
```[linux]
yum update mysql
```
### Commonly used commands along with yum:
| **Command** | **Description** |
| :------------- | :------------------------------------------------ |
| `install` | Installs the specified packages |
| `remove` | Removes the specified packages |
| `search` | Searches package metadata for keywords |
| `info` | Lists the description |
| `update` | Updates each package to the latest version |
| `repolist` | Lists repositories |
| `history` | Displays what has happened in past transactions |
| `groupinstall` | To install a particular package group |
| `clean` | To clean all cached files from enabled repository |
### Additional Flags and their Functionalities:
| **Short Flag** | **Long Flag** | **Description** |
| :---------------- | :-------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-C` | `--cacheonly` | Runs entirely from system cache, doesnt update the cache and use it even in case it is expired. |
| <center>-<center> | `--security` | Includes packages that provide a fix for a security issue. Applicable for the upgrade command. |
| `-y` | `--assumeyes` | Automatically answer yes for all questions. |
| <center>-<center> | `--skip-broken` | Resolves depsolve problems by removing packages that are causing problems from the transaction. It is an alias for the strict configuration option with value False. |
| `-v` | `--verbose` | Verbose operation, show debug messages. |

View File

@@ -0,0 +1,45 @@
# The `crontab` command
`crontab` is used to maintain crontab files for individual users (Vixie Cron)
crontab is the program used to install, uninstall or list the tables used to drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab, and though these are files in `/var/spool/cron/crontabs`, they are not intended to be edited directly.
### Syntax:
```
crontab [ -u user ] file
crontab [ -u user ] [ -i ] { -e | -l | -r }
```
### Examples:
1. The -l option causes the current crontab to be displayed on standard output.
```
crontab -l
```
2. The -r option causes the current crontab to be removed.
```
crontab -r
```
3. The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically. If neither of the environment variables is defined, then the default editor /usr/bin/editor is used.
```
crontab -e
```
4. You can specify the user you want to edit the crontab for. Every user has its own crontab. Assume you have a `www-data` user, which is in fact the user Apache is default running as. If you want to edit the crontab for this user you can run the following command
```
crontab -u www-data -e
```
### Help Command
Run below command to view the complete guide to `crontab` command.
```
man crontab
```

View File

@@ -0,0 +1,114 @@
# The `date` command
The `date` command is used to print the system current date and time.
`date` command is also used to set the date and time of the system, but you need to be the super-user *(root)* to do it.
### Examples:
1. To show the current date and time:
```
date
```
2. You can use -u option to show the date and time in UTC *(Coordinated Universal Time)* time zone
```
date -u
```
1. To display any given date string in formatted date:
```
date --date="2/02/2010"
date --date="2 years ago"
```
### Syntax:
```
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-d`|`--date=STRING`|convert the provided string into formatted date|
|`-f`|`--file=DATEFILE`|like `--date` but for files|
|`-I[FMT]`|`--iso-8601[=FMT]`|Display date and time in ISO 8601 format|
|`-r`|`--reference=FILE`|Display the last modification time of FILE|
|`-s`|`--set=STRING`|sets the time to the one described by STRING|
|`-u`|`--universal`|show the date and time in UTC *(Coordinated Universal Time)* time zone|
|`-R`|`--rfc-email`|Display date and time in ISO 8601 format Example: (Fri, 22 Oct 2021 05:18:42 +0200)|
|<center>-<center>|`rfc-3339=FMT`|Display date and time in RFC 3339 format|
|<center>-<center>|`--debug`|Usually used with `--date` to annotate the parsed date and warn about questionable usage to stderr|
### Control The output:
You can use Format specifiers to control the output date and time.
### Examples:
|**Command** |**Output** |
|:---|:---|
|`$ date "+%D"`|`10/22/21`|
|`$ date "+%D %T"`|`10/22/21 05:33:51`|
|`$ date "+%A %B %d %T %y"`|`Friday October 22 05:34:47 21`|
### Syntax:
```
date "+%[format-options ...]"
```
### List of Format specifiers to control the output:
|**Specifiers** |**Description** |
|:---|:---|
|`%a`|abbreviated weekday name *(e.g., Sun)*|
|`%A`|full weekday name *(e.g., Sunday)*|
|`%b`|abbreviated month name *(e.g., Jan)*|
|`%B`|full month name *(e.g., January)*|
|`%c`|date and time *(e.g., Thu Mar 3 23:05:25 2005)*|
|`%C`|century; like %Y, except omit last two digits (e.g., 20)|
|`%d`|day of month (e.g., 01)|
|`%D`|date; same as %m/%d/%y|
|`%e`|day of month, space padded; same as %_d|
|`%F`|full date; same as %Y-%m-%d|
|`%g`|last two digits of year of ISO week number (see %G)|
|`%G`|year of ISO week number (see %V); normally useful only with %V|
|`%h`|same as %b|
|`%H`|hour (00..23)|
|`%I`|hour (01..12)|
|`%j`|day of year (001..366)|
|`%k`|hour, space padded ( 0..23); same as %_H|
|`%l`|hour, space padded ( 1..12); same as %_I|
|`%m`|month (01..12)|
|`%M`|minute (00..59)|
|`%n`|a newline|
|`%N`|nanoseconds (000000000..999999999)|
|`%p`|locale's equivalent of either AM or PM; blank if not known|
|`%P`|like %p, but lower case|
|`%q`|quarter of year (1..4)|
|`%r`|locale's 12-hour clock time (e.g., 11:11:04 PM)|
|`%R`|24-hour hour and minute; same as %H:%M|
|`%s`|seconds since 1970-01-01 00:00:00 UTC|
|`%S`|second (00..60)|
|`%t`|a tab|
|`%T`|time; same as %H:%M:%S|
|`%u`|day of week (1..7); 1 is Monday|
|`%U`|week number of year, with Sunday as first day of week (00..53)|
|`%V`|ISO week number, with Monday as first day of week (01..53)|
|`%w`|day of week (0..6); 0 is Sunday|
|`%W`|week number of year, with Monday as first day of week (00..53)|
|`%x`|locale's date representation (e.g., 12/31/99)|
|`%X`|locale's time representation (e.g., 23:13:48)|
|`%y`|last two digits of year (00..99)|
|`%Y`|year|
|`%z`|+hhmm numeric time zone (e.g., -0400)|
|`%:z`|+hh:mm numeric time zone (e.g., -04:00)|
|`%::z`|+hh:mm:ss numeric time zone (e.g., -04:00:00)|
|`%:::z`|numeric time zone with : to necessary precision (e.g., -04, +05:30)|
|`%Z`|alphabetic time zone abbreviation (e.g., EDT)|

View File

@@ -0,0 +1,26 @@
# The `hostname` command
`hostname` is used to display the system's DNS name, and to display or set its hostname or NIS domain name.
### Syntax:
```
hostname [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns] [-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis]
```
### Examples:
1. ``` hostname -a, hostname --alias ```
Display the alias name of the host (if used). This option is deprecated and should not be used anymore.
2. ```hostname -s, hostname --short```
Display the short host name. This is the host name cut at the first dot.
3. ```hostname -V, hostname --version```
Print version information on standard output and exit successfully.
### Help Command
Run below command to view the complete guide to `hostname` command.
```
man hostname
```

View File

@@ -0,0 +1,44 @@
# The `hostnamectl` command
The `hostnamectl` command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the `/etc/hostname` file on a given system.
## Syntax
```
$ hostnamectl [OPTIONS...] COMMAND ...
```
where **COMMAND** can be any of the following
**status**: Used to check the current hostname settings
**set-hostname NAME**: Used to set system hostname
**set-icon-name NAME**: Used to set icon name for host
## Example
1. Basic usage to view the current hostnames
```
$ hostnamectl
```
or
```
$ hostnamectl status
```
2. To change the static host name to _myhostname_. It may or may not require root access
```
$ hostnamectl set-hostname myhostname --static
```
3. To set or change a transient hostname
```
$ hostnamectl set-hostname myotherhostname --transient
```
4. To set the pretty hostname. The name that is to be set needs to be in the double quote(” “).
```
$ hostname set-hostname "prettyname" --pretty
```

View File

@@ -0,0 +1,56 @@
# The `reboot` Command
The `reboot` command is used to restart a linux system. However, it requires elevated permission using the [sudo](https://github.com/bobbyiliev/101-linux-commands-ebook/blob/main/ebook/en/content/051-the-sudo-command.md) command. Necessity to use this command usually arises after significant system or network updates have been made to the system.
## Syntax
```
reboot [OPTIONS...]
```
### Options
- **help** : This option prints a short help text and exit.
- **-halt** : This command will stop the machine.
- **-w**, **wtmp-only** : This option only writes wtmp shutdown entry, it do not actually halt, power-off, reboot.
### Examples
1. Basic Usage. Mainly used to restart without any further details
```
$ sudo reboot
```
However, alternatively the shutdown command with the `-r` option
```
$ sudo shutdown -r now
```
**Note** that the usage of the reboot, halt and power off is almost similar in syntax and effect. Run each of these commands with help to see the details.
2. The `reboot` command has limited usage, and the `shutdown` command is being used instead of reboot command to fulfill much more advance reboot and shutdown requirements. One of those situations is a scheduled restart. Syntax is as follows
```
$ sudo shutdown r [TIME] [MESSAGE]
```
Here the TIME has various formats. The simplest one is `now`, already been listed in the previous section, and tells the system to restart immediately. Other valid formats we have are +m, where m is the number of minutes we need to wait until restart and HH:MM which specifies the TIME in a 24hr clock.
**Example to reboot the system in 2 minutes**
```
$ sudo shutdown r +2
```
**Example of a scheduled restart at 03:00 A.M**
```
$ sudo shutdown r 03:00
```
3. Cancelling a Reboot. Usually happens in case one wants to cancel a scheduled restart
**Syntax**
```
$ sudo shutdown c [MESSAGE]
```
**Usage**
```
$sudo shutdown -c "Scheduled reboot cancelled because the chicken crossed the road"
```
4. Checking your reboot logs
```
$ last reboot
```

View File

@@ -0,0 +1,39 @@
# The `shutdown` command
The `shutdown` command lets you bring your system down in a secure way. When `shutdown` is executed the system will notify all logged-in users and disallow further logins.
You have the option to shut down your system immediately or after a specific time.
Only users with root (or sudo) privileges can use the `shutdown` command.
### Examples:
1. Shut down your system immediately:
```
sudo shutdown now
```
2. Shut down your system after 10 minutes:
```
sudo shutdown +10
```
3. Shut down your system with a message after 5 minutes:
```
sudo shutdown +5 "System will shutdown in 5 minutes"
```
### Syntax:
```
shutdown [OPTIONS] [TIME] [MESSAGE]
```
### Additional Flags and their Functionalities:
|**Short Flag** |**Long Flag** |**Description** |
|:---|:---|:---|
|`-r`|<center>-</center>|Reboot the system|
|`-c`|<center>-</center>|Cancel an scheduled shut down|

View File

@@ -0,0 +1,39 @@
# The `su` command
In linux, `su` allows you to run commands with a substitute user and group ID.
When called without arguments, `su` defaults to running an interactive shell as root.
## Example :
```bash
$ su
```
In case that you wanted to switch to a user called `devdojo`, you could do that by running the following command:
```
$ su devdojo
```
## The syntax of the `su` command is :
```bash
$ su [options] [-] [<user>[<argument>...]]
```
## Options :
```bash
-m, -p --> do not reset environment variables
-w --> do not reset specified variables
-g --> specify the primary group
-G --> specify a supplemental group
-l --> make the shell a login shell
-f --> pass -f to the shell (for csh or tcsh)
-s --> run <shell> if /etc/shell allows it
-p --> create a new pseudo terminal
-h --> display this help
-v --> display version
```

View File

@@ -0,0 +1,52 @@
# The `sudo` command
The `sudo` ("substitute user do" or "super user do") command allows a user with proper permissions to execute a command as another user, such as the superuser.
This is the equivalent of "run as administrator" option in Windows. The `sudo` command allows you to elevate your current user account to have root privileges. Also, the root privilege in `sudo` is only valid for a temporary amount of time. Once that time expires, you have to enter your password again to regain root privilege.
> WARNING: Be very careful when using the `sudo` command. You can cause irreversible and catastrophic changes while acting as root!
### Syntax:
```
sudo [-OPTION] command
```
### Additional Flags and their Functionalities:
|**Flag** |**Description** |
|:---|:---|
|`-V`|The -V (version) option causes sudo to print the version number and exit. If the invoking user is already root, the -V option prints out a list of the defaults sudo was compiled with and the machine's local network addresses|
|`-l`|The -l (list) option prints out the commands allowed (and forbidden) the user on the current host.|
|`-L`|The -L (list defaults) option lists out the parameters set in a Defaults line with a short description for each. This option is useful in conjunction with grep.|
|`-h`|The -h (help) option causes sudo to print a usage message and exit.|
|`-v`|If given the `-v` (validate) option, `sudo` updates the user's timestamp, prompting for the user's password if necessary. This extends the sudo timeout for another 5 minutes (or whatever the timeout is set to in sudoers) but does not run a command.|
|`-K`|The -K (sure kill) option to sudo removes the user's timestamp entirely. Likewise, this option does not require a password.|
|`-u`|The -u (user) option causes sudo to run the specified command as a user other than root. To specify a uid instead of a username, use #uid.|
|`-s`|The -s (shell) option runs the shell specified by the SHELL environment variable if it's set or the shell as specified in the file passwd.|
|`--`|The -- flag indicates that sudo should stop processing command line arguments. It is most useful in conjunction with the -s flag.|
## Examples
This command switches your command prompt to the BASH shell as a root user:
```
sudo bash
```
Your command line should change to:
```
root@hostname:/home/[username]
```
Adding a string of text to a file is often used to add the name of a software repository to the sources file, without opening the file for editing. Use the following syntax with echo, sudo and tee command:
```
echo string-of-text | sudo tee -a [path_to_file]
```
Example:
````
echo "deb http://nginx.org/packages/debian `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
````

View File

@@ -0,0 +1,31 @@
# The `uname` command
The `uname` command lets you print out system information and defaults to outputting the kernel name.
## Syntax:
```bash
$ uname [OPTION]
```
## Examples
1. Print out all system information.
```bash
$ uname -a
```
2. Print out the kernel version.
```bash
$ uname -v
```
## Options
|**Short Flag**|**Long Flag**|**Description**|
|:-|:-|:-|
|`-a`|`--all`|Print all information, except omit processor and hardware platform if unknown.|
|`-s`|`--kernel-name`|Print the kernel name.|
|`-n`|`--nodename`|Print the network node hostname.|
|`-r`|`--kernel-release`|Print the kernel release.|
|`-v`|`--kernel-version`|Print the kernel version.|
|`-m`|`--machine`|Print the machine hardware name.|
|`-p`|`--processor`|Print the processor type (non-portable).|
|`-i`|`--hardware-platform`|Print the hardware platform (non-portable).|
|`-o`|`--operating-system`|Print the operating system.|

View File

@@ -0,0 +1,67 @@
# The `chmod` command
The `chmod` command allows you to change the permissions on a file using either a symbolic or numeric mode or a reference file.
### Examples:
1. Change the permission of a file using symbolic mode:
```
chmod u=rwx,g=rx,o=r myfile
```
The command above means :
- user can read, write, execute `myfile`
- group can read, execute `myfile`
- other can read `myfile`
2. Change the permission of a file using numeric mode
```
chmod 754 myfile user:group file.txt
```
The command above means :
- user can read, write, execute `myfile`
- group can read, execute `myfile`
- other can read `myfile`
3. Change the permission of a folder recursively
```
chmod -R 754 folder
```
### Syntax:
```
chmod [OPTIONS] MODE FILE(s)
```
- `[OPTIONS]` :
`-R`: recursive, mean all file inside directory
- `MODE`: different way to set permissions:
- **Symbolic mode explained**
- u: user
- g: group
- o: other
- =: set the permission
- r: read
- w: write
- x: execute
- example `u=rwx` means user can read write and execute
- **Numeric mode explained**:
The **numeric mode** is based off of a binary representation of the permissions for user, group, and others, for more information please look at this [explanation](https://www.digitalocean.com/community/tutorials/linux-permissions-basics-and-how-to-use-umask-on-a-vps#types-of-permissions) from Digital Ocean's community section:
- 4 stands for "read",
- 2 stands for "write",
- 1 stands for "execute", and
- 0 stands for "no permission."
- example 7 mean read + write + execute

View File

@@ -0,0 +1,36 @@
# The `chown` command
The `chown` command makes it possible to change the ownership of a file or directory. Users and groups are fundamental in Linux, with `chown` you can
change the owner of a file or directory. It's also possible to change ownership on folders recursively
### Examples:
1. Change the owner of a file
```
chown user file.txt
```
2. Change the group of a file
```
chown :group file.txt
```
3. Change the user and group in one line
```
chown user:group file.txt
```
4. Change to ownership on a folder recursively
```
chown -R user:group folder
```
### Syntax:
```
chown [-OPTION] [DIRECTORY_PATH]
```

View File

@@ -0,0 +1,40 @@
# The `deluser` command
The `deluser` command is used to delete a user account and related files
## Command Demo
<video src="/videos/commands/the-deluser-command.mp4" width="640" height="480" controls></video>
## Delete User
To delete a user with the `deluser` command the syntax would be the following:
```
deluser userName
```
## Delete User & Home Directory
To delete a user along with the files in the users home directory using the `deluser` command the syntax would be the following:
```
deluser --remove-home userName
```
## Basic Syntax:
```
deluser [options] [--force] [--remove-home] [--remove-all-files]
[--backup] [--backup-to DIR] user
```
## Possible Options:
|**Flag** |**Description** |
|:---|:---|
|`-f`|Force the removal of the specified user account even if the user is logged in|
|`-r`|Remove the files in the users home directory along with the home directory itself and the users mail spool|
|`-Z`|Remove any SELinux(Security-Enhanced Linux) user mapping for the users login.|

View File

@@ -0,0 +1,45 @@
# The `groups` command
In Linux, there can be multiple users (those who use/operate the system), and groups (a collection of users).
Groups make it easy to manage users with the same security and access privileges. A user can be part of different groups.
Important Points:
The `groups` command prints the names of the primary and any supplementary groups for each given username, or the current process if no names are given.
If more than one name is given, the name of each user is printed before the list of that users groups and the username is separated from the group list by a colon.
### Syntax:
```
groups [username]
```
#### Example 1
Provided with a username
```
groups demon
```
In this example, username demon is passed with groups command and the output shows the groups in which the user demon is present, separated by a colon.
#### Example 2
When no username is passed then this will display the group membership for the current user:
```
groups
```
Here the current user is demon . So when we run the `groups` command without arguments we get the groups in which demon is a user.
#### Example 3
Passing root with groups command:
```
$demon# groups
```
> Note: Primary and supplementary groups for a process are normally inherited from its parent and are usually unchanged since login. This means that if you change the group database after logging in, groups will not reflect your changes within your existing login session. The only options are help and version.

View File

@@ -0,0 +1,55 @@
# The `passwd` command
In Linux, `passwd` command changes the password of user accounts. A normal user may only change the password for their own account, but a superuser may change the password for any account.
`passwd` also changes the account or associated password validity period.
## Example
```bash
$ passwd
```
## The syntax of the `passwd` command is :
```bash
$ passwd [options] [LOGIN]
```
## options
```bash
-a, --all
This option can be used only with -S and causes show status for all users.
-d, --delete
Delete a user's password.
-e, --expire
Immediately expire an account's password.
-h, --help
Display help message and exit.
-i, --inactive
This option is used to disable an account after the password has been expired for a number of days.
-k, --keep-tokens
Indicate password change should be performed only for expired authentication tokens (passwords).
-l, --lock
Lock the password of the named account.
-q, --quiet
Quiet mode.
-r, --repository
change password in repository.
-S, --status
Display account status information.
```

View File

@@ -0,0 +1,43 @@
# The `useradd` command
The `useradd` command is used to add or update user accounts to the system.
### Examples:
To add a new user with the `useradd` command the syntax would be the following:
```
useradd NewUser
```
To add a new user with the `useradd` command and give a home directory path for this new user the syntax would be the following:
```
useradd -d /home/NewUser NewUser
```
To add a new user with the `useradd` command and give it a specific id the syntax would be the following:
```
useradd -u 1234 NewUser
```
### Syntax:
```
useradd [OPTIONS] NameOfUser
```
### Possible options:
|**Flag** |**Description** |**Params** |
|:---|:---|:---|
|`-d`|The new user will be created using /path/to/directory as the value for the user's login directory|/path/to/directory|
|`-u`|The numerical value of the user's ID|ID|
|`-g`|Create a user with specific group id|GroupID|
|`-M`|Create a user without home directory|-|
|`-e`|Create a user with expiry date|DATE (format: YYYY-MM-DD)|
|`-c`|Create a user with a comment|COMMENT|
|`-s`|Create a user with changed login shell|/path/to/shell|
|`-p`|Set an unencrypted password for the user|PASSWORD|

View File

@@ -0,0 +1,80 @@
# The `usermod` command
The `usermod` command lets you change the properties of a user in Linux through the command line. After creating a user we sometimes have to change their attributes, like their password or login directory etc. So in order to do that we use the `usermod` command.
### Syntax:
```
usermod [options] USER
```
#### Note : Only superuser (root) is allowed to execute `usermod` command
### Options and their Functionalities:
|**Option** |**Description** |
|:---|:---|
|`-a`|to add anyone of the group to a secondary group|
|`-c`|to add comment field for the useraccount|
|`-d`|to modify the directory for any existing user account|
|`-g`|change the primary group for a User|
|`-G`|to add supplementary groups|
|`-l`|to change existing user login name|
|`-L`|to lock system user account|
|`-m`|to move the contents of the home directory from existing home dir to new dir|
|`-p`|to create an un-encrypted password|
|`-s`|to create a specified shell for new accounts|
|`-u`|to assigned UID for the user account|
|`-U`|to unlock any locked user|
### Examples:
1. To add a comment/description for a user:
```
sudo usermod -c "This is test user" test_user
```
2. To change the home directory of a user:
```
sudo usermod -d /home/sam test_user
```
3. To change the expiry date of a user:
```
sudo usermod -e 2021-10-05 test_user
```
4. To change the group of a user:
```
sudo usermod -g sam test_user
```
5. To change user login name:
```
sudo usermod -l test_account test_user
```
6. To lock a user:
```
sudo usermod -L test_user
```
7. To unlock a user:
```
sudo usermod -U test_user
```
8. To set an unencrypted password for the user:
```
sudo usermod -p test_password test_user
```
9. To create a shell for the user:
```
sudo usermod -s /bin/sh test_user
```
10. To change the user id of a user:
```
sudo usermod -u 1234 test_user
```

View File

@@ -0,0 +1,58 @@
# The `whoami` command
---
The `whoami` command displays the username of the current effective user. In other words it just prints the username of the currently logged-in user when executed.
To display your effective user id just type `whoami` in your terminal:
```
manish@godsmack:~$ whoami
# Output:
manish
```
Syntax:
```
whoami [-OPTION]
```
There are only two options which can be passed to it :
`--help`: Used to display the help and exit
Example:
```
whoami --help
```
Output:
```
Usage: whoami [OPTION]...
Print the user name associated with the current effective user ID.
Same as id -un.
--help display this help and exit
--version output version information and exit
```
`--version`: Output version information and exit
Example:
```
whoami --version
```
Output:
```
whoami (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Richard Mlynarik.
```