Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the 30 interesting commands and prompts for Linux shell?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

What this article shares to you is about Linux shell 30 interesting commands and tips respectively, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Without saying much, let's take a look at it.

\ 1. Monitoring commands (run every 2 seconds)

Watch "ls-larth" 2. Use a port to kill the program

Sudo fuser-k 8000/tcp\ 3. Limit memory usage for the following commands

Ulimit``-Sv 1000 ``# 1000 KBs = 1 MB``ulimit``-Sv unlimited`` # Remove limit\ 4. Rename the selected file using a regular expression

Rename's /\ .bak $/ .txt /'* .bak\ 5. Get the complete file path

Readlink-f file.txt\ 6. List the contents of the tar.gz file and extract only one file

Tar```file`.tgz`tar``xf ``file`.tgz filename\ 7. List files by file size

Ls-lS\ 8. Trace rout

Mtr google.com\ 9. Tips for finding files

Find. -size 20c # By file size (20 bytes) find. -name "* .gz"-delete # Delete files find. -exec echo {}\; # One file by line. / file1. / file2. / file3 find. -exec echo {}\ + # All in the same line. / file1. / file2. / file3\ 10. Print text in an infinite loop

Yes`yes``hello\ 11. Currently logged in user

W\ 12. Output result leading line number

Ls | nl\ 13. Grep uses Perl-style syntax (characters like\ t are allowed)

Grep-P "\ t"\ 14. Cat command output in reverse (starting at the end)

Tac file\ 15. Check the permissions of the files in each directory

It is useful to detect permission errors, such as when configuring a web server.

Namei-l / path/to/file.txt\ 16. The command is executed every time the file is modified

While``inotifywait-e close_write document. Tex``do```make`done\ 17. Copy to clipboard

Cat file.txt | xclip-selection clipboard\ 18. Spelling and grammar checking of Latex

Detex file.tex | diction-bs you may need to install the following: sudo apt-get install diction texlive-extra-utils.

\ 19. Check the use of resources

/ usr/bin/time-v ls\ 20. Random lines of the file

Cat file.txt | sort-R cat file.txt | sort-R | head # Pick a random sambple # Even better (suggested by xearl in Hacker news): shuf file.txt\ 21. Keep the program running after leaving the SSH session

If the program does not require any interaction:

Nohup. / script.sh & if you need to type something manually, then leave:

. / script.sh # send process to sleep jobs-l # find out the jobid disown-h jobid # disown job bg # continue running in the background of course, you can also use screen or tmux to do this.

\ 22. Run the command in a limited time

Timeout 10s. / script.sh # Restart every 30 minutes while true; do timeout 30m. / script.sh; done\ 23. Merge lines from two sort files

Comm file1 file2 prints these three columns:

1. Yes, it's unique to file1. two。 Yes, it's unique to file2. 3. It is found in both line file1 and row file2.

You can delete these columns using options-1,-2,-3.

\ 24. Split the long file in the file, using the same number of lines

Split-l LINES-d file.txt output_prefix\ 25. Refresh the swap partition

If a program consumes too much memory, the swap partition will be filled with the remaining memory, and when you get back to normal, everything will be slow. Just restart the swap partition to fix it:

Sudo swapoff-a sudo swapon-a\ 26. Fix the superblock problem in the ext4 file system

Pdftk * .pdf cat output all.pdf # Join PDFs together pdftk A=in.pdf cat A5 output out.pdf # Extract page from PDF\ 27. Create an empty file of a given size

Fallocate-l 1G test.img\ 28. Manipulate PDF files from the command line

Pdftk is a better command than commands such as join,shuffle,select:

Pdftk * .pdf cat output all.pdf # Join PDFs together pdftk A=in.pdf cat A5 output out.pdf # Extract page from PDF can also use cpdf to manipulate content:

Cpdf-draft in.pdf-o out.pdf # Remove images cpdf-blacktext in.pdf-o out.pdf # Convert all text to black color\ 29. Monitor progress based on the generated output

# Write random data, encode it in base64 and monitor how fast it # is being sent to / dev/null cat / dev/urandom | base64 | pv-lbri2 > / dev/null # pv options: #-l, lines #-b, total counter #-r, show rate\ 30. Find a file package in Ubuntu

Apt- ``file``update`apt-``file``search ``dir`` / file`.h are the 30 interesting commands and tips of Linux shell. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report