Open IOriens opened 6 years ago
argc == argument count argv == argument vector
#include <stdio.h>
int main (int argc, char *argv[])
{
return 0;
}
gcc -o myprog myprog.c
argc
4
argv[0]
gcc
argv[1]
-o
argv[2]
myprog
argv[3]
myprog.c
On POSIX systems the standard convention is for the program to pass 0 for successful executions and 1 or higher for failed executions.
#!/bin/bash
touch /root/test 2> /dev/null
if [ $? -eq 0 ]
then
echo "Successfully created file"
exit 0
else
echo "Could not create file" >&2
exit 1
fi
Here’s stuff one can do with hard links that would break a soft link:
Stuff that soft links do that hard links can’t:
Symbolic links and hard links: creating, updating, deleting and all that
>
Save output to a file.
>>
Append output to a file.
<
Read input from a file.
2>
Redirect error messages.
|
Send the output from one program as input to another program.
The >
operator redirects the output usually to a file but it can be to a device. You can also use>>
to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file
1> file
redirects stdout to file
2> file
redirects stderr to file
&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
假设我们想要让一个名为 app 的应用开机启动
首先在 /etc/systemd/system/
目录下创建一个 app.service
文件,下面以 frp 的启动配置为例:
[Unit]
Description=frps daemon
After=syslog.target network.target
Wants=network.target
[Service]
Type=simple
ExecStart=/home/ioriens/bin/frp/frps -c /home/ioriens/bin/frp/frps.ini
Restart= always
RestartSec=1min
ExecStop=/usr/bin/killall frps
[Install]
WantedBy=multi-user.target
开机启动
systemctl enable app
取消开机启动
systemctl disable app
查看运行状态
systemctl status app
Network
Find port in use
Show all port in use
Find a specific port
DNS
Get ip address of one domain
Flush Dns Cache
Flushing your DNS cache in Mac OS X and Linux
Process
kill process
Recommend trying kill -15 before resorting to -9 for safety:
kill all vscode instances
kill port
File System
mkdir
-p
: make parents as neededln => make link
By default, ln makes hard links.
To make symbolic link, use
ln -s
ls
output: https://unix.stackexchange.com/questions/103114/what-do-the-fields-in-ls-al-output-mean/103117 https://en.wikipedia.org/wiki/Unix_file_types
chomod
diff
file
folder
Copy to or paste from clipboard
How can I copy the output of a command directly into my clipboard?
Ref
Understanding Exit Codes and how to use them in bash scripts
Others
Bad interpreter
Error:
Solution: In vim you could also use
:set ff=unix
and then save the file, or:set ff=dos
to get DOS formatting again.Sub Bash
beautify all the code in current dir
run process as background and never die
How to run process as background and never die?
Remove all node_module folders recursively
Remove all node_module folders recursively