Common shell commands under Linux

Source: Internet
Author: User
Tags base64 gz file

English original link: https://www.lopezferrando.com/30-interesting-shell-commands/1. Monitoring commands (run every 2 seconds)
"ls -larth"
2. Kill the program with one port
sudo fuser -k 8000/tcp
3. Limit the memory usage of the following commands
ulimit -Sv 1000       # 1000 KBs = 1 MBulimit -Sv unlimited  # Remove limit
4. Rename the selected file using regular expressions
‘s/\.bak$/.txt/‘ *.bak
5. Get the full file path
readlink -f file.txt
6. List the contents of the tar.gz file and extract only one file
tar tf file.tgztar xf file.tgz filename
7. list files by file size
ls -lS
8. Track routes
mtr google.com
9. Tips for finding files
find . -size 20c             # By file size (20 bytes)find . -name "*.gz" -delete  # Delete filesfind . -exec echo {} \; # One file by line./file1./file2./file3find . -exec echo {} \+ # All in the same line./file1 ./file2 ./file3
10. Print infinite loops of text
yesyes hello
11. Currently logged in user
w
12. Output result Front line number
ls | nl
grep uses Perl-style syntax (allows \tSuch a character)
"\t"
Cat command Reverse output (starting at the end)
tac file
15. Check the permissions of the files in each directory

It is useful to detect permissions errors, such as when you configure a Web server.

namei -l /path/to/file.txt
16. command is executed every time the file is modified
while inotifywait -e close_write document.texdo    makedone
17. Copy to Clipboard
cat file.txt | xclip -selection clipboard
Spelling and grammar check of latex
detex file.tex | diction -bs

You may need to install the following: sudo apt-get install diction texlive-extra-utils .

19. Checking the use of resources
/usr/bin/time -v ls
20. Random lines of files
cat file.txt | sort -Rcat 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 you leave the SSH session

If the program does not require any interaction:

nohup ./script.sh &

If you need to enter some content manually, then leave:

./script.sh<Type any input you want><Ctrl-Z>          # send process to sleepjobs -l           # find out the job iddisown -h jobid   # disown jobbg # continue running in the background

Of course, you can also use screen or tmux to accomplish this purpose.

22. Run the command for a limited period of time
timeout 10s ./script.sh# Restart every 30 minuteswhile true; do timeout 30m ./script.sh; done
23. Merging rows from two sorted files
comm file1 file2

Print these three columns:

    1. Line file1 Exclusive.
    2. Line file2 Exclusive.
    3. file1both in line and row file2 .

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

24. Split long files in a file, using the same number of rows
split -l LINES -d file.txt output_prefix
25. Refresh the Swap partition

If a program consumes too much memory, the swap partition is filled with the remaining memory, and when you return to normal, everything is slow. Simply restart the swap partition to fix it:

sudo swapoff -asudo swapon -a
26. Fix superblock Problem of EXT4 file system
of previous list> /dev/sda1
27. Create an empty file of a given size
fallocate -l 1G test.img
28. Manipulate PDF files from the command line

join shuffle select pdftk It's a better command than, like, a command:

pdftk *.pdf cat output all.pdf        # Join PDFs togetherpdftk A=in.pdf cat A5 output out.pdf  # Extract page from PDF

You can also use the cpdf action content:

in.pdf -o out.pdf      # Remove imagescpdf -blacktext in.pdf -o out.pdf # Convert all text to black color
29. Monitor progress against the generated output
# Write random data, encode it in base64 and monitor how fast it# is being sent to /dev/nullcat /dev/urandom | base64 | pv -lbri2 > /dev/null# pv options:# -l, lines# -b, total counter# -r, show rate# -i2, refresh every 2 seconds
30. Find a package of files in Ubuntu
apt-file updateapt-file search dir/file.h



Common shell commands under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.