Skip to content

Commit 456cd62

Browse files
committed
Update Linux command reference
1 parent 1a4e85a commit 456cd62

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Diff for: content/blog/linux-cmds.md

+67
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,73 @@ $ find . -name "\*.html"
4242
./projects.html
4343
```
4444

45+
#### Search for a Pattern (grep)
46+
47+
```Bash
48+
# Search for a pattern in a file
49+
# By default, this is not a regular expression pattern (see the '-E' flag)
50+
$ grep "string" file.txt
51+
52+
# Search for a pattern in text read from a pipe (equivalent to above)
53+
$ cat file.txt | grep "string"
54+
55+
# Search for multiple patterns in a file
56+
$ grep -e "string1" -e "string2" file.txt
57+
58+
# Search for the pattern case-insensitive
59+
$ grep -i "String" file.txt
60+
61+
# Print line number for every matched pattern
62+
$ grep -i "String" file.txt
63+
64+
# Search for anything that doesn't match the specified pattern
65+
$ grep -v "ath10k" dmesg.txt
66+
67+
# When piping data from a file that's actively being written to
68+
# make sure to pass the '--line-buffered' argument. Otherwise,
69+
# it may not match the specified pattern, even if it's written
70+
# to the file
71+
$ tail -F log_file.txt | grep --line-buffered "canary"
72+
73+
# Search for pattern in the output of text continuously read from a pipe
74+
# (don't forget the '--line-buffered'!) then write the output to both
75+
# the terminal (stdout) and a text file
76+
$ journalctl -f | grep --line-buffered "mt7921" | tee out.txt
77+
```
78+
79+
#### Login to a Remote System (ssh)
80+
81+
```Bash
82+
# Login into a remote system over SSH
83+
# Destination system is typically an IP address, hostname, or alias
84+
85+
86+
# Remote in using a non-standard port (default is 22)
87+
# Note that the 'scp' command uses the '-P' option for port
88+
ssh -p 2222 user@server
89+
90+
# Remote in using SSH URI (equivalent to previous command)
91+
ssh ssh://user@server:2222
92+
93+
# Generate a new SSH public/private key pair
94+
#
95+
# This is used both for authentication purposes on a remote system
96+
# and identifying a remote system to your system (~/.ssh/known_hosts)
97+
ssh-keygen -t ed25519
98+
99+
# Copy an SSH public key to a remote system
100+
#
101+
# This allows you to login using the associated private key.
102+
# The '-i' flag specifies the specific key to copy. Otherwise,
103+
# the default is used (if no '.pub' specified, it's automatically added)
104+
#
105+
# You can also alternatively use the 'ssh' command to manually copy
106+
# your public key into the 'known_hosts' file on the remote system,
107+
# but this does it for you. Using 'scp':
108+
# cat .ssh/id_ed25519.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys'
109+
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
110+
```
111+
45112
<!-- System Administration: Non-Systemd -->
46113

47114
## System Administration: Non-Systemd

0 commit comments

Comments
 (0)