In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What are the useful Unix/Linux command skills? in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
1. Delete a large file
I have a large 200GB log file on the production server that needs to be deleted. My rm and ls commands have crashed, and I'm afraid this is due to the huge disk IO. To delete this large file, type:
> / path/to/file.log # or use the following format: > / path/to/file.log # and delete it rm / path/to/file.log
2. How to record the terminal output?
Try using the script command line tool to create an output record for your terminal output.
Script my.terminal.sessio
Enter the command:
Ls date sudo service foo stop
To exit (end the script session), type exit or logout or press control-D.
Exit
To browse and enter:
More my.terminal.session less my.terminal.session cat my.terminal.session
3. Restore the deleted / tmp folder
I made some mistakes in the articles Linux and Unix shell. I accidentally deleted the / tmp folder. To restore it, I need to do this:
Mkdir / tmp chmod 1777 / tmp chown root:root / tmp ls-ld / tmp
4. Lock a folder
I want to lock the / downloads folder under my file server for the sake of my data privacy. So I ran:
Chmod 0000 / downloads
Root users can still access it, while the ls and cd commands do not work. To restore it with:
Chmod 0755 / downloads
5. Protect files with passwords in vim
Are you afraid of root users or others spying on your personal files? To try password protection in vim, enter:
Vim + X filename
Alternatively, use the: X command to encrypt your file before exiting vim, and vim will prompt you for a password.
6. Clear the garbled code on the screen
Just enter:
Reset
7. easy-to-read format
Pass the-h or-H (and other options) option to the GNU or BSD tool to get commands such as ls, df, du, and so on, output in an easy-to-read format:
Ls-lh # in an easy-to-read format (e.g. 1K 234m 2G) df-h df-k # in bytes, KB, MB or GB output: free-b free-k free-m free-g # output in an easy-to-read format (such as 1K 234m 2G) du-h # displays file system permissions stat-c% A / boot # more readable digits sort-h-a file # displays cpu information lscpu lscpu-e lscpu-e=cpu on Linux Node # displays the size of each file tree-h tree-h / boot in readable form
8. Display known user information in Linux system
Just enter:
# # linux version # # lslogins # # BSD version # # logins
Sample output:
UID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 0 0 22:37:59 root 1 bin 0 1 bin 2 daemon 0 1 daemon 3 adm 0 1 adm 4 lp 0 1 lp 5 sync 01 sync 6 shutdown 01 2014-Dec17 shutdown 7 halt 01 halt 8 mail 01 mail 10 uucp 01 uucp 11 operator 01 operator 12 games 01 Games 13 gopher 0 1 gopher 14 ftp 0 1 FTP User 27 mysql 0 1 MySQL Server 38 ntp 0 1 48 apache 0 1 Apache 68 haldaemon 0 1 HAL daemon 69 vcsa 0 1 virtual console memory owner 72 tcpdump 0 1 74 sshd 0 1 Privilege-separated SSH 81 dbus 0 1 System message bus 89 postfix 0 1 99 nobody 0 1 Nobody 173 abrt 0 1 497 vnstat 0 1 VnStat user 498 nginx 0 1 nginx user 499 saslauth 0 1
9. How do I delete files that were unzipped accidentally under the current folder?
I accidentally extracted a tarball under / var/www/html/ instead of / home/projects/www/current. It messes up the files under / var/www/html, and you don't even know which ones are misunderstood. The easiest way to fix this problem is:
Cd / var/www/html/ / bin/rm-f "$(tar ztf / path/to/file.tar.gz)"
10. Confused about the output of the top command?
Seriously, you should try using htop instead of top:
Sudo htop
11. Want to run the same command again
Just input!!. For example:
/ myhome/dir/script/name arg1 arg2 # to run the same command again! # # run the command sudo! as the root user *!
!! Runs the most recently used command. To run the recently run command that starts with "foo":
! foo # run the last command sudo! service that began with "service" as the root user
! $is used to run a command with * one parameter:
# Edit nginx.conf sudo vi / etc/nginx/nginx.conf # Test nginx.conf / sbin/nginx-t-c / etc/nginx/nginx.conf # after testing "/ sbin/nginx-t-c / etc/nginx/nginx.conf" you can edit this file again with vi sudo vi! $
Remind you on the terminal that you have to go
If you need a reminder to leave your terminal, enter the following command:
Leave + hhmm
Here:
Hhmm-time is in the form of hhmm, hh for hours (12-hour or 24-hour) and mm for minutes. All the time is converted to a 12-hour system, and it is assumed to happen in the next 12 hours.
13. Sweet home
Want to enter the place you just entered? Run:
Cd-
Need to get back to your home directory quickly? Enter:
Cd
The variable CDPATH defines the search path to the directory:
Export CDPATH=/var/www:/nas10
Now, instead of typing cd * / var/www/html/, I can enter / var/www/html directly by typing the following command:
Cd html
14. Edit the file while less browsing
To edit a file that you are browsing with less, press v. You can edit it with the editor specified by the variable $EDITOR:
Less * .c less foo.html # # press the v key to edit the file # after you exit the editor, you can continue to browse with less # #
15. List all files and directories in your system
To see all the directories in your system, run:
Find /-type d | less # list all directories of $HOME find $HOME-type d-ls | less
To see all the files, run:
Find /-type f | less # list all the files in $HOME find $HOME-type f-ls | less
You can use mkdir plus the-p option to create one directory tree at a time:
Mkdir-p / jail/ {dev,bin,sbin,etc,usr,lib,lib64} ls-l / jail/
17. Copy files to multiple directories
You do not have to run:
Cp / path/to/file / usr/dir1 cp / path/to/file / var/dir2 cp / path/to/file / nas/dir3
Run the following command to copy files to multiple directories:
Echo / usr/dir1 / var/dir2 / nas/dir3 | xargs-n 1 cp-v / path/to/file
Leave it as an exercise for the reader to create a shell function.
18. Quickly find out the difference between the two directories
The diff command compares files by line. But it can also compare two directories:
Ls-l / tmp/r ls-l / tmp/s # compare two folders diff / tmp/r/ / tmp/s/ using diff
Fig. : Finding differences between folders
Picture: find out the differences between directories
19. Text formatting
You can reformat each paragraph with the fmt command. In this case, I want to split the extra-long line and fill the short line:
Fmt file.txt
You can also split long lines, but not refill them, that is, split long lines, but not fill short lines:
Fmt-s file.txt
You can see the output and write it to a file
Use the tee command to see the output on the screen and write to the log file my.log as follows:
Mycoolapp arg1 arg2 input.file | tee my.log
Tee ensures that you can see the output of mycoolapp on the screen and write to the file my.log at the same time.
This is the answer to the questions about the easy-to-use Unix/Linux command skills. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.