banner
lca

lca

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

Some quick commands under 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 as sudo#

sudo !!

image

find#


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

# Find files with a size of 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 in .md, but do not include 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 '.ibd' extension 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 that represents 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 text content#

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

Save a root user file 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#

# Establish 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

View 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, you can prevent it from being saved in 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 unit size
du -sh * | sort -hr | head

Quickly start an SMTP service 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.