mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-10 00:00:29 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
1481914876
@ -0,0 +1,91 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Passive optical networking: Its day is dawning)
|
||||
[#]: via: (https://www.networkworld.com/article/3489477/passive-optical-networking-its-day-is-dawning.html)
|
||||
[#]: author: (Zeus Kerravala https://www.networkworld.com/author/Zeus-Kerravala/)
|
||||
|
||||
Passive optical networking: Its day is dawning
|
||||
======
|
||||
|
||||
Getty Images
|
||||
|
||||
The concept of using passive optical LANs in enterprise campuses has been around for years, but hasn’t taken off because most businesses consider all-fiber networks to be overkill for their needs. I’ve followed this market for the better part of two decades, and now I believe we’re on the cusp of seeing POL go mainstream, starting in certain verticals.
|
||||
|
||||
The primary driver of change from copper to optical is that the demands on the network have evolved. Every company now considers its network to be business critical where just a few years ago, it was considered best effort in nature. Downtime or a congested network meant inconvenienced users, but today they mean the business is likely losing big money.
|
||||
|
||||
[[Get regularly scheduled insights by signing up for Network World newsletters.]][1]
|
||||
|
||||
There are also a number of new trends driving the evolution of the campus network. These include:
|
||||
|
||||
[][2]
|
||||
|
||||
BrandPost Sponsored by HPE
|
||||
|
||||
[Take the Intelligent Route with Consumption-Based Storage][2]
|
||||
|
||||
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
|
||||
|
||||
* Cloud services. The cloud is certainly the way of the future but it’s playing havoc with enterprise networks. As data centers evolved to modernized systems, East-West traffic was superseded by North-South. Today, businesses are connecting direct to cloud for [hybrid-cloud][3] deployments driving more North-South traffic. Traditional networks can be a bottleneck.
|
||||
* [Internet of Things][4] (IoT). [Wi-Fi 6 and 5G][5] will enable more devices to be connected in more places leading to more bandwidth on the network. For the first time in history, wireless speeds will match wired speeds straining the campus network.
|
||||
* Video of all kinds is on the rise. Surveillance, collaboration, room systems, streaming and other kinds of video usage are on the rise. Video requires high-quality, low-latency connectivity.
|
||||
|
||||
|
||||
|
||||
### Copper is running out of life
|
||||
|
||||
The increased speeds pose quite a predicament for companies. If the organization has Cat5 cabling, the speed is capped at 1Gbps. If Cat6 is deployed, speeds of 10Gbps can be reached but only 55 meter’s distance. If the company wants to reach the full 100M length of copper, Cat6A or higher must be used. Optical cable has no distance limitations because POL is completely passive and requires no electronics to boost the signal. Optical cabling can carry petabytes of bandwidth over long distances. Also, with optical, there’s no concern over what type of cable is being used and having the quality degrade over time. Lastly, upgrading speeds is easier. The cabling can stay in place and just the optics get changed out at the ends of the cable making the process simple.
|
||||
|
||||
### POL is a cheaper, longer lasting than copper upgrades
|
||||
|
||||
If businesses are faced with having to upgrade their networks from Cat5 to another type of cabling, it might make sense to look at POL as it can be the foundation for the campus network for years.
|
||||
|
||||
The early adopters of POL are companies that are highly distributed with large campuses and need to get more network services in more places. This includes manufacturing organizations, universities, hospitality, cities and airports. Although I’ve highlighted a few verticals, the fact is that any business can take advantage of POL.
|
||||
|
||||
### POL in a mixed-use development
|
||||
|
||||
At a Huawei conference earlier this year the company showcased the Dubai Creek Harbor project being built by Emaar Properties – a six-square-mile development including residences, offices, retail and cultural facilities. The complex is designed to be fully digital and the network has to support IoT, cloud computing, AI-based analytics and more.
|
||||
|
||||
The project features an optical network built on Huawei’s Campus OptiX solution that simplifies the network as the architecture moves from a three-tier hierarchical design to a two-tier one. That design uses less equipment and reduces power and cooling requirements. Also, the flat, 10Gbps network obviates the need for parallel overlay networks, making it easier to manage and giving it a degree of future-proofing as the network can easily be upgraded. The all-optical network resulted in a 60% improvement in operational efficiency and a deployment time that was cut in half compared a similar network using Ethernet.
|
||||
|
||||
### Cost effective **
|
||||
|
||||
**
|
||||
|
||||
Although there are many benefits to POL, adoption has been light. The biggest impediment to its adoption is a general lack of awareness and a misunderstanding of cost. The actual cost of fiber cabling is higher than copper, but I’ve talked to many companies that have looked at fully loaded costs and often optical is cheaper. Optical isn’t subject to electromagnetic interference like copper is so there’s no need to lay a pipeline down first. Also, copper cabling requires distribution cabinets to boost the signal and that adds the cost of UPSes, cooling and power that fiber does not.
|
||||
|
||||
North American buyers may not have the same awareness of POL as those in China, where:
|
||||
|
||||
* The engineering standard of POL was released in June, outlining the system, design, cabling, testing and acceptance rules.
|
||||
* An alliance was established Oct. 22 bringing together a number of companies including Nokia, Huawei, and Yangtze Optical Fiber and Cable.
|
||||
|
||||
|
||||
|
||||
Both of these will help drive innovation and standardization.
|
||||
|
||||
Copper has been the preferred campus backbone, but businesses are changing and so is the network. It’s not enough to just change the infrastructure but the cabling that connects everything should be looked at and POL used as a next-generation backbone.
|
||||
|
||||
Join the Network World communities on [Facebook][6] and [LinkedIn][7] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3489477/passive-optical-networking-its-day-is-dawning.html
|
||||
|
||||
作者:[Zeus Kerravala][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Zeus-Kerravala/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/newsletters/signup.html
|
||||
[2]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||
[3]: https://www.networkworld.com/article/3268448/what-is-hybrid-cloud-really-and-whats-the-best-strategy.html
|
||||
[4]: https://www.networkworld.com/article/3207535/what-is-iot-how-the-internet-of-things-works.html
|
||||
[5]: https://www.networkworld.com/article/3402316/when-to-use-5g-when-to-use-wi-fi-6.html
|
||||
[6]: https://www.facebook.com/NetworkWorld/
|
||||
[7]: https://www.linkedin.com/company/network-world
|
@ -1,292 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (24 sysadmin job interview questions you should know)
|
||||
[#]: via: (https://opensource.com/article/19/7/sysadmin-job-interview-questions)
|
||||
[#]: author: (DirectedSoul https://opensource.com/users/directedsoul)
|
||||
|
||||
24 sysadmin job interview questions you should know
|
||||
======
|
||||
Have a sysadmin job interview coming up? Read this article for some
|
||||
questions you might encounter and possible answers.
|
||||
![Question and answer.][1]
|
||||
|
||||
As a geek who always played with computers, a career after my masters in IT was a natural choice. So, I decided the sysadmin path was the right one. In the process of my career, I have grown quite familiar with the job interview process. Here is a look at what to expect, the general career path, and a set of common questions and my answers to them.
|
||||
|
||||
### Typical sysadmin tasks and duties
|
||||
|
||||
Organizations need someone who understands the basics of how a system works so that they can keep their data safe, and keep their services running smoothly. You might ask: "Wait, isn’t there more that a sysadmin can do?"
|
||||
|
||||
You are right. Now, in general, let’s look at what might be a typical sysadmin’s day-to-day tasks. Depending on their company’s needs and the person’s skill level, a sysadmin’s tasks vary from managing desktops, laptops, networks, and servers, to designing the organization’s IT policies. Sometimes sysadmins are even in charge of purchasing and placing orders for new IT equipment.
|
||||
|
||||
Those seeking system administration as their career paths might find it difficult to keep their skills and knowledge up to date, as rapid changes in the IT field are inevitable. The next natural question that arises out of anyone’s mind is how IT professionals keep up with the latest updates and skills.
|
||||
|
||||
### Low difficulty questions
|
||||
|
||||
Here are some of the more basic questions you will encounter, and my answers:
|
||||
|
||||
1. What are the first five commands you type on a *nix server after login?
|
||||
|
||||
|
||||
|
||||
> * **lsblk** to see information on all block devices
|
||||
> * **who** to see who is logged into the server
|
||||
> * **top** to get a sense of what is running on the server
|
||||
> * **df -khT** to view the amount of disk space available on the server
|
||||
> * **netstat** to see what TCP network connections are active
|
||||
>
|
||||
|
||||
|
||||
2. How do you make a process run in the background, and what are the advantages of doing so?
|
||||
|
||||
|
||||
|
||||
> You can make a process run in the background by adding the special character **&** at the end of the command. Generally, applications that take too long to execute, and don’t require user interaction are sent to the background so that we can continue our work in the terminal. ([Citation][2])
|
||||
|
||||
3. Is running these commands as root a good or bad idea?
|
||||
|
||||
|
||||
|
||||
> Running (everything) as root is bad due to two major issues. The first is _risk_. Nothing prevents you from making a careless mistake when you are logged in as **root**. If you try to change the system in a potentially harmful way, you need to use **sudo**, which introduces a pause (while you’re entering the password) to ensure that you aren’t about to make a mistake.
|
||||
>
|
||||
> The second reason is _security_. Systems are harder to hack if you don’t know the admin user’s login information. Having access to root means you already have one half of the working set of admin credentials.
|
||||
|
||||
4. What is the difference between **rm** and **rm -rf**?
|
||||
|
||||
|
||||
|
||||
> The **rm** command by itself only deletes the named files (and not directories). With **-rf** you add two additional features: The **-r**, **-R**, or --**recursive** flag recursively deletes the directory’s contents, including hidden files and subdirectories, and the **-f**, or --**force**, flag makes **rm** ignore nonexistent files, and never prompt for confirmation.
|
||||
|
||||
5. **Compress.tgz** has a file size of approximately 15GB. How can you list its contents, and how do you list them only for a specific file?
|
||||
|
||||
|
||||
|
||||
> To list the file’s contents:
|
||||
>
|
||||
> **tar tf archive.tgz**
|
||||
>
|
||||
> To extract a specific file:
|
||||
>
|
||||
> **tar xf archive.tgz filename**
|
||||
|
||||
### Medium difficulty questions
|
||||
|
||||
Here are some harder questions you might encounter, and my answers:
|
||||
|
||||
6. What is RAID? What is RAID 0, RAID 1, RAID 5, RAID 6, and RAID 10?
|
||||
|
||||
|
||||
|
||||
> A RAID (Redundant Array of Inexpensive Disks) is a technology used to increase the performance and/or reliability of data storage. The RAID levels are:
|
||||
>
|
||||
> * RAID 0: Also known as disk striping, which is a technique that breaks up a file, and spreads the data across all of the disk drives in a RAID group. There are no safeguards against failure. ([Citation][3])
|
||||
> * RAID 1: A popular disk subsystem that increases safety by writing the same data on two drives. Called _mirroring_, RAID1 does not increase write performance, but read performance may increase up to the sum of each disks’ performance. Also, if one drive fails, the second drive is used, and the failed drive is manually replaced. After replacement, the RAID controller duplicates the contents of the working drive onto the new one.
|
||||
> * RAID 5: A disk subsystem that increases safety by computing parity data and increasing speed. RAID 5 does this by interleaving data across three or more drives (striping). Upon failure of a single drive, subsequent reads can be calculated from the distributed parity such that no data is lost.
|
||||
> * RAID 6: Which extends RAID 5 by adding another parity block. This level requires a minimum of four disks, and can continue to execute read/write with any two concurrent disk failures. RAID 6 does not have a performance penalty for reading operations, but it does have a performance penalty on write operations because of the overhead associated with parity calculations.
|
||||
> * RAID 10: Also known as RAID 1+0, RAID 10 combines disk mirroring and disk striping to protect data. It requires a minimum of four disks, and stripes data across mirrored pairs. As long as one disk in each mirrored pair is functional, data can be retrieved. If two disks in the same mirrored pair fail, all data will be lost because there is no parity in the striped sets. ([Citation][4])
|
||||
>
|
||||
|
||||
|
||||
7. Which port is used for the **ping** command?
|
||||
|
||||
|
||||
|
||||
> The **ping** command uses ICMP. Specifically, it uses ICMP echo requests and ICMP echo reply packets.
|
||||
>
|
||||
> ICMP does not use either UDP or TCP communication services: Instead, it uses raw IP communication services. This means that the ICMP message is carried directly in an IP datagram data field.
|
||||
|
||||
8. What is the difference between a router and a gateway? What is the default gateway?
|
||||
|
||||
|
||||
|
||||
> _Router_ describes the general technical function (layer 3 forwarding), or a hardware device intended for that purpose, while _gateway_ describes the function for the local segment (providing connectivity to elsewhere). You could also state that you "set up a router as a gateway." Another term is _hop_, which describes forwarding between subnets.
|
||||
>
|
||||
> The term _default gateway_ is used to mean the router on your LAN, which has the responsibility of being the first point of contact for traffic to computers outside the LAN.
|
||||
|
||||
9. Explain the boot process for Linux.
|
||||
|
||||
|
||||
|
||||
> BIOS -> Master Boot Record (MBR) -> GRUB -> the kernel -> init -> runlevel
|
||||
|
||||
10. How do you check the error messages while the server is booting up?
|
||||
|
||||
|
||||
|
||||
> Kernel messages are always stored in the kmsg buffer, visible via the **dmesg** command.
|
||||
>
|
||||
> Boot issues and errors call for a system administrator to look into certain important files, in conjunction with particular commands, which are each handled differently by different versions of Linux:
|
||||
>
|
||||
> * **/var/log/boot.log** is the system boot log, which contains all that unfolded during the system boot.
|
||||
> * **/var/log/messages** stores global system messages, including the messages logged during system boot.
|
||||
> * **/var/log/dmesg** contains kernel ring buffer information.
|
||||
>
|
||||
|
||||
|
||||
11. What is the difference between a symbolic link and a hard link?
|
||||
|
||||
|
||||
|
||||
> A _symbolic_ or _soft link_ is an actual link to the original file, whereas a _hard link_ is a mirror copy of the original file. If you delete the original file, the soft link has no value, because it then points to a non-existent file. In the case of a hard link, it is entirely the opposite. If you delete the original file, the hard link still contains the data from the original file. ([Citation][5])
|
||||
|
||||
12. How do you change kernel parameters? What kernel options might you need to tune?
|
||||
|
||||
|
||||
|
||||
> To set the kernel parameters in Unix-like systems, first edit the file **/etc/sysctl.conf**. After making the changes, save the file and run the **sysctl -p** command. This command makes the changes permanent without rebooting the machine
|
||||
|
||||
13. Explain the **/proc** filesystem.
|
||||
|
||||
|
||||
|
||||
> The **/proc** filesystem is virtual, and provides detailed information about the kernel, hardware, and running processes. Since **/proc** contains virtual files, it is called the _virtual file system_. These virtual files have unique qualities. Most of them are listed as zero bytes in size.
|
||||
>
|
||||
> Virtual files such as **/proc/interrupts**, **/proc/meminfo**, **/proc/mounts** and **/proc/partitions** provide an up-to-the-moment glimpse of the system’s hardware. Others, such as **/proc/filesystems** and the **/proc/sys** directory provide system configuration information and interfaces.
|
||||
|
||||
14. How do you run a script as another user without their password?
|
||||
|
||||
|
||||
|
||||
> For example, if you were editing the sudoers file (such as **/private/etc/sudoers**), you might use **visudo** to add the following:
|
||||
>
|
||||
> [**user1 ALL=(user2) NOPASSWD: /opt/scripts/bin/generate.sh**][2]
|
||||
|
||||
15. What is the UID 0 toor account? Have you been compromised?
|
||||
|
||||
|
||||
|
||||
> The toor user is an alternative superuser account, where toor is root spelled backward. It is intended to be used with a non-standard shell, so the default shell for root does not need to change.
|
||||
>
|
||||
> This purpose is important. Shells which are not part of the base distribution, but are instead installed from ports or packages, are installed in **/usr/local/bin**; which, by default, resides on a different file system. If root’s shell is located in **/usr/local/bin** and the file system containing **/usr/local/bin** is not mounted, root could not log in to fix a problem, and the sysadmin would have to reboot into single-user mode to enter the shell’s path.
|
||||
|
||||
### Advanced questions
|
||||
|
||||
Here are the even more difficult questions you may encounter:
|
||||
|
||||
16. How does **tracert** work and what protocol does it use?
|
||||
|
||||
|
||||
|
||||
> The command **tracert**—or **traceroute** depending on the operating system—allows you to see exactly what routers you touch as you move through the chain of connections to your final destination. If you end up with a problem where you can’t connect to or **ping** your final destination, a **tracert** can help in that you can tell exactly where the chain of connections stops. ([Citation][6])
|
||||
>
|
||||
> With this information, you can contact the correct people; whether it be your own firewall, your ISP, your destination’s ISP, or somewhere in the middle. The **tracert** command—like **ping**—uses the ICMP protocol, but also can use the first step of the TCP three-way handshake to send SYN requests for a response.
|
||||
|
||||
17. What is the main advantage of using **chroot**? When and why do we use it? What is the purpose of the **mount /dev**, **mount /proc**, and **mount /sys** commands in a **chroot** environment?
|
||||
|
||||
|
||||
|
||||
> An advantage of having a **chroot** environment is that the filesystem is isolated from the physical host, since **chroot** has a separate filesystem inside your filesystem. The difference is that **chroot** uses a newly created root (**/**) as its root directory.
|
||||
>
|
||||
> A **chroot** jail lets you isolate a process and its children from the rest of the system. It should only be used for processes that don’t run as **root**, as **root** users can break out of the jail easily.
|
||||
>
|
||||
> The idea is that you create a directory tree where you copy or link in all of the system files needed for the process to run. You then use the **chroot()** system call to tell it the root directory now exists at the base of this new tree, and then start the process running in that **chroot**’d environment. Since the command then can’t reference paths outside the modified root directory, it can’t perform operations (read, write, etc.) maliciously on those locations. ([Citation][7])
|
||||
|
||||
18. How do you protect your system from getting hacked?
|
||||
|
||||
|
||||
|
||||
> By following the principle of least privileges and these practices:
|
||||
>
|
||||
> * Encrypt with public keys, which provides excellent security.
|
||||
> * Enforce password complexity.
|
||||
> * Understand why you are making exceptions to the rules above.
|
||||
> * Review your exceptions regularly.
|
||||
> * Hold someone to account for failure. (It keeps you on your toes.) ([Citation][8])
|
||||
>
|
||||
|
||||
|
||||
19. What is LVM, and what are the advantages of using it?
|
||||
|
||||
|
||||
|
||||
> LVM, or Logical Volume Management, uses a storage device management technology that gives users the power to pool and abstract the physical layout of component storage devices for easier and flexible administration. Using the device mapper Linux kernel framework, the current iteration (LVM2) can be used to gather existing storage devices into groups and allocate logical units from the combined space as needed.
|
||||
|
||||
20. What are sticky ports?
|
||||
|
||||
|
||||
|
||||
> Sticky ports are one of the network administrator’s best friends and worst headaches. They allow you to set up your network so that each port on a switch only permits one (or a number that you specify) computer to connect on that port, by locking it to a particular MAC address.
|
||||
|
||||
21. Explain port forwarding?
|
||||
|
||||
|
||||
|
||||
> When trying to communicate with systems on the inside of a secured network, it can be very difficult to do so from the outside—and with good reason. Therefore, the use of a port forwarding table within the router itself, or other connection management device, can allow specific traffic to automatically forward to a particular destination. For example, if you had a web server running on your network and you wanted to grant access to it from the outside, you would set up port forwarding to port 80 on the server in question. This would mean that anyone entering your IP address in a web browser would connect to the server’s website immediately.
|
||||
>
|
||||
> Please note, it is usually not recommended to allow access to a server from the outside directly into your network.
|
||||
|
||||
22. What is a false positive and false negative in the case of IDS?
|
||||
|
||||
|
||||
|
||||
> When the Intrusion Detection System (IDS) device generates an alert for an intrusion which has actually not happened, this is false positive. If the device has not generated any alert and the intrusion has actually happened, this is the case of a false negative.
|
||||
|
||||
23. Explain **:(){ :|:& };:** and how to stop this code if you are already logged into the system?
|
||||
|
||||
|
||||
|
||||
> This is a fork bomb. It breaks down as follows:
|
||||
>
|
||||
> * **:()** defines the function, with **:** as the function name, and the empty parenthesis shows that it will not accept any arguments.
|
||||
> * **{ }** shows the beginning and end of the function definition.
|
||||
> * **:|:** loads a copy of the function **:** into memory, and pipes its output to another copy of the **:** function, which also has to be loaded into memory.
|
||||
> * **&** makes the previous item a background process, so that the child processes will not get killed even though the parent gets auto-killed.
|
||||
> * **:** at the end executes the function again, and hence the chain reaction begins.
|
||||
>
|
||||
|
||||
>
|
||||
> The best way to protect a multi-user system is to use Privileged Access Management (PAM) to limit the number of processes a user can use.
|
||||
>
|
||||
> The biggest problem with a fork bomb is the fact it takes up so many processes. So, we have two ways of attempting to fix this if you are already logged into the system. One option is to execute a SIGSTOP command to stop the process, such as:
|
||||
>
|
||||
> **killall -STOP -u user1**
|
||||
>
|
||||
> If you can’t use the command line due to all processes being used, you will have to use **exec** to force it to run:
|
||||
>
|
||||
> **exec killall -STOP -u user1**
|
||||
>
|
||||
> With fork bombs, your best option is preventing them from becoming too big of an issue in the first place
|
||||
|
||||
24. What is OOM killer and how does it decide which process to kill first?
|
||||
|
||||
|
||||
|
||||
> If memory is exhaustively used up by processes to the extent that possibly threatens the system’s stability, then the out of memory (OOM) killer comes into the picture.
|
||||
>
|
||||
> An OOM killer first has to select the best process(es) to kill. _Best_ here refers to the process which will free up the maximum memory upon being killed, and is also the least important to the system. The primary goal is to kill the least number of processes to minimize the damage done, and at the same time maximize the amount of memory freed.
|
||||
>
|
||||
> To facilitate this goal, the kernel maintains an oom_score for each of the processes. You can see the oom_score of each of the processes in the **/proc** filesystem under the **pid** directory:
|
||||
>
|
||||
> **$ cat /proc/10292/oom_score**
|
||||
>
|
||||
> The higher the value of oom_score for any process, the higher its likelihood is of being killed by the OOM Killer in an out-of-memory situation. ([Citation][9])
|
||||
|
||||
### Conclusion
|
||||
|
||||
System administration salaries have a [wide range][10] with some sites mentioning $70,000 to $100,000 a year, depending on the location, the size of the organization, and your education level plus years of experience. In the end, the system administration career path boils down to your interest in working with servers and solving cool problems. Now, I would say go ahead and achieve your dream path.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/7/sysadmin-job-interview-questions
|
||||
|
||||
作者:[DirectedSoul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/directedsoul
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_HowToFish_520x292.png?itok=DHbdxv6H (Question and answer.)
|
||||
[2]: https://github.com/trimstray/test-your-sysadmin-skills
|
||||
[3]: https://www.waytoeasylearn.com/2016/05/netapp-filer-tutorial.html
|
||||
[4]: https://searchstorage.techtarget.com/definition/RAID-10-redundant-array-of-independent-disks
|
||||
[5]: https://www.answers.com/Q/What_is_hard_link_and_soft_link_in_Linux
|
||||
[6]: https://www.wisdomjobs.com/e-university/network-administrator-interview-questions.html
|
||||
[7]: https://unix.stackexchange.com/questions/105/chroot-jail-what-is-it-and-how-do-i-use-it
|
||||
[8]: https://serverfault.com/questions/391370/how-to-prevent-zero-day-attacks
|
||||
[9]: https://unix.stackexchange.com/a/153586/8369
|
||||
[10]: https://blog.netwrix.com/2018/07/23/systems-administrator-salary-in-2018-how-much-can-you-earn/
|
@ -1,137 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Counting down the days using bash)
|
||||
[#]: via: (https://www.networkworld.com/article/3487712/counting-down-the-days-using-bash.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
Counting down the days using bash
|
||||
======
|
||||
Need to know how many days there are before some important event? Let Linux bash and the date command help with that!
|
||||
Thinkstock
|
||||
|
||||
With some pretty important holidays right around the corner, you might need to be reminded how much longer you have to prepare.
|
||||
|
||||
Fortunately, you can get a lot of help from the **date** command. In this post, we’ll look at ways that **date** and bash scripts can tell you how many days there are between today and some event that you’re anticipating.
|
||||
|
||||
[[Get regularly scheduled insights by signing up for Network World newsletters.]][1]
|
||||
|
||||
First a couple hints at how this is going to work. The **date** command’s **%j** option is going to show you today’s date as a number between 1 and 366. January 1st, as you’d expect, will be displayed as 1 and December 31st will be 365 or 366 depending on whether it’s leap year. Go ahead and try it. You should see something like this:
|
||||
|
||||
[][2]
|
||||
|
||||
BrandPost Sponsored by HPE
|
||||
|
||||
[Take the Intelligent Route with Consumption-Based Storage][2]
|
||||
|
||||
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
|
||||
|
||||
```
|
||||
$ date +%j
|
||||
339
|
||||
```
|
||||
|
||||
You can, however, get the **date** command to give you the day-of-the-year number for _any_ date by supplying it in a **date** command like this:
|
||||
|
||||
```
|
||||
$ date -d "Mar 18" +%j
|
||||
077
|
||||
```
|
||||
|
||||
One important thing to keep in mind is that this command will show you the date in the _current year_ even if that date is in the past. However, you can add a year to the command and fix that:
|
||||
|
||||
```
|
||||
$ date -d "Apr 29" +%j
|
||||
119
|
||||
$ date -d "Apr 29 2020" +%j
|
||||
120
|
||||
```
|
||||
|
||||
In a leap year, Apr 29th will be the 120th day of the year, not the 119th.
|
||||
|
||||
If you want to count down the days until Christmas and don’t want to end up with fingerprints on your wall calendar, you can use a script like this:
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
XMAS=`date -d "Dec 25" +%j`
|
||||
TODAY=`date +%j`
|
||||
DAYS=$(($XMAS - $TODAY))
|
||||
|
||||
case $DAYS in
|
||||
0) echo "It's today! Merry Christmas!";;
|
||||
[0-9]*) echo "$DAYS days remaining";;
|
||||
-[0-9]*) echo "Oops, you missed it";;
|
||||
esac
|
||||
```
|
||||
|
||||
In this script, we get the day numbers for Dec 25th and today and then subtract one from the other. If the result is positive, we display the number of days remaining. If it’s zero, we issue a “Merry Christmas” message and, if it’s negative, we just tell the person running the script that they missed the holiday. Maybe they got carried away with the egg nog.
|
||||
|
||||
The case statement is made up of ready-to-print statements for remaining-day counts that equal zero, those that that include any digits and those that start with a **-** sign (i.e., in the past).
|
||||
|
||||
The same idea can be generalized for any date that someone wants to keep in focus. In fact, we can ask the person running our script to supply the date and then let them know how many days remain between now and then. This version of the script does just that.
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
echo -n "Enter event date (e.g., June 6): "
|
||||
read dt
|
||||
EVENT=`date -d "$dt" +%j`
|
||||
TODAY=`date +%j`
|
||||
DAYS=`expr $EVENT - $TODAY`
|
||||
|
||||
case $DAYS in
|
||||
0) echo "It's today!";;
|
||||
[0-9]*) echo "$DAYS days remaining";;
|
||||
-[0-9]*) echo "Oops, you missed it";;
|
||||
esac
|
||||
```
|
||||
|
||||
One problem you’ll have with this script is that, if the person running it is hoping to find out how many days must pass before they reach a special day the following year, they’ll be disappointed. Even if they supply a year when they enter the date, the date -d command will still only supply the day number in that year, not the days between now and then.
|
||||
|
||||
Calculating the number of days between today and some date years from now can be a bit tricky. You’d need to include all the intervening years and pay attention to those that are leap years.
|
||||
|
||||
### Using Unix (Epoch) time
|
||||
|
||||
Another way to calculate the number of days between now and some special date is to take advantage of the way that Unix systems store dates. If you convert the number of seconds since the start of the day on Jan 1, 1970 to days, you can do this quite easily as in this script:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
echo -n "Enter target date (e.g., Mar 18 2021)> "
|
||||
read target_date
|
||||
today=`echo $(($(date --utc --date "$1" +%s)/86400))`
|
||||
target=`echo $(($(date --utc --date "$target_date" +%s)/86400))`
|
||||
days=`expr $target - $today`
|
||||
echo "$days days until $target_date"
|
||||
```
|
||||
|
||||
To explain, 86400 is the number of seconds in a day. Dividing the number of seconds since the epoch began by this number gives us the number of days.
|
||||
|
||||
```
|
||||
$ ./countdown
|
||||
Enter target date (e.g., Mar 18 2021)> Mar 18 2020
|
||||
104 days until Mar 18 2020
|
||||
```
|
||||
|
||||
Join the Network World communities on [Facebook][3] and [LinkedIn][4] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3487712/counting-down-the-days-using-bash.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/newsletters/signup.html
|
||||
[2]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||
[3]: https://www.facebook.com/NetworkWorld/
|
||||
[4]: https://www.linkedin.com/company/network-world
|
@ -0,0 +1,105 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Annotate screenshots on Linux with Ksnip)
|
||||
[#]: via: (https://opensource.com/article/19/12/annotate-screenshots-linux-ksnip)
|
||||
[#]: author: (Clayton Dewey https://opensource.com/users/cedewey)
|
||||
|
||||
Annotate screenshots on Linux with Ksnip
|
||||
======
|
||||
Ksnip allows you to create and mark up screenshots in Linux with ease.
|
||||
![a checklist for a team][1]
|
||||
|
||||
I recently switched from MacOS to [Elementary OS][2], a Linux distribution focused on ease of use and privacy. As a user-experience designer and a free software supporter, I take screenshots and annotate them all the time. After trying out several different tools, the one I enjoy the most by far is [Ksnip][3], an open source tool licensed under GPLv2.
|
||||
|
||||
![Ksnip screenshot][4]
|
||||
|
||||
### Installation
|
||||
|
||||
Install Ksnip with your preferred package manager. I installed it via Apt:
|
||||
|
||||
|
||||
```
|
||||
`sudo apt-get install ksnip`
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Ksnip comes with quite a few configuration options, including:
|
||||
|
||||
* Location to save screenshots
|
||||
* Default screenshot filename
|
||||
* Image grabber behavior
|
||||
* Cursor color and thickness
|
||||
* Text font
|
||||
|
||||
|
||||
|
||||
You can also integrate it with your Imgur account.
|
||||
|
||||
![Ksnip configuration options][5]
|
||||
|
||||
### Usage
|
||||
|
||||
Ksnip offers a wide range of [features][6]. My favorite part of Ksnip is that it has all the annotation tools I need (plus one I hadn't thought of!).
|
||||
|
||||
You can annotate with:
|
||||
|
||||
* Pen
|
||||
* Marker
|
||||
* Rectangles
|
||||
* Ellipses
|
||||
* Text
|
||||
|
||||
|
||||
|
||||
You can also blur areas to remove sensitive information. And use my new favorite tool: numbered dots for steps on an interface.
|
||||
|
||||
### About the creator
|
||||
|
||||
I'm enjoying Ksnip so much that I reached out to the creator, [Damir Porobic][7], to learn more about the project.
|
||||
|
||||
When I asked what inspired him to create Ksnip, he said:
|
||||
|
||||
> "I switched from Windows to Linux a few years ago and missed the Windows Snipping Tool that I was used to on Windows. All other screenshot tools at that time were either huge (a lot of buttons and complex features) or lacked key features like annotations, so I decided to build a simple Snipping Tool clone, but with time it got more and more features. So here we are."
|
||||
|
||||
This is exactly what I found as I was evaluating screenshot tools. It's great that he took the time to build a solution and freely share it for others to benefit.
|
||||
|
||||
As for the future of Ksnip, Damir would like to add global shortcuts (at least for Windows) and tabs for new screenshots and allow the application to run in the background. There is also a growing list of feature requests on GitHub.
|
||||
|
||||
### Ways to help
|
||||
|
||||
Damir's biggest need for Ksnip help is with development. He and his wife are expecting a baby soon, so he won't have as much time to devote to the project. He is available to review and accept pull requests, though.
|
||||
|
||||
Also, the project could benefit from additional installation options via Snap and Flatpak and installers for MacOS and a setup for Windows. If you would like to help, check out the [Contribution][8] section of Ksnip's README.
|
||||
|
||||
* * *
|
||||
|
||||
_This article originally appeared on [Agaric Tech Cooperative's blog][9] and is republished with permission._
|
||||
|
||||
How do you know when your documentation needs screenshots? Ben Cotton shares some helpful tips.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/annotate-screenshots-linux-ksnip
|
||||
|
||||
作者:[Clayton Dewey][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/cedewey
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk (a checklist for a team)
|
||||
[2]: https://elementary.io/
|
||||
[3]: https://github.com/damirporobic/ksnip
|
||||
[4]: https://opensource.com/sites/default/files/uploads/ksnip.png (Ksnip screenshot)
|
||||
[5]: https://opensource.com/sites/default/files/uploads/ksnip-configuration.png (Ksnip configuration options)
|
||||
[6]: https://github.com/DamirPorobic/ksnip#features
|
||||
[7]: https://github.com/damirporobic/
|
||||
[8]: https://github.com/DamirPorobic/ksnip/blob/master/README.md#contribution
|
||||
[9]: https://agaric.coop/blog/annotate-screenshots-linux-ksnip
|
@ -0,0 +1,474 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Enable your Python game player to run forward and backward)
|
||||
[#]: via: (https://opensource.com/article/19/12/python-platformer-game-run)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Enable your Python game player to run forward and backward
|
||||
======
|
||||
Let your player run free by enabling the side-scroller effect in your
|
||||
Python platformer using the Pygame module.
|
||||
![Gaming artifacts with joystick, GameBoy, paddle][1]
|
||||
|
||||
This is part 8 in an ongoing series about creating video games in Python 3 using the Pygame module. Previous articles are:
|
||||
|
||||
* [Learn how to program in Python by building a simple dice game][2]
|
||||
* [Build a game framework with Python using the Pygame module][3]
|
||||
* [How to add a player to your Python game][4]
|
||||
* [Using Pygame to move your game character around][5]
|
||||
* [What's a hero without a villain? How to add one to your Python game][6]
|
||||
* [Simulate gravity in your Python game][7]
|
||||
* [Add jumping to your Python platformer game][8]
|
||||
|
||||
|
||||
|
||||
In previous entries in this series about creating video games in [Python 3][9] using the [Pygame][10] module, you designed your level-design layout, but some portion of your level probably extended past your viewable screen. The ubiquitous solution to that problem in platformer games is, as the term "side-scroller" suggests, scrolling.
|
||||
|
||||
The key to scrolling is to make the platforms around the player sprite move when the player sprite gets close to the edge of the screen. This provides the illusion that the screen is a "camera" panning across the game world.
|
||||
|
||||
This scrolling trick requires two dead zones at either edge of the screen, at which point your avatar stands still while the world scrolls by.
|
||||
|
||||
### Putting the scroll in side-scroller
|
||||
|
||||
You need one trigger point to go forward and another if you want your player to be able to go backward. These two points are simply two variables. Set them each about 100 or 200 pixels from each screen edge. Create the variables in your **setup** section. In the following code, the first two lines are for context, so just add the last two lines:
|
||||
|
||||
|
||||
```
|
||||
player_list.add(player)
|
||||
steps = 10
|
||||
forwardX = 600
|
||||
backwardX = 230
|
||||
```
|
||||
|
||||
In the main loop, check to see if your player sprite is at the **forwardx** or **backwardx** scroll point. If so, move all platforms either left or right, depending on whether the world is moving forward or backward. In the following code, the final three lines of code are only for your reference:
|
||||
|
||||
|
||||
```
|
||||
# scroll the world forward
|
||||
if player.rect.x >= forwardx:
|
||||
scroll = player.rect.x - forwardx
|
||||
player.rect.x = forwardx
|
||||
for p in plat_list:
|
||||
p.rect.x -= scroll
|
||||
|
||||
# scroll the world backward
|
||||
if player.rect.x <= backwardx:
|
||||
scroll = backwardx - player.rect.x
|
||||
player.rect.x = backwardx
|
||||
for p in plat_list:
|
||||
p.rect.x += scroll
|
||||
|
||||
## scrolling code above
|
||||
world.blit(backdrop, backdropbox)
|
||||
player.gravity() # check gravity
|
||||
player.update()
|
||||
```
|
||||
|
||||
Launch your game and try it out.
|
||||
|
||||
![Scrolling the world in Pygame][11]
|
||||
|
||||
Scrolling works as expected, but you may notice a small problem that happens when you scroll the world around your player and non-player sprites: the enemy sprite doesn't scroll along with the world. Unless you want
|
||||
|
||||
your enemy sprite to pursue your player endlessly, you need to modify the enemy code so that when your player makes an expeditious retreat, the enemy is left behind.
|
||||
|
||||
### Enemy scroll
|
||||
|
||||
In your main loop, you must apply the same rules for scrolling platforms to your enemy's position. Because your game world will (presumably) have more than one enemy in it, the rules are applied to your enemy list rather than an individual enemy sprite. That's one of the advantages of grouping similar elements into lists.
|
||||
|
||||
The first two lines are for context, so just add the final two to your main loop:
|
||||
|
||||
|
||||
```
|
||||
# scroll the world forward
|
||||
if player.rect.x >= forwardx:
|
||||
scroll = player.rect.x - forwardx
|
||||
player.rect.x = forwardx
|
||||
for p in plat_list:
|
||||
p.rect.x -= scroll
|
||||
for e in enemy_list:
|
||||
e.rect.x -= scroll
|
||||
```
|
||||
|
||||
To scroll in the other direction:
|
||||
|
||||
|
||||
```
|
||||
# scroll the world backward
|
||||
if player.rect.x <= backwardx:
|
||||
scroll = backwardx - player.rect.x
|
||||
player.rect.x = backwardx
|
||||
for p in plat_list:
|
||||
p.rect.x += scroll
|
||||
for e in enemy_list:
|
||||
e.rect.x += scroll
|
||||
```
|
||||
|
||||
Launch the game again and see what happens.
|
||||
|
||||
Here's all the code you've written for this Python platformer so far:
|
||||
|
||||
|
||||
```
|
||||
#!/usr/bin/env python3
|
||||
# draw a world
|
||||
# add a player and player control
|
||||
# add player movement
|
||||
# add enemy and basic collision
|
||||
# add platform
|
||||
# add gravity
|
||||
# add jumping
|
||||
# add scrolling
|
||||
|
||||
# GNU All-Permissive License
|
||||
# Copying and distribution of this file, with or without modification,
|
||||
# are permitted in any medium without royalty provided the copyright
|
||||
# notice and this notice are preserved. This file is offered as-is,
|
||||
# without any warranty.
|
||||
|
||||
import pygame
|
||||
import sys
|
||||
import os
|
||||
|
||||
'''
|
||||
Objects
|
||||
'''
|
||||
|
||||
class Platform(pygame.sprite.Sprite):
|
||||
# x location, y location, img width, img height, img file
|
||||
def __init__(self,xloc,yloc,imgw,imgh,img):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.image.load(os.path.join('images',img)).convert()
|
||||
self.image.convert_alpha()
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.y = yloc
|
||||
self.rect.x = xloc
|
||||
|
||||
class Player(pygame.sprite.Sprite):
|
||||
'''
|
||||
Spawn a player
|
||||
'''
|
||||
def __init__(self):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.movex = 0
|
||||
self.movey = 0
|
||||
self.frame = 0
|
||||
self.health = 10
|
||||
self.collide_delta = 0
|
||||
self.jump_delta = 6
|
||||
self.score = 1
|
||||
self.images = []
|
||||
for i in range(1,9):
|
||||
img = pygame.image.load(os.path.join('images','hero' + str(i) + '.png')).convert()
|
||||
img.convert_alpha()
|
||||
img.set_colorkey(ALPHA)
|
||||
self.images.append(img)
|
||||
self.image = self.images[0]
|
||||
self.rect = self.image.get_rect()
|
||||
|
||||
def jump(self,platform_list):
|
||||
self.jump_delta = 0
|
||||
|
||||
def gravity(self):
|
||||
self.movey += 3.2 # how fast player falls
|
||||
|
||||
if self.rect.y > worldy and self.movey >= 0:
|
||||
self.movey = 0
|
||||
self.rect.y = worldy-ty
|
||||
|
||||
def control(self,x,y):
|
||||
'''
|
||||
control player movement
|
||||
'''
|
||||
self.movex += x
|
||||
self.movey += y
|
||||
|
||||
def update(self):
|
||||
'''
|
||||
Update sprite position
|
||||
'''
|
||||
|
||||
self.rect.x = self.rect.x + self.movex
|
||||
self.rect.y = self.rect.y + self.movey
|
||||
|
||||
# moving left
|
||||
if self.movex < 0:
|
||||
self.frame += 1
|
||||
if self.frame > ani*3:
|
||||
self.frame = 0
|
||||
self.image = self.images[self.frame//ani]
|
||||
|
||||
# moving right
|
||||
if self.movex > 0:
|
||||
self.frame += 1
|
||||
if self.frame > ani*3:
|
||||
self.frame = 0
|
||||
self.image = self.images[(self.frame//ani)+4]
|
||||
|
||||
# collisions
|
||||
enemy_hit_list = pygame.sprite.spritecollide(self, enemy_list, False)
|
||||
for enemy in enemy_hit_list:
|
||||
self.health -= 1
|
||||
#print(self.health)
|
||||
|
||||
plat_hit_list = pygame.sprite.spritecollide(self, plat_list, False)
|
||||
for p in plat_hit_list:
|
||||
self.collide_delta = 0 # stop jumping
|
||||
self.movey = 0
|
||||
if self.rect.y > p.rect.y:
|
||||
self.rect.y = p.rect.y+ty
|
||||
else:
|
||||
self.rect.y = p.rect.y-ty
|
||||
|
||||
ground_hit_list = pygame.sprite.spritecollide(self, ground_list, False)
|
||||
for g in ground_hit_list:
|
||||
self.movey = 0
|
||||
self.rect.y = worldy-ty-ty
|
||||
self.collide_delta = 0 # stop jumping
|
||||
if self.rect.y > g.rect.y:
|
||||
self.health -=1
|
||||
print(self.health)
|
||||
|
||||
if self.collide_delta < 6 and self.jump_delta < 6:
|
||||
self.jump_delta = 6*2
|
||||
self.movey -= 33 # how high to jump
|
||||
self.collide_delta += 6
|
||||
self.jump_delta += 6
|
||||
|
||||
class Enemy(pygame.sprite.Sprite):
|
||||
'''
|
||||
Spawn an enemy
|
||||
'''
|
||||
def __init__(self,x,y,img):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.image.load(os.path.join('images',img))
|
||||
self.movey = 0
|
||||
#self.image.convert_alpha()
|
||||
#self.image.set_colorkey(ALPHA)
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.x = x
|
||||
self.rect.y = y
|
||||
self.counter = 0
|
||||
|
||||
|
||||
def move(self):
|
||||
'''
|
||||
enemy movement
|
||||
'''
|
||||
distance = 80
|
||||
speed = 8
|
||||
|
||||
self.movey += 3.2
|
||||
|
||||
if self.counter >= 0 and self.counter <= distance:
|
||||
self.rect.x += speed
|
||||
elif self.counter >= distance and self.counter <= distance*2:
|
||||
self.rect.x -= speed
|
||||
else:
|
||||
self.counter = 0
|
||||
|
||||
self.counter += 1
|
||||
|
||||
if not self.rect.y >= worldy-ty-ty:
|
||||
self.rect.y += self.movey
|
||||
|
||||
plat_hit_list = pygame.sprite.spritecollide(self, plat_list, False)
|
||||
for p in plat_hit_list:
|
||||
self.movey = 0
|
||||
if self.rect.y > p.rect.y:
|
||||
self.rect.y = p.rect.y+ty
|
||||
else:
|
||||
self.rect.y = p.rect.y-ty
|
||||
|
||||
ground_hit_list = pygame.sprite.spritecollide(self, ground_list, False)
|
||||
for g in ground_hit_list:
|
||||
self.rect.y = worldy-ty-ty
|
||||
|
||||
|
||||
class Level():
|
||||
def bad(lvl,eloc):
|
||||
if lvl == 1:
|
||||
enemy = Enemy(eloc[0],eloc[1],'yeti.png') # spawn enemy
|
||||
enemy_list = pygame.sprite.Group() # create enemy group
|
||||
enemy_list.add(enemy) # add enemy to group
|
||||
|
||||
if lvl == 2:
|
||||
print("Level " + str(lvl) )
|
||||
|
||||
return enemy_list
|
||||
|
||||
def loot(lvl,lloc):
|
||||
print(lvl)
|
||||
|
||||
def ground(lvl,gloc,tx,ty):
|
||||
ground_list = pygame.sprite.Group()
|
||||
i=0
|
||||
if lvl == 1:
|
||||
while i < len(gloc):
|
||||
ground = Platform(gloc[i],worldy-ty,tx,ty,'ground.png')
|
||||
ground_list.add(ground)
|
||||
i=i+1
|
||||
|
||||
if lvl == 2:
|
||||
print("Level " + str(lvl) )
|
||||
|
||||
return ground_list
|
||||
|
||||
def platform(lvl,tx,ty):
|
||||
plat_list = pygame.sprite.Group()
|
||||
ploc = []
|
||||
i=0
|
||||
if lvl == 1:
|
||||
ploc.append((0,worldy-ty-128,3))
|
||||
ploc.append((300,worldy-ty-256,3))
|
||||
ploc.append((500,worldy-ty-128,4))
|
||||
|
||||
while i < len(ploc):
|
||||
j=0
|
||||
while j <= ploc[i][2]:
|
||||
plat = Platform((ploc[i][0]+(j*tx)),ploc[i][1],tx,ty,'ground.png')
|
||||
plat_list.add(plat)
|
||||
j=j+1
|
||||
print('run' + str(i) + str(ploc[i]))
|
||||
i=i+1
|
||||
|
||||
if lvl == 2:
|
||||
print("Level " + str(lvl) )
|
||||
|
||||
return plat_list
|
||||
|
||||
'''
|
||||
Setup
|
||||
'''
|
||||
worldx = 960
|
||||
worldy = 720
|
||||
|
||||
fps = 40 # frame rate
|
||||
ani = 4 # animation cycles
|
||||
clock = pygame.time.Clock()
|
||||
pygame.init()
|
||||
main = True
|
||||
|
||||
BLUE = (25,25,200)
|
||||
BLACK = (23,23,23 )
|
||||
WHITE = (254,254,254)
|
||||
ALPHA = (0,255,0)
|
||||
|
||||
world = pygame.display.set_mode([worldx,worldy])
|
||||
backdrop = pygame.image.load(os.path.join('images','stage.png')).convert()
|
||||
backdropbox = world.get_rect()
|
||||
player = Player() # spawn player
|
||||
player.rect.x = 0
|
||||
player.rect.y = 0
|
||||
player_list = pygame.sprite.Group()
|
||||
player_list.add(player)
|
||||
steps = 10
|
||||
forwardx = 600
|
||||
backwardx = 230
|
||||
|
||||
eloc = []
|
||||
eloc = [200,20]
|
||||
gloc = []
|
||||
#gloc = [0,630,64,630,128,630,192,630,256,630,320,630,384,630]
|
||||
tx = 64 #tile size
|
||||
ty = 64 #tile size
|
||||
|
||||
i=0
|
||||
while i <= (worldx/tx)+tx:
|
||||
gloc.append(i*tx)
|
||||
i=i+1
|
||||
|
||||
enemy_list = Level.bad( 1, eloc )
|
||||
ground_list = Level.ground( 1,gloc,tx,ty )
|
||||
plat_list = Level.platform( 1,tx,ty )
|
||||
|
||||
'''
|
||||
Main loop
|
||||
'''
|
||||
while main == True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit(); sys.exit()
|
||||
main = False
|
||||
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_LEFT or event.key == ord('a'):
|
||||
print("LEFT")
|
||||
player.control(-steps,0)
|
||||
if event.key == pygame.K_RIGHT or event.key == ord('d'):
|
||||
print("RIGHT")
|
||||
player.control(steps,0)
|
||||
if event.key == pygame.K_UP or event.key == ord('w'):
|
||||
print('jump')
|
||||
|
||||
if event.type == pygame.KEYUP:
|
||||
if event.key == pygame.K_LEFT or event.key == ord('a'):
|
||||
player.control(steps,0)
|
||||
if event.key == pygame.K_RIGHT or event.key == ord('d'):
|
||||
player.control(-steps,0)
|
||||
if event.key == pygame.K_UP or event.key == ord('w'):
|
||||
player.jump(plat_list)
|
||||
|
||||
if event.key == ord('q'):
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
main = False
|
||||
|
||||
# scroll the world forward
|
||||
if player.rect.x >= forwardx:
|
||||
scroll = player.rect.x - forwardx
|
||||
player.rect.x = forwardx
|
||||
for p in plat_list:
|
||||
p.rect.x -= scroll
|
||||
for e in enemy_list:
|
||||
e.rect.x -= scroll
|
||||
|
||||
# scroll the world backward
|
||||
if player.rect.x <= backwardx:
|
||||
scroll = backwardx - player.rect.x
|
||||
player.rect.x = backwardx
|
||||
for p in plat_list:
|
||||
p.rect.x += scroll
|
||||
for e in enemy_list:
|
||||
e.rect.x += scroll
|
||||
|
||||
world.blit(backdrop, backdropbox)
|
||||
player.gravity() # check gravity
|
||||
player.update()
|
||||
player_list.draw(world) #refresh player position
|
||||
enemy_list.draw(world) # refresh enemies
|
||||
ground_list.draw(world) # refresh enemies
|
||||
plat_list.draw(world) # refresh platforms
|
||||
for e in enemy_list:
|
||||
e.move()
|
||||
pygame.display.flip()
|
||||
clock.tick(fps)
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/python-platformer-game-run
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/open_gaming_games_roundup_news.png?itok=KM0ViL0f (Gaming artifacts with joystick, GameBoy, paddle)
|
||||
[2]: https://opensource.com/article/17/10/python-101
|
||||
[3]: https://opensource.com/article/17/12/game-framework-python
|
||||
[4]: https://opensource.com/article/17/12/game-python-add-a-player
|
||||
[5]: https://opensource.com/article/17/12/game-python-moving-player
|
||||
[6]: https://opensource.com/article/18/5/pygame-enemy
|
||||
[7]: https://opensource.com/article/19/11/simulate-gravity-python
|
||||
[8]: https://opensource.com/article/19/12/jumping-python-platformer-game
|
||||
[9]: https://www.python.org/
|
||||
[10]: https://www.pygame.org/news
|
||||
[11]: https://opensource.com/sites/default/files/uploads/pygame-scroll.jpg (Scrolling the world in Pygame)
|
@ -0,0 +1,78 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Revamp your old Linux desktop with Joe's Window Manager)
|
||||
[#]: via: (https://opensource.com/article/19/12/joes-window-manager-linux-desktop)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Revamp your old Linux desktop with Joe's Window Manager
|
||||
======
|
||||
This article is part of a special series of 24 days of Linux desktops.
|
||||
JWM's meager weight and simplicity makes it a great window manager for
|
||||
slow or old Linux computers.
|
||||
![and old computer and a new computer, representing migration to new software or hardware][1]
|
||||
|
||||
Joe's Window Manager ([JWM][2] for short) is a lightweight window manager for X11. It's written in C, minimally using [Xlib][3]. Because it's so small and simple, JWM makes a great window manager for slow or old computers. The Raspberry Pi barely registers that JWM is running, leaving precious system resources for more important tasks than the desktop.
|
||||
|
||||
JWM follows in the footsteps of environments like FVWM, Window Maker, and Fluxbox. It provides an application menu, window decoration, and a panel with an application menu, taskbar, and clock.
|
||||
|
||||
Install JWM from your distribution's software repository. After installing it, log out of your current desktop session so you can log into JWM. By default, your session manager (KDM, GDM, LightDM, or XDM, depending on your setup) will continue to log you into your previous desktop, so you must override that before logging in.
|
||||
|
||||
To select a new desktop with GDM:
|
||||
|
||||
![Select your desktop session in GDM][4]
|
||||
|
||||
With KDM:
|
||||
|
||||
![Select your desktop session with KDM][5]
|
||||
|
||||
The first time you log into JWM, you may find a black screen with a panel at the bottom. It's normal on most distributions to let you choose the wallpaper for this minimal desktop. You can set a wallpaper with the **feh** command (you may need to install it from your repository). This command has a few options for setting the background, including **\--bg-fill** to fill the screen with your wallpaper of choice, **\--bg-scale** to scale it to fit, and so on.
|
||||
|
||||
|
||||
```
|
||||
`$ feh --bg-fill ~/Pictures/wallpapers/mybackground.jpg`
|
||||
```
|
||||
|
||||
### Application menu
|
||||
|
||||
There are two locations for the application menus in JWM: it appears at your mouse cursor when you left-click on the desktop, and it is also available by clicking the JWM logo in the lower-left corner.
|
||||
|
||||
![JWM running on Debian][6]
|
||||
|
||||
There aren't any applications bundled with JWM, so it's up to you to decide what applications to use. You can get applications from any desktop, like GNOME or KDE, or you can use independent applications. Most of the integration between applications is done by [D-Bus][7] and other backend technology on Linux, so it's safe to mix and match them. I use [PCManFM-Qt][8] as a file manager, [unicode-rxvt][9] as a terminal, and, of course, Firefox as an internet browser.
|
||||
|
||||
### Configuration
|
||||
|
||||
Two configuration files govern JWM. The system-wide configuration file is **/etc/jwm/system.jwmrc**, and the user local file is **$HOME/.jwmrc**. Configuration files are written in XML, but the schema is very basic and easy to reverse-engineer, whether you know XML or not. Configuration options are well-documented on [Joewing.net][10], home of the JWM project.
|
||||
|
||||
### Why you should use JWM
|
||||
|
||||
There's no shortage of lightweight window managers available for Linux, and you might wonder why there seems to be so much redundancy, much less why you should try Joe's. There are a few reasons JWM is as important as any of the others. When looking at software projects, redundancy is a _good thing_. Should one project's implementation of a desktop paradigm fade, you have many others to choose from. And often, the strengths of each project are in the minor details. For example, the quick and easy setup of a taskbar and application menu makes for a quick, sensible default configuration for all the users who want that common setup. For technical users, the XML configuration may be a refreshing change from the custom configuration formats in other environments.
|
||||
|
||||
Joe's Window Manager, in a way, demonstrates the rich diversity of open source and how it's a luxury Linux users enjoy. If you're interested in JWM, try it out today, and see if you can make your own window manager, too.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/joes-window-manager-linux-desktop
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/migration_innovation_computer_software.png?itok=VCFLtd0q (and old computer and a new computer, representing migration to new software or hardware)
|
||||
[2]: http://joewing.net/projects/jwm/
|
||||
[3]: https://en.wikipedia.org/wiki/Xlib
|
||||
[4]: https://opensource.com/sites/default/files/advent-gdm_0.jpg (Select your desktop session in GDM)
|
||||
[5]: https://opensource.com/sites/default/files/advent-kdm.jpg (Select your desktop session with KDM)
|
||||
[6]: https://opensource.com/sites/default/files/uploads/advent-jwm_675px.jpg (JWM running on Debian)
|
||||
[7]: https://en.wikipedia.org/wiki/D-Bus
|
||||
[8]: https://blog.lxqt.org/category/pcmanfm-qt/
|
||||
[9]: https://opensource.com/article/19/10/why-use-rxvt-terminal
|
||||
[10]: http://joewing.net/projects/jwm/config-2.3.html
|
@ -0,0 +1,129 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (15 Useful Firefox Keyboard Shortcuts You Should Know)
|
||||
[#]: via: (https://itsfoss.com/firefox-keyboard-shortcuts/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
15 Useful Firefox Keyboard Shortcuts You Should Know
|
||||
======
|
||||
|
||||
[Firefox][1] is one of the most popular free and open-source browsers for Linux users. Even though you have a lot of [open source chrome alternatives][2], Firefox still is one of the best choices to go with.
|
||||
|
||||
And you don’t even need to [install Firefox on Ubuntu][3] or most other distributions because it is installed by default.
|
||||
|
||||
What if you can make your browsing experience on Firefox even better by using some keyboard shortcuts?
|
||||
|
||||
Hold on, of course, not everyone prefers to use keyboard shortcuts. But, if you’re comfortable with that and want to do perform tasks in a jiffy, you should know some of the most common Firefox keyboard shortcuts.
|
||||
|
||||
It is also worth noting that you could use some of these shortcuts on Chrome/Chromium as well- however, we already have a list of [useful Google Chrome shortcuts][4] to help you out. So, if you’re using Chrome/Chromium, I insist you check out that article.
|
||||
|
||||
### 15 Useful Firefox Keyboard Shortcuts
|
||||
|
||||
![][5]
|
||||
|
||||
You could always refer to the [official documentation][6] of keyboard shortcuts for Firefox. However, that’s a very long list, and you probably do not need to use all of that.
|
||||
|
||||
So, here, I shall be listing the most commonly used (and useful) keyboard shortcuts that you can use on Firefox. To be honest, these are the shortcuts that I use most frequently on Firefox.
|
||||
|
||||
#### 1\. Open A New Tab
|
||||
|
||||
You don’t have to hover your cursor over to the **+** sign in the browser.
|
||||
|
||||
Simply press **CTRL + T** to open a new tab in the same window.
|
||||
|
||||
#### 2\. Open A New Tab In A New Window
|
||||
|
||||
If you want to open up a new window along with a new tab, you just have to press **CTRL + N**.
|
||||
|
||||
#### 3\. Close A Tab
|
||||
|
||||
Lazy to use your mouse to navigate and close the tab? Fret not, just press **CTRL + W** to make your active tab vanish!
|
||||
|
||||
#### 4\. Open A New Private Window
|
||||
|
||||
Don’t want to store the history/cookies for a specific browsing session? You can try the private mode by pressing **CTRL + Shift + P** as the keyboard shortcut for Firefox.
|
||||
|
||||
#### 5\. Open Recently Closed Tabs
|
||||
|
||||
If you closed a tab recently (or a number of tabs), just press **CTRL + Shift + T** till you get all your closed tabs restored.
|
||||
|
||||
#### 6\. Reload Webpage
|
||||
|
||||
You might want to reload a webpage quickly, to do that press **F5**.
|
||||
|
||||
If you want to ignore the cached content and want to fetch a new copy of the webpage, you can try **CTRL + F5**.
|
||||
|
||||
#### 7\. Scroll Up/Down Webpage
|
||||
|
||||
You can also scroll up/down using just your keyboard.
|
||||
|
||||
Simply use **PAGE UP** to scroll up and **PAGE DOWN** key to scroll down.
|
||||
|
||||
#### 8\. Find A Text In Webpage
|
||||
|
||||
You do not need to endlessly look for a word on a webpage just like you would in a physical book.
|
||||
|
||||
Simply press **CTRL + F** and then type in the exact word, it should highlight the matching words if it exists.
|
||||
|
||||
#### 9\. Close Your Browser At Once
|
||||
|
||||
Hit **CTRL + Shift + W** to close all the tabs in one go. However, you might get the prompt to confirm it.
|
||||
|
||||
#### 10\. View The Page Source
|
||||
|
||||
If you’re interested to take peek at the webpage’s source code, you just have to press **CTRL + U** to open view source in a new tab.
|
||||
|
||||
#### 11\. Switch Tabs Quickly
|
||||
|
||||
If you have multiple tabs opened up, you can easily navigate through them by pressing:
|
||||
|
||||
**CTRL + Tab**.
|
||||
|
||||
#### 12\. View Your Downloads
|
||||
|
||||
Do you want to quickly take a look at your download library? All you need to do is press:
|
||||
|
||||
**CTRL + Shift + Y**
|
||||
|
||||
#### 13\. Bookmark A Webpage
|
||||
|
||||
To bookmark a webpage, hit **CTRL + D** and press the **ENTER** key to save it.
|
||||
|
||||
#### 14\. Select the Address/Search Bar
|
||||
|
||||
If you want to search for something through the address bar, hit **CTRL + L** to immediately highlight the search bar for you.
|
||||
|
||||
#### 15\. Check Browsing History
|
||||
|
||||
Usually, it needs a couple of clicks to view your history. But, you can just press **CTRL + H** to launch the sidebar to view your history right away.
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
As I mentioned, you will find a huge list of Firefox keyboard shortcuts if you take a look at their [official documentation][6].
|
||||
|
||||
If you want to explore more options, feel free to check the documentation. In either case, the mentioned keyboard shortcuts should come pretty handy.
|
||||
|
||||
I’ll be interested to know what Firefox keyboard shortcuts do you use? Let me know your thoughts in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/firefox-keyboard-shortcuts/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.mozilla.org/en-US/firefox/
|
||||
[2]: https://itsfoss.com/open-source-browsers-linux/
|
||||
[3]: https://itsfoss.com/firefox-quantum-ubuntu/
|
||||
[4]: https://itsfoss.com/google-chrome-shortcuts/
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/Firefox_Keyboard_Shortcuts.jpg?ssl=1
|
||||
[6]: https://developer.mozilla.org/en-US/docs/Tools/Keyboard_shortcuts
|
@ -0,0 +1,69 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to configure Openbox for your Linux desktop)
|
||||
[#]: via: (https://opensource.com/article/19/12/openbox-linux-desktop)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
How to configure Openbox for your Linux desktop
|
||||
======
|
||||
This article is part of a special series of 24 days of Linux desktops.
|
||||
The Openbox Linux window manager is light on system resources, easy to
|
||||
configure, and a pleasure to use.
|
||||
![open with sky and grass][1]
|
||||
|
||||
You may have used the [Openbox][2] desktop without knowing it: While Openbox is a great window manager on its own, it also serves as the window manager "engine" for desktop environments like LXDE and LXQT, and it can even manage KDE and GNOME. Aside from being the foundation for several desktops, Openbox is arguably one of the easiest window managers to configure for anyone who doesn't want to learn all the options to put into a config file. By using the **obconf** menu-based configuration application, all the common preferences can be set just as easily as in a full desktop, like GNOME or KDE.
|
||||
|
||||
### Installing Openbox
|
||||
|
||||
You are likely to find Openbox in the software repository of your Linux distribution, but you can also find it on [Openbox.org][3]. If you're already running a different desktop, it's safe to install Openbox on the same system, because Openbox doesn't include any bundled applications aside from a few configuration panels.
|
||||
|
||||
After installing it, log out of your current desktop session so you can log into your Openbox desktop. By default, your session manager (KDM, GDM, LightDM, or XDM, depending on your setup) will continue to log you into your previous desktop, so you must override that before logging in.
|
||||
|
||||
To override it with GDM:
|
||||
|
||||
![Select your desktop session in GDM][4]
|
||||
|
||||
With SDDM:
|
||||
|
||||
![Select your desktop session with KDM][5]
|
||||
|
||||
### Configure the Openbox desktop
|
||||
|
||||
By default, Openbox includes the **obconf** application, which you can use to choose and install themes, modify mouse behavior, set desktop preferences, and do much more. You can probably find other configuration applications, like **obmenu**, in your repository to configure other parts of your window manager.
|
||||
|
||||
![Openbox Obconf configuration application][6]
|
||||
|
||||
Building your own desktop experience is relatively easy. There are little components for all the usual desktop tropes, like [stalonetray][7] for a system tray, [Tint2][8] for a taskbar, or [Xfce4-panel][9] for nearly anything you can think of. String any set of applications together until you have the open source desktop of your dreams.
|
||||
|
||||
![Openbox][10]
|
||||
|
||||
### Why you should use Openbox
|
||||
|
||||
Openbox is light on system resources, easy to configure, and a pleasure to use. It pops up in the unlikeliest of places, so it can be a good system to get familiar with. You never know when you'll be in front of a desktop that secretly uses Openbox as its window manager (and won't it be nice that you know how to customize it?). If critical mass and open source appeal to you, open up the Openbox box and get started.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/openbox-linux-desktop
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc_general_openfield.png?itok=MeVN97oy (open with sky and grass)
|
||||
[2]: http://openbox.org
|
||||
[3]: http://openbox.org/wiki/Openbox:Download
|
||||
[4]: https://opensource.com/sites/default/files/advent-gdm_0.jpg (Select your desktop session in GDM)
|
||||
[5]: https://opensource.com/sites/default/files/advent-kdm.jpg (Select your desktop session with KDM)
|
||||
[6]: https://opensource.com/sites/default/files/uploads/advent-openbox-obconf_675px.jpg (Openbox Obconf configuration application)
|
||||
[7]: https://sourceforge.net/projects/stalonetray/
|
||||
[8]: https://opensource.com/article/19/1/productivity-tool-tint2
|
||||
[9]: http://xfce.org
|
||||
[10]: https://opensource.com/sites/default/files/uploads/advent-openbox_675px.jpg (Openbox)
|
@ -0,0 +1,236 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (24 sysadmin job interview questions you should know)
|
||||
[#]: via: (https://opensource.com/article/19/7/sysadmin-job-interview-questions)
|
||||
[#]: author: (DirectedSoul https://opensource.com/users/directedsoul)
|
||||
|
||||
24 个必知必会的系统管理员面试问题
|
||||
======
|
||||
|
||||
> 即将进行系统管理员工作面试吗? 阅读本文,了解你可能会遇到的一些问题以及可能的答案。
|
||||
|
||||
![Question and answer.][1]
|
||||
|
||||
作为一个经常与计算机打交道的极客,在硕士毕业后在 IT 行业选择我的职业是很自然的选择。因此,我认为走上系统管理员之路是正确的路径。在我的职业生涯中,我对求职面试过程非常熟悉。现在来看一下该职位的预期、职业发展道路,以及一系列常见问题和我的回答。
|
||||
|
||||
### 系统管理员的典型任务和职责
|
||||
|
||||
组织需要了解系统工作原理的人员,以确保数据安全并保持服务平稳运行。你可能会问:“等等,是不是系统管理员还能做更多的事情?”
|
||||
|
||||
你是对的。现在,一般来说,让我们看一下典型的系统管理员的日常任务。根据公司的需求和人员的技能水平,系统管理员的任务从管理台式机、笔记本电脑、网络和服务器到设计组织的 IT 策略不等。有时,系统管理员甚至负责购买和订购新的 IT 设备。
|
||||
|
||||
那些寻求系统管理工作作为其职业道路的人可能会发现,由于 IT 领域的快速变化是不可避免的,因此难以保持其技能和知识的最新状态。所有人都会想到的下一个自然而然的问题是 IT 专业人员如何掌握最新的更新和技能。
|
||||
|
||||
### 小意思
|
||||
|
||||
这是你将遇到的一些最基本的问题,以及我的答案:
|
||||
|
||||
1、在 *nix 服务器上登录后键入的前五个命令是什么?
|
||||
|
||||
> * `lsblk` 以查看所有的块设备信息
|
||||
> * `who` 查看谁登录到服务器
|
||||
> * `top`,以了解服务器上正在运行的进程
|
||||
> * `df -khT` 以查看服务器上可用的磁盘容量
|
||||
> * `netstat` 以查看哪些 TCP 网络连接处于活动状态
|
||||
|
||||
2、如何使进程在后台运行,这样做的好处是什么?
|
||||
|
||||
> 你可以通过在命令末尾添加特殊字符 `&` 来使进程在后台运行。通常,执行时间太长并且不需要用户交互的应用程序会放到后台,以便我们可以在终端中继续工作。([引文][2])
|
||||
|
||||
3、以 root 用户身份运行这些命令是好事还是坏事?
|
||||
|
||||
> 由于两个主要问题,以 root 身份运行(任何命令)是不好的。第一个是*风险*。当你以 **root** 身份登录时,无法避免你犯粗心大意的错误。如果你尝试以带有潜在危害的方式更改系统,则需要使用 `sudo`,它会引入一个暂停(在你输入密码时),以确保你不会犯错。
|
||||
>
|
||||
> 第二个原因是*安全*。如果你不知道管理员用户的登录信息,则系统更难被攻击。拥有 root 的访问权限意味着你已经拥有管理员凭据工作集的一半。
|
||||
|
||||
4、`rm` 和 `rm -rf` 有什么区别?
|
||||
|
||||
> `rm` 命令本身仅删除指明的文件(而不删除目录)。使用 `-rf` 标志,你添加了两个附加功能:`-r`、`-R` 或 `--recursive` 标志递归删除目录的内容,包括隐藏的文件和子目录;而 `-f`或 `--force` 标志使 `rm` 忽略不存在的文件,并且从不提示你进行确认。
|
||||
|
||||
5、有一个大小约为 15GB 的 `Compress.tgz` 文件。你如何列出其内容,以及如何仅提取出特定文件?
|
||||
|
||||
> 要列出文件的内容:
|
||||
>
|
||||
> `tar tf archive.tgz`
|
||||
>
|
||||
> 要提取特定文件:
|
||||
>
|
||||
> `tar xf archive.tgz filename`
|
||||
|
||||
### 中等意思
|
||||
|
||||
这是你可能会遇到的一些较难的问题,以及我的答案:
|
||||
|
||||
6、什么是 RAID?什么是 RAID 0、RAID 1、RAID 5、RAID 6 和 RAID 10?
|
||||
|
||||
> RAID(<ruby>廉价磁盘冗余阵列<rt>Redundant Array of Inexpensive Disks</rt></ruby>)是一种用于提高数据存储性能和/或可靠性的技术。RAID 级别为:
|
||||
>
|
||||
> * RAID 0:也称为磁盘条带化,这是一种分解文件并将数据分布在 RAID 组中所有磁盘驱动器上的技术。它没有防止磁盘失败的保障。([引文][3])
|
||||
> * RAID 1:一种流行的磁盘子系统,通过在两个驱动器上写入相同的数据来提高安全性。 RAID 1 被称为*镜像*,它不会提高写入性能,但读取性能可能会提高到每个磁盘性能的总和。另外,如果一个驱动器发生故障,则使用第二个驱动器,发生故障的驱动器要手动更换。更换后,RAID 控制器将可工作的驱动器的内容复制到新驱动器上。
|
||||
> * RAID 5:一种磁盘子系统,可通过计算奇偶校验数据来提高安全性和提高速度。RAID 5 通过跨三个或更多驱动器交错数据(条带化)来实现此目的。在单个驱动器发生故障时,后续读取可以从分布式奇偶校验计算出,从而不会丢失任何数据。
|
||||
> * RAID 6:通过添加另一个奇偶校验块来扩展 RAID 5。此级别至少需要四个磁盘,并且可以在任何两个并发磁盘故障的情况下继续执行读/写操作。RAID 6 不会对读取操作造成性能损失,但由于与奇偶校验计算相关的开销,因此确实会对写入操作造成性能损失。
|
||||
> * RAID 10:RAID 10 也称为 RAID 1 + 0,它结合了磁盘镜像和磁盘条带化功能来保护数据。它至少需要四个磁盘,并且跨镜像对对数据进行条带化。只要每个镜像对中的一个磁盘起作用,就可以检索数据。如果同一镜像对中的两个磁盘发生故障,则所有数据将丢失,因为带区集中没有奇偶校验。([引文][4])
|
||||
|
||||
7、`ping` 命令使用哪个端口?
|
||||
|
||||
> `ping` 命令使用 ICMP。具体来说,它使用 ICMP 回显请求和 ICMP 回显应答包。
|
||||
>
|
||||
> ICMP 不使用 UDP 或 TCP 通信服务:相反,它使用原始的 IP 通信服务。这意味着,ICMP 消息直接承载在 IP 数据报数据字段中。
|
||||
|
||||
8、路由器和网关之间有什么区别? 什么是默认网关?
|
||||
|
||||
> *路由器*描述的是一种通用技术功能(第 3 层转发)或用于该目的的硬件设备,而*网关*描述的是本地网段的功能(提供到其他地方的连接性)。你还可以说“将路由器设置为网关”。另一个术语是“跳”,它描述了子网之间的转发。
|
||||
>
|
||||
>术语*默认网关*表示局域网上的路由器,它的责任是作为向局域网外部计算机通信的第一个联系点。
|
||||
|
||||
9、解释一下 Linux 的引导过程。
|
||||
|
||||
> BIOS -> 主引导记录(MBR) -> GRUB -> 内核 -> 初始化 -> 运行级
|
||||
|
||||
10、服务器启动时如何检查错误消息?
|
||||
|
||||
> 内核消息始终存储在 kmsg 缓冲区中,可通过 `dmesg` 命令查看。
|
||||
>
|
||||
> 引导的问题和错误要求系统管理员结合某些特定命令来查看某些重要文件,这些文件不同版本的 Linux 处理不同:
|
||||
>
|
||||
> * `/var/log/boot.log` 是系统引导日志,其中包含系统引导过程中展开的所有内容。
|
||||
> * `/var/log/messages` 存储全局系统消息,包括系统引导期间记录的消息。
|
||||
> * `/var/log/dmesg` 包含内核环形缓冲区信息。
|
||||
|
||||
11、符号链接和硬链接有什么区别?
|
||||
|
||||
> *符号链接*或*软链接*实际是是到原始文件的链接,而*硬链接*是原始文件的镜像副本。如果删除原始文件,则该软链接就没有用了,因为它指向的文件不存在了。如果是硬链接,则完全相反。如果删除原始文件,则硬链接仍然包含原始文件中的数据。([引文][5])
|
||||
|
||||
12、如何更改内核参数?你可能需要调整哪些内核选项?
|
||||
|
||||
> 要在类 Unix 系统中设置内核参数,请首先编辑文件 `/etc/sysctl.conf`。进行更改后,保存文件并运行 `sysctl -p` 命令。此命令使更改永久生效,而无需重新启动计算机
|
||||
|
||||
13、解释一下 `/proc` 文件系统。
|
||||
|
||||
> `/proc` 文件系统是虚拟的,并提供有关内核、硬件和正在运行的进程的详细信息。由于 `/proc` 包含虚拟文件,因此称为“虚拟文件系统”。这些虚拟文件具有独特性。其中大多数列为零字节。
|
||||
>
|
||||
> 虚拟文件,例如 `/proc/interrupts`、`/proc/meminfo`、`/proc/mounts` 和 `/proc/partitions`,提供了系统硬件的最新信息。其他诸如 `/proc/filesystems` 和 `/proc/sys` 目录提供系统配置信息和接口。
|
||||
|
||||
14、如何在没有密码的情况下以其他用户身份运行脚本?
|
||||
|
||||
> 例如,如果你可以编辑 sudoers 文件(例如 `/private/etc/sudoers`),则可以使用 `visudo` 添加以下[内容][2]:
|
||||
>
|
||||
> `user1 ALL =(user2)NOPASSWD:/opt/scripts/bin/generate.sh`
|
||||
>
|
||||
|
||||
15、什么是 UID 0 toor 帐户?是被入侵了么?
|
||||
|
||||
> `toor` 用户是备用的超级用户帐户,其中 `toor` 是 `root` 反向拼写。它预期与非标准 shell 一起使用,因此 `root` 的默认 shell 不需要更改。
|
||||
>
|
||||
> 此用途很重要。这些 shell 不是基本发行版的一部分,而是从 ports 或软件包安装的,它们安装在 `/usr/local/bin` 中,默认情况下,位于其他文件系统上。如果 root 的 shell 位于 `/usr/local/bin` 中并且未挂载包含 `/usr/local/bin` 的文件系统,则 root 无法登录以解决问题,并且系统管理员必须重新启动进入为单用户模式来输入 shell 程序的路径。
|
||||
|
||||
### 小目标?
|
||||
|
||||
这是你可能会遇到的甚至更困难的问题:
|
||||
|
||||
16、`tracert` 如何工作,使用什么协议?
|
||||
|
||||
> 命令 `tracert`(或 `traceroute`,具体取决于操作系统)使你可以准确地看到在连接到最终目的地的连接链条中触及的路由器。如果你遇到无法连接或无法 `ping` 通最终目的地的问题,则可以使用 `tracert` 来帮助你确定连接链在何处停止。 ([引文][6])
|
||||
>
|
||||
> 通过此信息,你可以联系正确的人;无论是你自己的防火墙、ISP、目的地的 ISP 还是中间的某个位置。 `tracert` 命令像 `ping` 一样使用 ICMP 协议,但也可以使用 TCP 三步握手的第一步来发送 SYN 请求以进行响应。
|
||||
|
||||
17、使用 `chroot` 的主要优点是什么?我们何时以及为什么使用它?在 chroot 环境中,`mount /dev`、`mount /proc` 和 `mount /sys` 命令的作用是什么?
|
||||
|
||||
> chroot 环境的优点是文件系统与物理主机是隔离的,因为 chroot 在文件系统内部有一个单独的文件系统。区别在于 `chroot` 使用新创建的根目录(`/`)作为其根目录。
|
||||
>
|
||||
> chroot 监狱可让你将进程及其子进程与系统其余部分隔离。它仅应用于不以 root 身份运行的进程,因为 root 用户可以轻松地脱离监狱。
|
||||
>
|
||||
> 该思路是创建一个目录树,在其中复制或链接运行该进程所需的所有系统文件。然后,你可以使用 `chroot()` 系统调用来告诉它根目录现在位于此新树的基点上,然后启动在该 chroot 环境中运行的进程。由于该命令因此而无法引用修改后的根目录之外的路径,因此它无法在这些位置上恶意执行操作(读取、写入等)。([引文][7])
|
||||
|
||||
18、如何保护你的系统免遭黑客攻击?
|
||||
|
||||
> 遵循最低特权原则和这些做法:
|
||||
>
|
||||
> * 使用公钥加密,它可提供出色的安全性。
|
||||
> * 增强密码复杂性。
|
||||
> * 了解为什么要对上述规则设置例外。
|
||||
> * 定期检查你的例外情况。
|
||||
> * 让具体的人对失败负责。(它使你保持警惕。)([引文][8])
|
||||
|
||||
19、什么是 LVM,使用 LVM 有什么好处?
|
||||
|
||||
> LVM(逻辑卷管理)使用一种存储设备管理技术,该技术使用户能够合并和抽象化组件存储设备的物理布局,从而可以更轻松、灵活地进行管理。使用设备映射器 Linux 内核框架,当前迭代(LVM2)可用于将现有存储设备收集到组中,并根据需要从组合的空间分配逻辑单元。
|
||||
|
||||
20、什么是粘性端口?
|
||||
|
||||
> 粘性端口是网络管理员最好的朋友,也是最头痛的事情之一。它们允许你设置网络,以便通过将交换机上的每个端口锁定到特定的 MAC 地址,仅允许一台(或你指定的数字)计算机在该端口上进行连接。
|
||||
|
||||
21、解释一下端口转发?
|
||||
|
||||
> 尝试与安全的网络内部的系统进行通信时,从外部进行通信可能非常困难,这是很显然的。因此,在路由器本身或其他连接管理设备中使用端口转发表可以使特定流量自动转发到特定目的地。例如,如果你的网络上运行着一台 Web 服务器,并且想从外部授予对该服务器的访问权限,则可以将端口转发设置为该服务器上的端口 80。这意味着在网络浏览器中输入你的(外网)IP 地址的任何人都将立即连接到服务器的网站。
|
||||
>
|
||||
> 请注意,通常不建议允许从你的网络外部直接访问服务器。
|
||||
|
||||
22、对于 IDS,误报和漏报是什么?
|
||||
|
||||
> 当入侵检测系统(IDS)设备为实际上没有发生的入侵生成警报时,这是<ruby>误报(假阳性)<rt>false positive</rt></ruby>。如果设备未生成任何警报,而入侵实际上已发生,则为<ruby>漏报(假阴性)</rt></ruby>。
|
||||
|
||||
23、解释一下 `:(){ :|:& };:`,如果已经登录系统,如何停止此代码?
|
||||
|
||||
> 这是一枚复刻炸弹。它分解如下:
|
||||
>
|
||||
> * `:()` 定义了函数,以 `:` 作为函数名,并且空括号表示它将不接受任何参数。
|
||||
> * `{}` 是函数定义的开始和结束。
|
||||
> * `:|:` 将函数 `:` 的副本加载到内存中,并将其输出通过管道传递给函数 `:` 的另一个副本,该副本也必须加载到内存中。
|
||||
> * `&` 使前一个命令行成为后台进程,因此即使父进程被自动杀死,子进程也不会被杀死。
|
||||
> * `:` 再次执行该函数,因此连锁反应开始。
|
||||
>
|
||||
> 保护多用户系统的最佳方法是使用特权访问管理(PAM)来限制用户可以使用的进程数。
|
||||
>
|
||||
> 复刻炸弹的最大问题是它发起了太多进程。因此,如果你已经登录系统,我们有两种尝试解决此问题的方法。一种选择是执行一个 `SIGSTOP` 命令来停止进程,例如:
|
||||
>
|
||||
> `killall -STOP -u user1`
|
||||
>
|
||||
> 如果由于占用了所有进程而无法使用命令行,则必须使用 `exec` 强制其运行:
|
||||
>
|
||||
> `exec killall -STOP -u user1`
|
||||
>
|
||||
> 对于复刻炸弹,最好的选择是防患于未然。
|
||||
|
||||
24、什么是 OOM 杀手,它如何决定首先杀死哪个进程?
|
||||
|
||||
> 如果内存被进程彻底耗尽,可能会威胁到系统的稳定性,那么<ruby>内存不足<rt>out of memory</rt></ruby>(OOM)杀手就登场了。
|
||||
>
|
||||
> OOM 杀手首先必须选择要杀死的最佳进程。*最佳*在这里指的是在被杀死时将释放最大内存的进程,并且对系统来说最不重要。主要目标是杀死最少数量的进程,以最大程度地减少造成的损害,同时最大化释放的内存量。
|
||||
>
|
||||
> 为了实现此目标,内核为每个进程维护一个 `oom_score`。你可以在 `/proc` 文件系统中的 `pid` 目录下的看到每个进程的 `oom_score`:
|
||||
>
|
||||
> `$ cat /proc/10292/oom_score`
|
||||
>
|
||||
> 任何进程的 `oom_score` 值越高,在内存不足的情况下被 OOM 杀手杀死的可能性就越高。 ([引文][9])
|
||||
|
||||
### 总结
|
||||
|
||||
系统管理人员的薪水[差别很大][10],有些网站上说年薪在 70,000 到 100,000 美元之间,具体取决于地点、组织的规模以及你的教育水平以及多年的工作经验。最后,系统管理的职业道路归结为你对使用服务器和解决那些酷问题的兴趣。现在,我要说,继续前进,实现你的梦想之路吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/7/sysadmin-job-interview-questions
|
||||
|
||||
作者:[DirectedSoul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/directedsoul
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/OSDC_HowToFish_520x292.png?itok=DHbdxv6H (Question and answer.)
|
||||
[2]: https://github.com/trimstray/test-your-sysadmin-skills
|
||||
[3]: https://www.waytoeasylearn.com/2016/05/netapp-filer-tutorial.html
|
||||
[4]: https://searchstorage.techtarget.com/definition/RAID-10-redundant-array-of-independent-disks
|
||||
[5]: https://www.answers.com/Q/What_is_hard_link_and_soft_link_in_Linux
|
||||
[6]: https://www.wisdomjobs.com/e-university/network-administrator-interview-questions.html
|
||||
[7]: https://unix.stackexchange.com/questions/105/chroot-jail-what-is-it-and-how-do-i-use-it
|
||||
[8]: https://serverfault.com/questions/391370/how-to-prevent-zero-day-attacks
|
||||
[9]: https://unix.stackexchange.com/a/153586/8369
|
||||
[10]: https://blog.netwrix.com/2018/07/23/systems-administrator-salary-in-2018-how-much-can-you-earn/
|
124
translated/tech/20191209 Counting down the days using bash.md
Normal file
124
translated/tech/20191209 Counting down the days using bash.md
Normal file
@ -0,0 +1,124 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Counting down the days using bash)
|
||||
[#]: via: (https://www.networkworld.com/article/3487712/counting-down-the-days-using-bash.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
用 bash 倒计时
|
||||
======
|
||||
需要知道重要事件发生前有多少天吗?让 Linux bash 和 date 命令可以帮助你!
|
||||
|
||||
随着即将来临的重要假期,你可能需要提醒你还要准备多久。
|
||||
|
||||
幸运的是,你可以从 **date** 命令获得很多帮助。在本篇中,我们将研究 **date** 和 bash 脚本如何告诉你从今天到你预期的事件之间有多少天。
|
||||
|
||||
首先,有几个提示如何进行。**date** 命令的 **%j** 选项将以 1 至 366 之间的数字显示当前日期。如你所想的一样,1 月 1 日将显示为 1,12 月 31 日将显示为 365 或 366,这取决于是否是闰年。继续尝试。你应该会看到以下内容:
|
||||
|
||||
```
|
||||
$ date +%j
|
||||
339
|
||||
```
|
||||
|
||||
但是,你可以通过以下方式,在 **date** 命令中得到一年中_任何_一天的数字:
|
||||
|
||||
```
|
||||
$ date -d "Mar 18" +%j
|
||||
077
|
||||
```
|
||||
|
||||
要记住的是,即使该日期是过去的日期,此命令也会向你显示_当年_的日期。但是,你可以在命令中添加年来修复该问题:
|
||||
|
||||
```
|
||||
$ date -d "Apr 29" +%j
|
||||
119
|
||||
$ date -d "Apr 29 2020" +%j
|
||||
120
|
||||
```
|
||||
|
||||
在闰年中,4 月 29 日将是一年的 120 天,而不是 119 天。
|
||||
|
||||
如果你想倒数圣诞节之前的日子并且不想在挂历上留下指纹,你可以使用以下脚本:
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
XMAS=`date -d "Dec 25" +%j`
|
||||
TODAY=`date +%j`
|
||||
DAYS=$(($XMAS - $TODAY))
|
||||
|
||||
case $DAYS in
|
||||
0) echo "It's today! Merry Christmas!";;
|
||||
[0-9]*) echo "$DAYS days remaining";;
|
||||
-[0-9]*) echo "Oops, you missed it";;
|
||||
esac
|
||||
```
|
||||
|
||||
在此脚本中,我们获取 12 月 25 日和今天的日期,然后相减。如果结果是正数,我们将显示剩余天数。如果为零,则发出 “Merry Christmas” 的消息,如果为负,那么仅告诉运行脚本的人他们错过了假期。也许他们沉迷在蛋酒中了。
|
||||
|
||||
case 语句由可打印的语句组成,剩余时间等于 0,或任意数字或以 **-** 符号开头的数字(也就是过去)。
|
||||
|
||||
对于人们想要关注的任何日期,都可以使用相同方法。实际上,我们可以要求运行脚本的人员提供日期,然后让他们知道从现在到那天还有多少天。这个脚本是这样的。
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
echo -n "Enter event date (e.g., June 6): "
|
||||
read dt
|
||||
EVENT=`date -d "$dt" +%j`
|
||||
TODAY=`date +%j`
|
||||
DAYS=`expr $EVENT - $TODAY`
|
||||
|
||||
case $DAYS in
|
||||
0) echo "It's today!";;
|
||||
[0-9]*) echo "$DAYS days remaining";;
|
||||
-[0-9]*) echo "Oops, you missed it";;
|
||||
esac
|
||||
```
|
||||
|
||||
使用此脚本会遇到的一个问题,如果运行该脚本的人希望知道到第二年这个特殊日子还有多少天,他们会感到失望。即使他们输入日期时提供了年,date -d 命令仍将仅提供金年中的天数,而不会提供从现在到那时的天数。
|
||||
|
||||
计算从今天到某年的日期之间的天数可能有些棘手。你需要包括所有中间年份,并注意那些闰年。
|
||||
|
||||
### 使用 Unix(Epoch)时间
|
||||
|
||||
计算从现在到某个特殊日期之间的天数的另一种方法是利用 Unix 系统存储日期的方法。如果将自 1970 年 1 月 1 日开始的秒数转换为天数,那么就可以很容易地执行此操作,如下脚本所示:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
echo -n "Enter target date (e.g., Mar 18 2021)> "
|
||||
read target_date
|
||||
today=`echo $(($(date --utc --date "$1" +%s)/86400))`
|
||||
target=`echo $(($(date --utc --date "$target_date" +%s)/86400))`
|
||||
days=`expr $target - $today`
|
||||
echo "$days days until $target_date"
|
||||
```
|
||||
|
||||
解释一下,86400 是一天中的秒数。将自纪元开始以来的秒数除该数即为天数。
|
||||
|
||||
```
|
||||
$ ./countdown
|
||||
Enter target date (e.g., Mar 18 2021)> Mar 18 2020
|
||||
104 days until Mar 18 2020
|
||||
```
|
||||
|
||||
加入 [Facebook][3] 和 [LinkedIn][4] 上的 Network World 社区,评论热门主题。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3487712/counting-down-the-days-using-bash.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[3]: https://www.facebook.com/NetworkWorld/
|
||||
[4]: https://www.linkedin.com/company/network-world
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (lxbwolf)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
@ -7,43 +7,17 @@
|
||||
[#]: via: (https://www.2daygeek.com/how-to-find-high-cpu-consumption-processes-in-linux/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How to Find High CPU Consumption Processes in Linux
|
||||
Linux 中怎么找出 CPU 占用高的进程
|
||||
======
|
||||
|
||||
We have already described in our previous article **[how to find high memory consumption processes in Linux][1]**.
|
||||
在之前的文章中我们已经讨论过 [Linux 中怎么找出消耗内存高的进程][1] 。你可能也会遇到在 Linux 系统中找出 CPU 占用高的进程的情形。如果是这样,那么你需要列出系统中 CPU 占用高的进程的列表来确定。我认为只有两种方法能实现:使用 [top 命令][2] 和 [ps 命令][3]。出于一些理由,我更倾向于用 top 命令而不是 ps 命令。但是两个工具都能达到你要的目的,所以你可以根据需求决定使用哪个。这两个工具都被 Linux 系统管理员广泛使用。
|
||||
|
||||
There are situations where you might see more CPU usage on a Linux system.
|
||||
### 1) 怎样使用 top 命令找出 Linux 中 CPU 占用高的进程
|
||||
|
||||
If so, you should identify a list of processes that consume more CPU on the system.
|
||||
|
||||
I believe there are only two ways for you to check this.
|
||||
|
||||
This can be done using the **[top command][2]** and the **[ps command][3]**.
|
||||
|
||||
I’d like to go with the top command for most reasons instead of ps.
|
||||
|
||||
But both will give you the same results, so you can choose the one you like.
|
||||
|
||||
Both of these options are widely used by Linux administrators.
|
||||
|
||||
### 1) How to Find High CPU Consumption Process in Linux Using the top Command
|
||||
|
||||
The Linux top command is the best and most well known command that everyone uses to monitor Linux system performance.
|
||||
|
||||
The top command provides a dynamic real-time view of the running process on a Linux system.
|
||||
|
||||
It display system summary information, the list of processes currently being managed by the Linux kernel.
|
||||
|
||||
It displays various system information such as CPU usage, Memory usage, Swap Memory, Number of running processes, system uptime, system load, Buffer Size, Cache Size, Process PID, etc.
|
||||
|
||||
By default, it sorts the top output with the CPU usage and updates the top command data every 5 seconds.
|
||||
|
||||
If you want to see a clear view of the top command output for further analysis, this is a best way to **[run the top command in the batch mode][4]**.
|
||||
|
||||
Also, you need to **[understand the top command output][5]** to fix the performance problem on the system.
|
||||
在所有监控 Linux 系统性能的工具中,Linux 的 top 命令是最好的也是最知名的。top 命令提供了 Linux 系统运行中的进程的动态实时视图。它能显示系统的概览信息,和 Linux 内核当前管理的进程列表。它显示了大量的系统信息,如 CPU 使用,内存使用,交换内存,运行的进程数,目前系统开机时间,系统负载,缓冲区大小,缓存大小,进程 PID等等。默认情况下,top 命令的输出结果按 CPU 占用进行排序,每 5 秒中更新一次结果。如果你想要一个更清晰的视图来更深入的分析结果,[以批次档模式运行 top 命令][4] 是最好的方法。同时,你需要 [理解 top 命令输出结果的含义][5] ,这样才能解决系统的性能问题。
|
||||
|
||||
```
|
||||
# top -c -b | head -50
|
||||
# top -b | head -50
|
||||
|
||||
top - 00:19:17 up 14:23, 1 user, load average: 2.46, 2.18, 1.97
|
||||
Tasks: 306 total, 1 running, 305 sleeping, 0 stopped, 0 zombie
|
||||
@ -71,30 +45,30 @@ PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||
3286 daygeek 20 3089736 404088 184968 S 1.0 2.5 41:57.44 Web Content
|
||||
```
|
||||
|
||||
Details of the above command:
|
||||
上面的命令的各部分解释:
|
||||
|
||||
* **top :** This is a command.
|
||||
* **-b :** Batch mode.
|
||||
* **head -50:** Display first 50 lines in the output.
|
||||
* **PID :** Unique ID of the process.
|
||||
* **USER :** Owner of the process.
|
||||
* **PR :** priority of the process.
|
||||
* **NI :** The NICE value of the process.
|
||||
* **VIRT :** How much virtual memory used by the process.
|
||||
* **RES :** How much physical memory used by the process.
|
||||
* **SHR :** How much shared memory used by the process.
|
||||
* **S :** This indicates the status of the process: S=sleep R=running Z=zombie.
|
||||
* **%CPU :** The percentage of CPU used by the process.
|
||||
* **%MEM :** The percentage of RAM used by the process.
|
||||
* **TIME+ :** How long the process being running.
|
||||
* **COMMAND :** Name of the process.
|
||||
* **top :** 命令
|
||||
* **-b :** 批次档模式
|
||||
* **head -50:** 显示输出结果的前 50 个
|
||||
* **PID :** 进程的 ID
|
||||
* **USER :** 进程的归属者
|
||||
* **PR :** 进程的等级
|
||||
* **NI :** 进程的 NICE 值
|
||||
* **VIRT :** 进程使用的虚拟内存
|
||||
* **RES :** 进程使用的物理内存
|
||||
* **SHR :** 进程使用的共享内存
|
||||
* **S :** 这个值表示进程的状态: S=睡眠 R=运行 Z=僵尸进程
|
||||
* **%CPU :** 进程占用的 CPU 比例
|
||||
* **%MEM :** 进程使用的 RAM 比例
|
||||
* **TIME+ :** 进程运行了多长时间
|
||||
* **COMMAND :** 进程名字
|
||||
|
||||
|
||||
|
||||
If you want to see the full path of the command instead of the command name, run the following top command format.
|
||||
如果你想看命令的完整路径而不是命令名字,以运行下面的格式 top 命令:
|
||||
|
||||
```
|
||||
# top -b | head -50
|
||||
# top -c -b | head -50
|
||||
|
||||
top - 00:28:49 up 14:33, 1 user, load average: 2.43, 2.49, 2.23
|
||||
Tasks: 305 total, 1 running, 304 sleeping, 0 stopped, 0 zombie
|
||||
@ -123,11 +97,9 @@ PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||
2179 daygeek 20 2945348 429644 172940 S 1.0 2.6 15:20.90 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -prefsLen 7821 -prefMapSize 213431 -parentBuildID 20191031132559 -greomni /us+
|
||||
```
|
||||
|
||||
### 2) How to Find High CPU Consumption Process in Linux Using the ps Command
|
||||
### 2) 怎样使用 ps 命令找出 Linux 中 CPU 占用高的进程
|
||||
|
||||
ps stands for processes status, it display the information about the active/running processes on the system.
|
||||
|
||||
It provides a snapshot of the current processes along with detailed information like username, user id, cpu usage, memory usage, process start date and time command name etc.
|
||||
ps 是 `process status`(进程状态)的缩写,它能显示系统中活跃的/运行中的进程的信息。它提供了当前进程及其详细信息,诸如用户名、用户 ID、CPU 使用率、内存使用、进程启动日期时间、命令名等等的快照。
|
||||
|
||||
```
|
||||
# ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%cpu | head
|
||||
@ -144,22 +116,22 @@ It provides a snapshot of the current processes along with detailed information
|
||||
2179 1714 2.7 1.8 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -prefsLen 7821 -prefMapSize 213431 -parentBuildID 20191031132559 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1714 true tab
|
||||
```
|
||||
|
||||
Details of the above command:
|
||||
上面的命令的各部分解释:
|
||||
|
||||
* **ps :** This is a command.
|
||||
* **-e :** Select all processes.
|
||||
* **-o :** To customize a output format.
|
||||
* **–sort=-%cpu :** Sort the ouput based on CPU usage.
|
||||
* **head :** To display first 10 lines of the output
|
||||
* **PID :** Unique ID of the process.
|
||||
* **PPID :** Unique ID of the parent process.
|
||||
* **%MEM :** The percentage of RAM used by the process.
|
||||
* **%CPU :** The percentage of CPU used by the process.
|
||||
* **Command :** Name of the process.
|
||||
* **ps :** 命令名字
|
||||
* **-e :** 选择所有进程
|
||||
* **-o :** 自定义输出格式
|
||||
* **–sort=-%cpu :** 基于 CPU 使用率对输出结果排序
|
||||
* **head :** 显示结果的前 10 行
|
||||
* **PID :** 进程的 ID
|
||||
* **PPID :** 父进程的 ID
|
||||
* **%MEM :** 进程使用的 RAM 比例
|
||||
* **%CPU :** 进程占用的 CPU 比例
|
||||
* **Command :** 进程名字
|
||||
|
||||
|
||||
|
||||
If you only want to see the command name instead of the absolute path of the command, use the ps command format below.
|
||||
如果你只想看命令名字而不是命令的绝对路径,以运行下面的格式 ps 命令:
|
||||
|
||||
```
|
||||
# ps -eo pid,ppid,%mem,%cpu,comm --sort=-%cpu | head
|
||||
@ -182,7 +154,7 @@ via: https://www.2daygeek.com/how-to-find-high-cpu-consumption-processes-in-linu
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[lxbwolf](https://github.com/lxbwolf)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user