惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
罗磊的独立博客
腾讯CDC
云风的 BLOG
云风的 BLOG
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
U
Unit 42
I
InfoQ
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
美团技术团队
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
GbyAI
GbyAI
S
SegmentFault 最新的问题

Ittavern.com

Wimage - Hosting Open-Source Image Uploader with Podman and external S3 Storage Switching from Hugo to picopaper Encryption using SSH Keys with age in Linux ETag in nginx - Simple Resource Caching Sending nginx Logs to Loki with Grafana Alloy How to: Cisco ISE backup to SFTP repository with public key authentication Dummy IP & MAC Addresses for Documentation & Sanitization Deploying ISSO Commenting System for Static Content using Docker Generate a Vanity v3 Hidden Service Onion Address with mkp224o ssh-audit Primer - Audit your SSH Server mtr - More Detailed Traceroute - Network Troubleshooting My Personal Backup Strategy - August 2024 iperf3 - User Authentication with Password and RSA Public Keypair Adding a trash can to Linux with trash-cli Bandwidth Measurement using netcat on Linux Getting started with rsync - Comprehensive Guide Cron Jobs on Linux - Comprehensive Guide with Examples SSH Server Hardening Guide v2 Port Knocking with knockd and Linux - Server Hardening Getting started with rclone - Data transmission Getting started with dig - DNS troubleshooting Getting started with Fail2Ban on Linux Getting started with netcat on Linux with examples URL explained - The Fundamentals Troubleshooting Asking The Right Questions Create tmux layouts using bash scripts Getting started with tcpdump - Ittavern.com Curl on Linux - Reference Guide Getting started with nmap scripts My Offsite Backup - March 2023
Linux - How to work with complex commands
2022-12-10 · via Ittavern.com

It can frustrate to work on complex commands in the terminal. I'll present you some tips on how to manage them. If you have another tip, I'd appreciate a quick message.

Use backslash\ to add a line break

This is fairly simple. Having one or multiple long lines with no structure can be messy and confusing. By adding \ for a line break adds more structure. A really simple example:

podman run -d --restart=always -p 127.0.0.1:3001:3001 -v /path/data:/app/data --name status.brrl.net docker.io/louislam/uptime-kuma:latest

With line breaks:

podman run -d \
  --restart=always \
  -p 127.0.0.1:3001:3001 \
  -v /path/data:/app/data \
  --name status.brrl.net \
  docker.io/louislam/uptime-kuma:latest

It is easier to read and work with, at least in my opinion.

Work on complex commands in your favorite $EDITOR #

I'lll show you now, how you can edit complex commands in your favorite CLI editor.

Enter command fc, or keep CTRL pressed and enter x and e as keyboard shortcut. This will open your default CLI editor. After finishing working on the command you want to run, simply 'save and close', and the command will run right after. I am going to show you how yo set your default editor at the end of the post.

The fc command is normally used to show the command history or re-edit already entered commands, but we can use it to work on complex commands. fc --help to find out more.

Set default editor in the CLI #

There are various ways to set the default editors, so you might have to look it up for your setup.

In general, it works to set the $EDITOR environment variable with the editor of choice. On most distros it should be 'nano', but you might prefer something else.

If we want to change our default editor to 'vim' temporarily, we can enter this command:

export EDITOR="/bin/vim"

You can double-check with:

echo $EDITOR or env | grep EDITOR

and

$EDITOR test.txt

Important: To change the default editor permanently, add export EDITOR="/bin/vim" to your .bashrc or whatever config file you use.

From now on, whenever you want to edit a command with fc, your favorite editor will open.