"@" 符号在 Linux 里没有单一固定含义,具体作用取决于上下文。
1. 用户名与主机名分隔符
最常见的用法,格式为 `用户名@主机名`:
```bash
ssh root@192.168.1.100
scp file.txt user@remote-server:/home/user/
```
2. systemd 模板单元(Template Units)
systemd 用 `@` 表示"模板服务",允许用同一份配置启动多个实例。
```bash
systemctl start getty@tty1.service
systemctl start openvpn@client1.service
```
3. 符号链接的显示标记(`ls -l`)
```bash
$ ls -l
lrwxrwxrwx 1 root root 7 Aug 8 10:00 mylink -> target.txt
```
```bash
ls -F
mylink@
```
4. 命令行中表示"从文件读取参数"
一些工具(如 `curl`)用 `@` 前缀表示"这是一个文件路径,请读取其内容",而不是把内容当作字面字符串:
```bash
# 上传文件内容作为 POST body
curl -X POST -d @data.json https://api.example.com/upload
5. Crontab 中的特殊时间字符串
`@` 开头的关键字是常见调度周期的简写:
```bash
@reboot /path/to/script.sh # 系统启动时执行一次
@daily /path/to/backup.sh # 相当于 0 0 * * *
@weekly /path/to/cleanup.sh
@hourly /path/to/check.sh
```
比手写 cron 表达式更直观,适合写运维脚本时用。
6. Shell 参数展开中的特殊变量
在 Bash 脚本里,`$@` 表示"所有位置参数",是编写脚本时的高频用法:
```bash
#!/bin/bash
echo "参数个数: $#"
for arg in "$@"; do
echo "参数: $arg"
done
```