Commit 342d25

2024-03-29 21:28:17 Arpan S.: -/-
standard linux commands.md ..
@@ 3,13 3,78 @@
This page contains some standard linux commands that are available for use across all linux systems but are easy to forget that they exist or using them can get confusing sometimes.
#### `wc` Command
- This command is used to count things in linux and supports piping. It can be used for multiple purposes as shown below.
+ This command[^1wclink-ref] is used to count things in linux and supports piping. It can be used for multiple purposes as shown below.
Syntax:
```
wc OPTION... [FILE]...
```
+ ###### Options
+ - `-l` / `--lines` - Print number of lines.
+ - `-w` / `--words` - Print number of words.
+ - `-m` / `--chars` - Print the number of characters.
+ - `-c` / `--bytes` - Print the number of bytes.
+ - `-L` / `--max-line-length` - Print the length of the longest line.
+
+ Default Output:
+
+ ```
+ # wc fileA
+ 20 30 60 fileA
+ ```
+ Here, _20_ is the number of lines, _30_ is the number of words & _60_ is the number of characters in the file.
+
+ Generic uses:
+
+ Standard usage (Pipe Back)
+ ```
+ wc < fileA
+ ```
+
+ Multiple Files
+ ```
+ # wc fileA fileB
+ ```
+ _Output:_
+ ```
+ 20 40 60 fileA
+ 60 80 100 fileB
+ 80 120 160 total
+ #
+ ```
+
+ Number of words (Piped Output)
+ ```
+ cat /etc/shadow | wc -w
+ ```
+
+ Number of lines (Piped Output)
+ ```
+ cat /etc/shadow | wc -l
+ ```
+
+ ###### How to count number of lines in a file using `wc`
+ ```
+ wc -l /path/to/file
+ ```
+
+ ###### How to count number of words in a file using `wc`
+ ```
+ wc -w /path/to/file
+ ```
+
+ ###### How to count number of lines output by a command using `wc`
+ ```
+ example_command | wc -l
+ ```
+
+ ###### How to count number of files in current directory using `wc`
+ ```
+ find . -type f | wc -l
+ ```
+
+ [^1wclink-ref]: More details on this can be found [here](https://linuxize.com/post/how-to-remove-symbolic-links-in-linux/).
#### `ln` Command - How to create symbolic links / sys links in Linux.
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9