banner
lca

lca

真正的不自由,是在自己的心中设下牢笼。

Some quick commands in Linux.

Filtering specific lines#

# Filter lines with "vpn" from the text
grep -v "vpn" filename

Ports#

# View the default port names and numbers for all services
getent services

image

Run the previous command with sudo#

sudo !!

image

find#

# Display the file content and output the current file name
find . -type f -print -exec cat {} \;

# Find files with size 0 in the current directory and its subdirectories, and display detailed information about the files.
find . -size 0 -type f -exec ls -lh "{}" \;

# Find all files in the current directory that have been modified in the last day, have a file name ending with .md, but exclude files named "template.md" and "temp.md".
find . -maxdepth 1 -type f -mtime -1 -name "*.md" -not -name "template.md" -not -name "temp.md" -exec ls -lh "{}" \;

# Find files that have been modified in the last two days and have "margin" in their file names in the current directory, and move them to the /tmp/img/ directory.
find . -maxdepth 1 -type f -mtime -2 -name "*margin*" -exec mv "{}" /tmp/img/ \;

# Find files with the extension '.ibd' in the current directory, then filter out files that contain 'tpcc1000', and exclude files that contain 'mysql_global'. Finally, copy the found files to the /tmp/bak/ directory.
find . -name '*.ibd' | grep tpcc1000 | grep -v mysql_global | xargs -I{} cp --path {} /tmp/bak/

xargs#

xargs is usually used to process the output of a command in batches, and pass the output content to the subsequent command for further processing.

# Each line in ip.txt contains an IP address. xargs processes each IP address and passes it to nmap for port scanning. {} is a placeholder for the IP address.
cat ip.txt | xargs -I {} nmap -p80 {}

cat aqc.100.ip.alive.1 | xargs -I {} java -jar shiro_tool.jar {}

ps#

ps -Tfp <PID>

image

Loop through the content of a text file#

while read i ; do echo $i ; done <./prometheus.list

Save a file as root in vim opened as a regular user#

:w !sudo tee %

Switch back to the previous directory#

$cd -

Passwordless SSH login to a remote host#

$ ssh-copy-id remote-machine

Clear or create a file#

> file.txt

Create a port forwarding channel with SSH#

# Create an SSH tunnel on the local host, mapping port 2001 on the local host to port 80 on the remote host. This allows you to access port 80 on the remote host through port 2001 on the local host. Note that "user" is your login username on "some machine".
ssh -f -N -L2001:remotehost:80 user@somemachine

image

Monitor the latest modified files in a directory in real time#

watch -d -n 1 'df; ls -FlAt /path'

Download an entire website using Wget in recursive mode#

nohup wget --random-wait -nc -q -r -l 0 --reject=html -np -e robots=off -U Mozilla www.example.com &

Execute a command without saving it to history#

By adding a space before the command on the command line, you can prevent the command from being saved to the bash history (~/.bash_history) file.
$ command

Display the size of all subdirectories in the current directory#

sudo du -h -max-depth=1 -BG //unit block-size G; or -BM MB

# Sort by size
du -sh * | sort -hr | head

Quickly start an SMTP server with Python#

python -m smtpd -n -c DebuggingServer localhost:1025

Quickly start an HTTP server with Python#

python3 -m http.server 8080

Others#

image

from X @javinpaul

Reference:

https://plantegg.github.io/2017/01/01/top_linux_commands/

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.