automated terminal push
This commit is contained in:
71
landing/docs/Linux-Commands/Working-With-Files/001-the-ls-command.md
Executable file
71
landing/docs/Linux-Commands/Working-With-Files/001-the-ls-command.md
Executable 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.
|
||||
|
||||
|
||||
153
landing/docs/Linux-Commands/Working-With-Files/003-the-cat-tac-command.md
Executable file
153
landing/docs/Linux-Commands/Working-With-Files/003-the-cat-tac-command.md
Executable 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|
|
||||
59
landing/docs/Linux-Commands/Working-With-Files/007-the-touch-command.md
Executable file
59
landing/docs/Linux-Commands/Working-With-Files/007-the-touch-command.md
Executable 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
|
||||
```
|
||||
44
landing/docs/Linux-Commands/Working-With-Files/014-the-mkdir-command.md
Executable file
44
landing/docs/Linux-Commands/Working-With-Files/014-the-mkdir-command.md
Executable 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.|
|
||||
103
landing/docs/Linux-Commands/Working-With-Files/031-the-cp-command.md
Executable file
103
landing/docs/Linux-Commands/Working-With-Files/031-the-cp-command.md
Executable 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|
|
||||
46
landing/docs/Linux-Commands/Working-With-Files/032-the-mv-command.md
Executable file
46
landing/docs/Linux-Commands/Working-With-Files/032-the-mv-command.md
Executable 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 |
|
||||
51
landing/docs/Linux-Commands/Working-With-Files/039-the-nano-command.md
Executable file
51
landing/docs/Linux-Commands/Working-With-Files/039-the-nano-command.md
Executable 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|
|
||||
36
landing/docs/Linux-Commands/Working-With-Files/040-the-rm-command.md
Executable file
36
landing/docs/Linux-Commands/Working-With-Files/040-the-rm-command.md
Executable 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.
|
||||
44
landing/docs/Linux-Commands/Working-With-Files/057-the-dir-command.md
Executable file
44
landing/docs/Linux-Commands/Working-With-Files/057-the-dir-command.md
Executable 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 |
|
||||
48
landing/docs/Linux-Commands/Working-With-Files/062-the-diff-sdiff-command.md
Executable file
48
landing/docs/Linux-Commands/Working-With-Files/062-the-diff-sdiff-command.md
Executable 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. |
|
||||
106
landing/docs/Linux-Commands/Working-With-Files/100-the-vim-command.md
Executable file
106
landing/docs/Linux-Commands/Working-With-Files/100-the-vim-command.md
Executable 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/)
|
||||
|
||||
70
landing/docs/Linux-Commands/Working-With-Files/102-the-find-command.md
Executable file
70
landing/docs/Linux-Commands/Working-With-Files/102-the-find-command.md
Executable 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
|
||||
```
|
||||
Reference in New Issue
Block a user