df
you get "command not found". What could be wrong and how to fix it?
Most likely the default/generated $PATH was somehow modified or overridden thus not containing /bin/
where df would normally go.
This issue could also happen if bash_profile or any configuration file of your interpreter was wrongly modified, causing erratics behaviours.
You would solve this by fixing your $PATH variable:
As to fix it there are several options:
1. Manually adding what you need to your $PATH PATH="$PATH":/user/bin:/..etc
2. You have your weird env variables backed up.
3. You would look for your distro default $PATH variable, copy paste using method #1
Note: There are many ways of getting errors like this: if bash_profile or any configuration file of your interpreter was wrongly modified; causing erratics behaviours,
permissions issues, bad compiled software (if you compiled it by yourself)... there is no answer that will be true 100% of the time.
cron
and at
.
With cron, tasks are scheduled using the following format:
*/30 * * * * bash myscript.sh
Executes the script every 30 minutes.
crontab -e
Alternatively if you are using a distro with systemd it's recommended to use systemd timers.
ls > filelist.txt
* Redirecting Standard Error (stderr):
ls /some/nonexistent/directory 2> error.txt
* Appending to a file:
echo "hello" >> myfile.txt
* Redirecting Input (stdin):
sort < unsorted.txt
* Using Pipes: Pipes ("|"):
ls | grep "\.txt$"
ls > ls_output.txt
yippiekaiyay 2> ls_output.txt
yippiekaiyay &> file
yippiekaiyay 1>&2 die_hard
/
?777 - You give the owner, group and other: Execute (1), Write (2) and Read (4); 4+2+1 = 7. 644 - Owner has Read (4), Write (2), 4+2 = 6; Group and Other have Read (4). 750 - Owner has x+r+w, Group has Read (4) and Execute (1); 4+1 = 5. Other have no permissions.
chmod +x some_file
chmod -x $(which chmod)
. How to fix it?journalctl
dstat -t
is great for identifying network and disk issues.
netstat -tnlaup
can be used to see which processes are running on which ports.
lsof -i -P
can be used for the same purpose as netstat.
ngrep -d any metafilter
for matching regex against payloads of packets.
tcpdump
for capturing packets
wireshark
same concept as tcpdump but with GUI (optional).
dstat -t
is great for identifying network and disk issues.
opensnoop
can be used to see which files are being opened on the system (in real time).
strace
is great for understanding what your program does. It prints every system call your program executed.
top
will show you how much CPU percentage each process consumes
perf
is a great choice for sampling profiler and in general, figuring out what your CPU cycles are "wasted" on
flamegraphs
is great for CPU consumption visualization (http://www.brendangregg.com/flamegraphs.html)
sysctl -a
as a regular user vs. root, produce different result?sysctl
applies the changes to kernel's runtime parameters the moment you run sysctl command?~/.ssh/known_hosts
?ssh-keygen
is used for?ssh-keygen
is a tool to generate an authentication key pair for SSH, that consists of a private and a public key. It supports a number of algorithms to generate authentication keys :
- dsa
- ecdsa
- ecdsa-sk
- ed25519
- ed25519-sk
- rsa (default)
One can also specify number of bits in key. Command below generates an SSH key pair with RSA 4096-bits :
```
$ ssh-keygen -t rsa -b 4096
```
The output looks like this:
```
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa
Your public key has been saved in /home/user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:f5MOGnhzYfC0ZCHvbSXXiRiNVYETjxpHcXD5xSojx+M user@mac-book-pro
The key's randomart image is:
+---[RSA 4096]----+
| . ..+***o|
| o o++*o+|
| . =+.++++|
| B.oX+. .|
| S *=o+ |
| . o oE. |
| . + + + |
| . = + . |
| . . |
+----[SHA256]-----+
```
One can check how many bits an SSH key has with :
```
$ ssh-keygen -l -f /home/user/.ssh/id_rsa
```
Output should look like this :
```
4096 SHA256:f5MOGnhzYfC0ZCHvbSXXiRiNVYETjxpHcXD5xSojx+M user@mac-book-pro (RSA)
```
It shows the key is RSA 4096-bits.
`-l` and `-f` parameters usage explanation :
```
-l Show the fingerprint of the key file.
-f filename Filename of the key file.
```
Learn more : [How can I tell how many bits my ssh key is? - Superuser](https://superuser.com/a/139311)
ls [XYZ]
matchls [^XYZ]
matchls [0-5]
matchgrep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' some_file
* grep -E "error|failure" some_file
* grep '[0-9]$' some_file
mount
command but you get no output. How would you check what mounts you have on your system?top
and free
mem()
{
ps -eo rss,pid,euser,args:100 --sort %mem | grep -v grep | grep -i $@ | awk '{printf $1/1024 "MB"; $1=""; print }'
}
[Source](https://stackoverflow.com/questions/3853655/in-linux-how-to-tell-how-much-memory-processes-are-using)
The default signal is SIGTERM (15). This signal kills process gracefully which means it allows it to save current state configuration.
kill 0
does?kill -0
does?Running (R) Uninterruptible Sleep (D) - The process is waiting for I/O Interruptible Sleep (S) Stopped (T) Dead (x) Zombie (z)
strace
does? What about ltrace
?split
command this way: split -l 25 some_file
/etc/resolv.conf
is used for? What does it include?dig
* host
* nslookup
dig codingshell.com
and get the following result:
```
ANSWER SECTION:
codingshell.com. 3515 IN A 185.199.109.153
```
What is the meaning of the number 3515?
systemctl enable [service_name]
System V: update-rc.d [service_name]
and add this line id:5678:respawn:/bin/sh /path/to/app
to /etc/inittab
Upstart: add Upstart init script at /etc/init/service.conf
ssh 127.0.0.1
but it fails with "connection refused". What could be the problem?grep $(whoami) /etc/passwd
but the output is empty. What might be a possible reason for that?awk
command does? Have you used it? What for?lsof
command does? Have you used it? What for?ls -l
?ls -l *.log
?alias x=y
does?/my/file
and 5 is the file descriptor number.
ip a
you see there is a device called 'lo'. What is it and why do we need it?traceroute
command does? How does it works?201.7.19.90 - - [05/Jun/1985:13:42:99 +0000] "GET /site HTTP/1.1" 200 32421