mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
20150911-2 选题,这两篇有一个第一篇,是今年三月份的,文件名写在说明中了
第一篇的文件名:20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md
This commit is contained in:
parent
3fdea4dc7d
commit
93c32f1b55
@ -0,0 +1,250 @@
|
||||
10 Useful Linux Command Line Tricks for Newbies – Part 2
|
||||
================================================================================
|
||||
I remember when I first started using Linux and I was used to the graphical interface of Windows, I truly hated the Linux terminal. Back then I was finding the commands hard to remember and proper use of each one of them. With time I realised the beauty, flexibility and usability of the Linux terminal and to be honest a day doesn’t pass without using. Today, I would like to share some useful tricks and tips for Linux new comers to ease their transition to Linux or simply help them learn something new (hopefully).
|
||||
|
||||
![10 Linux Commandline Tricks for Newbies](http://www.tecmint.com/wp-content/uploads/2015/09/10-Linux-Commandline-Tricks.jpg)
|
||||
|
||||
10 Linux Commandline Tricks – Part 2
|
||||
|
||||
- [5 Interesting Command Line Tips and Tricks in Linux – Part 1][1]
|
||||
- [5 Useful Commands to Manage Linux File Types – Part 3][2]
|
||||
|
||||
This article intends to show you some useful tricks how to use the Linux terminal like a pro with minimum amount of skills. All you need is a Linux terminal and some free time to test these commands.
|
||||
|
||||
### 1. Find the right command ###
|
||||
|
||||
Executing the right command can be vital for your system. However in Linux there are so many different command lines that they are often hard to remember. So how do you search for the right command you need? The answer is apropos. All you need to run is:
|
||||
|
||||
# apropos <description>
|
||||
|
||||
Where you should change the “description” with the actual description of the command you are looking for. Here is a good example:
|
||||
|
||||
# apropos "list directory"
|
||||
|
||||
dir (1) - list directory contents
|
||||
ls (1) - list directory contents
|
||||
ntfsls (8) - list directory contents on an NTFS filesystem
|
||||
vdir (1) - list directory contents
|
||||
|
||||
On the left you can see the commands and on the right their description.
|
||||
|
||||
### 2. Execute Previous Command ###
|
||||
|
||||
Many times you will need to execute the same command over and over again. While you can repeatedly press the Up key on your keyboard, you can use the history command instead. This command will list all commands you entered since you launched the terminal:
|
||||
|
||||
# history
|
||||
|
||||
1 fdisk -l
|
||||
2 apt-get install gnome-paint
|
||||
3 hostname tecmint.com
|
||||
4 hostnamectl tecmint.com
|
||||
5 man hostnamectl
|
||||
6 hostnamectl --set-hostname tecmint.com
|
||||
7 hostnamectl -set-hostname tecmint.com
|
||||
8 hostnamectl set-hostname tecmint.com
|
||||
9 mount -t "ntfs" -o
|
||||
10 fdisk -l
|
||||
11 mount -t ntfs-3g /dev/sda5 /mnt
|
||||
12 mount -t rw ntfs-3g /dev/sda5 /mnt
|
||||
13 mount -t -rw ntfs-3g /dev/sda5 /mnt
|
||||
14 mount -t ntfs-3g /dev/sda5 /mnt
|
||||
15 mount man
|
||||
16 man mount
|
||||
17 mount -t -o ntfs-3g /dev/sda5 /mnt
|
||||
18 mount -o ntfs-3g /dev/sda5 /mnt
|
||||
19 mount -ro ntfs-3g /dev/sda5 /mnt
|
||||
20 cd /mnt
|
||||
...
|
||||
|
||||
As you will see from the output above, you will receive a list of all commands that you have ran. On each line you have number indicating the row in which you have entered the command. You can recall that command by using:
|
||||
|
||||
!#
|
||||
|
||||
Where # should be changed with the actual number of the command. For better understanding, see the below example:
|
||||
|
||||
!501
|
||||
|
||||
Is equivalent to:
|
||||
|
||||
# history
|
||||
|
||||
### 3. Use midnight Commander ###
|
||||
|
||||
If you are not used to using commands such cd, cp, mv, rm than you can use the midnight command. It is an easy to use visual shell in which you can also use mouse:
|
||||
|
||||
![Midnight Commander in Action](http://www.tecmint.com/wp-content/uploads/2015/09/mc-command.jpg)
|
||||
|
||||
Midnight Commander in Action
|
||||
|
||||
Thanks to the F1 – F12 keys, you can easy perform different tasks. Simply check the legend at the bottom. To select a file or folder click the “Insert” button.
|
||||
|
||||
In short the midnight command is called “mc“. To install mc on your system simply run:
|
||||
|
||||
$ sudo apt-get install mc [On Debian based systems]
|
||||
|
||||
----------
|
||||
|
||||
# yum install mc [On Fedora based systems]
|
||||
|
||||
Here is a simple example of using midnight commander. Open mc by simply typing:
|
||||
|
||||
# mc
|
||||
|
||||
Now use the TAB button to switch between windows – left and right. I have a LibreOffice file that I will move to “Software” folder:
|
||||
|
||||
![Midnight Commander Move Files](http://www.tecmint.com/wp-content/uploads/2015/09/Midnight-Commander-Move-Files.jpg)
|
||||
|
||||
Midnight Commander Move Files
|
||||
|
||||
To move the file in the new directory press F6 button on your keyboard. MC will now ask you for confirmation:
|
||||
|
||||
![Move Files to New Directory](http://www.tecmint.com/wp-content/uploads/2015/09/Move-Files-to-new-Directory.png)
|
||||
|
||||
Move Files to New Directory
|
||||
|
||||
Once confirmed, the file will be moved in the new destination directory.
|
||||
|
||||
Read More: [How to Use Midnight Commander File Manager in Linux][4]
|
||||
|
||||
### 4. Shutdown Computer at Specific Time ###
|
||||
|
||||
Sometimes you will need to shutdown your computer some hours after your work hours have ended. You can configure your computer to shut down at specific time by using:
|
||||
|
||||
$ sudo shutdown 21:00
|
||||
|
||||
This will tell your computer to shut down at the specific time you have provided. You can also tell the system to shutdown after specific amount of minutes:
|
||||
|
||||
$ sudo shutdown +15
|
||||
|
||||
That way the system will shut down in 15 minutes.
|
||||
|
||||
### 5. Show Information about Known Users ###
|
||||
|
||||
You can use a simple command to list your Linux system users and some basic information about them. Simply use:
|
||||
|
||||
# lslogins
|
||||
|
||||
This should bring you the following output:
|
||||
|
||||
UID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS
|
||||
0 root 0 0 Apr29/11:35 root
|
||||
1 bin 0 1 bin
|
||||
2 daemon 0 1 daemon
|
||||
3 adm 0 1 adm
|
||||
4 lp 0 1 lp
|
||||
5 sync 0 1 sync
|
||||
6 shutdown 0 1 Jul19/10:04 shutdown
|
||||
7 halt 0 1 halt
|
||||
8 mail 0 1 mail
|
||||
10 uucp 0 1 uucp
|
||||
11 operator 0 1 operator
|
||||
12 games 0 1 games
|
||||
13 gopher 0 1 gopher
|
||||
14 ftp 0 1 FTP User
|
||||
23 squid 0 1
|
||||
25 named 0 1 Named
|
||||
27 mysql 0 1 MySQL Server
|
||||
47 mailnull 0 1
|
||||
48 apache 0 1 Apache
|
||||
...
|
||||
|
||||
### 6. Search for Files ###
|
||||
|
||||
Searching for files can sometimes be not as easy as you think. A good example for searching for files is:
|
||||
|
||||
# find /home/user -type f
|
||||
|
||||
This command will search for all files located in /home/user. The find command is extremely powerful one and you can pass more options to it to make your search even more detailed. If you want to search for files larger than given size, you can use:
|
||||
|
||||
# find . -type f -size 10M
|
||||
|
||||
The above command will search from current directory for all files that are larger than 10 MB. Make sure not to run the command from the root directory of your Linux system as this may cause high I/O on your machine.
|
||||
|
||||
One of the most frequently used combinations that I use find with is “exec” option, which basically allows you to run some actions on the results of the find command.
|
||||
|
||||
For example, lets say that we want to find all files in a directory and change their permissions. This can be easily done with:
|
||||
|
||||
# find /home/user/files/ -type f -exec chmod 644 {} \;
|
||||
|
||||
The above command will search for all files in the specified directory recursively and will executed chmod command on the found files. I am sure you will find many more uses on this command in future, for now read [35 Examples of Linux ‘find’ Command and Usage][5].
|
||||
|
||||
### 7. Build Directory Trees with one Command ###
|
||||
|
||||
You probably know that you can create new directories by using the mkdir command. So if you want to create a new folder you will run something like this:
|
||||
|
||||
# mkdir new_folder
|
||||
|
||||
But what, if you want to create 5 subfolders within that folder? Running mkdir 5 times in a row is not a good solution. Instead you can use -p option like that:
|
||||
|
||||
# mkdir -p new_folder/{folder_1,folder_2,folder_3,folder_4,folder_5}
|
||||
|
||||
In the end you should have 5 folders located in new_folder:
|
||||
|
||||
# ls new_folder/
|
||||
|
||||
folder_1 folder_2 folder_3 folder_4 folder_5
|
||||
|
||||
### 8. Copy File into Multiple Directories ###
|
||||
|
||||
File copying is usually performed with the cp command. Copying a file usually looks like this:
|
||||
|
||||
# cp /path-to-file/my_file.txt /path-to-new-directory/
|
||||
|
||||
Now imagine that you need to copy that file in multiple directories:
|
||||
|
||||
# cp /home/user/my_file.txt /home/user/1
|
||||
# cp /home/user/my_file.txt /home/user/2
|
||||
# cp /home/user/my_file.txt /home/user/3
|
||||
|
||||
This is a bit absurd. Instead you can solve the problem with a simple one line command:
|
||||
|
||||
# echo /home/user/1/ /home/user/2/ /home/user/3/ | xargs -n 1 cp /home/user/my_file.txt
|
||||
|
||||
### 9. Deleting Larger Files ###
|
||||
|
||||
Sometimes files can grow extremely large. I have seen cases where a single log file went over 250 GB large due to poor administrating skills. Removing the file with rm utility might not be sufficient in such cases due to the fact that there is extremely large amount of data that needs to be removed. The operation will be a “heavy” one and should be avoided. Instead, you can go with a really simple solution:
|
||||
|
||||
# > /path-to-file/huge_file.log
|
||||
|
||||
Where of course you will need to change the path and the file names with the exact ones to match your case. The above command will simply write an empty output to the file. In more simpler words it will empty the file without causing high I/O on your system.
|
||||
|
||||
### 10. Run Same Command on Multiple Linux Servers ###
|
||||
|
||||
Recently one of our readers asked in our [LinuxSay forum][6], how to execute single command to multiple Linux boxes at once using SSH. He had his machines IP addresses looking like this:
|
||||
|
||||
10.0.0.1
|
||||
10.0.0.2
|
||||
10.0.0.3
|
||||
10.0.0.4
|
||||
10.0.0.5
|
||||
|
||||
So here is a simple solution of this issue. Collect the IP addresses of the servers in a one file called list.txt one under other just as shown above. Then you can run:
|
||||
|
||||
# for in $i(cat list.txt); do ssh user@$i 'bash command'; done
|
||||
|
||||
In the above example you will need to change “user” with the actual user with which you will be logging and “bash command” with the actual bash command you wish to execute. The method is better working when you are [using passwordless authentication with SSH key][7] to your machines as that way you will not need to enter the password for your user over and over again.
|
||||
|
||||
Note that you may need to pass some additional parameters to the SSH command depending on your Linux boxes setup.
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
The above examples are really simple ones and I hope they have helped you to find some of the beauty of Linux and how you can easily perform different operations that can take much more time on other operating systems.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/10-useful-linux-command-line-tricks-for-newbies/
|
||||
|
||||
作者:[Marin Todorov][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/marintodorov89/
|
||||
[1]:http://www.tecmint.com/5-linux-command-line-tricks/
|
||||
[2]:http://www.tecmint.com/manage-file-types-and-set-system-time-in-linux/
|
||||
[3]:http://www.tecmint.com/history-command-examples/
|
||||
[4]:http://www.tecmint.com/midnight-commander-a-console-based-file-manager-for-linux/
|
||||
[5]:http://www.tecmint.com/35-practical-examples-of-linux-find-command/
|
||||
[6]:http://www.linuxsay.com/
|
||||
[7]:http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
|
@ -0,0 +1,279 @@
|
||||
5 Useful Commands to Manage File Types and System Time in Linux – Part 3
|
||||
================================================================================
|
||||
Adapting to using the command line or terminal can be very hard for beginners who want to learn Linux. Because the terminal gives more control over a Linux system than GUIs programs, one has to get a used to running commands on the terminal. Therefore to memorize different commands in Linux, you should use the terminal on a daily basis to understand how commands are used with different options and arguments.
|
||||
|
||||
![Manage File Types and Set Time in Linux](http://www.tecmint.com/wp-content/uploads/2015/09/Find-File-Types-in-Linux.jpg)
|
||||
|
||||
Manage File Types and Set Time in Linux – Part 3
|
||||
|
||||
Please go through our previous parts of this [Linux Tricks][1] series.
|
||||
|
||||
- [5 Interesting Command Line Tips and Tricks in Linux – Part 1][2]
|
||||
- [ Useful Commandline Tricks for Newbies – Part 2][3]
|
||||
|
||||
In this article, we are going to look at some tips and tricks of using 10 commands to work with files and time on the terminal.
|
||||
|
||||
### File Types in Linux ###
|
||||
|
||||
In Linux, everything is considered as a file, your devices, directories and regular files are all considered as files.
|
||||
|
||||
There are different types of files in a Linux system:
|
||||
|
||||
- Regular files which may include commands, documents, music files, movies, images, archives and so on.
|
||||
- Device files: which are used by the system to access your hardware components.
|
||||
|
||||
There are two types of device files block files that represent storage devices such as harddisks, they read data in blocks and character files read data in a character by character manner.
|
||||
|
||||
- Hardlinks and softlinks: they are used to access files from any where on a Linux filesystem.
|
||||
- Named pipes and sockets: allow different processes to communicate with each other.
|
||||
|
||||
#### 1. Determining the type of a file using ‘file’ command ####
|
||||
|
||||
You can determine the type of a file by using the file command as follows. The screenshot below shows different examples of using the file command to determine the types of different files.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ dir
|
||||
BACKUP master.zip
|
||||
crossroads-stable.tar.gz num.txt
|
||||
EDWARD-MAYA-2011-2012-NEW-REMIX.mp3 reggea.xspf
|
||||
Linux-Security-Optimization-Book.gif tmp-link
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file BACKUP/
|
||||
BACKUP/: directory
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file master.zip
|
||||
master.zip: Zip archive data, at least v1.0 to extract
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file crossroads-stable.tar.gz
|
||||
crossroads-stable.tar.gz: gzip compressed data, from Unix, last modified: Tue Apr 5 15:15:20 2011
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file Linux-Security-Optimization-Book.gif
|
||||
Linux-Security-Optimization-Book.gif: GIF image data, version 89a, 200 x 259
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file EDWARD-MAYA-2011-2012-NEW-REMIX.mp3
|
||||
EDWARD-MAYA-2011-2012-NEW-REMIX.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file /dev/sda1
|
||||
/dev/sda1: block special
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ file /dev/tty1
|
||||
/dev/tty1: character special
|
||||
|
||||
#### 2. Determining the file type using ‘ls’ and ‘dir’ commands ####
|
||||
|
||||
Another way of determining the type of a file is by performing a long listing using the ls and [dir][4] commands.
|
||||
|
||||
Using ls -l to determine the type of a file.
|
||||
|
||||
When you view the file permissions, the first character shows the file type and the other charcters show the file permissions.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l
|
||||
total 6908
|
||||
drwxr-xr-x 2 tecmint tecmint 4096 Sep 9 11:46 BACKUP
|
||||
-rw-r--r-- 1 tecmint tecmint 1075620 Sep 9 11:47 crossroads-stable.tar.gz
|
||||
-rwxr----- 1 tecmint tecmint 5916085 Sep 9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3
|
||||
-rw-r--r-- 1 tecmint tecmint 42122 Sep 9 11:49 Linux-Security-Optimization-Book.gif
|
||||
-rw-r--r-- 1 tecmint tecmint 17627 Sep 9 11:46 master.zip
|
||||
-rw-r--r-- 1 tecmint tecmint 5 Sep 9 11:48 num.txt
|
||||
-rw-r--r-- 1 tecmint tecmint 0 Sep 9 11:46 reggea.xspf
|
||||
-rw-r--r-- 1 tecmint tecmint 5 Sep 9 11:47 tmp-link
|
||||
|
||||
Using ls -l to determine block and character files.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l /dev/sda1
|
||||
brw-rw---- 1 root disk 8, 1 Sep 9 10:53 /dev/sda1
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l /dev/tty1
|
||||
crw-rw---- 1 root tty 4, 1 Sep 9 10:54 /dev/tty1
|
||||
|
||||
Using dir -l to determine the type of a file.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ dir -l
|
||||
total 6908
|
||||
drwxr-xr-x 2 tecmint tecmint 4096 Sep 9 11:46 BACKUP
|
||||
-rw-r--r-- 1 tecmint tecmint 1075620 Sep 9 11:47 crossroads-stable.tar.gz
|
||||
-rwxr----- 1 tecmint tecmint 5916085 Sep 9 11:49 EDWARD-MAYA-2011-2012-NEW-REMIX.mp3
|
||||
-rw-r--r-- 1 tecmint tecmint 42122 Sep 9 11:49 Linux-Security-Optimization-Book.gif
|
||||
-rw-r--r-- 1 tecmint tecmint 17627 Sep 9 11:46 master.zip
|
||||
-rw-r--r-- 1 tecmint tecmint 5 Sep 9 11:48 num.txt
|
||||
-rw-r--r-- 1 tecmint tecmint 0 Sep 9 11:46 reggea.xspf
|
||||
-rw-r--r-- 1 tecmint tecmint 5 Sep 9 11:47 tmp-link
|
||||
|
||||
#### 3. Counting number of files of a specific type ####
|
||||
|
||||
Next we shall look at tips on counting number of files of a specific type in a given directory using the ls, [grep][5] and [wc][6] commands. Communication between the commands is achieved through named piping.
|
||||
|
||||
- grep – command to search according to a given pattern or regular expression.
|
||||
- wc – command to count lines, words and characters.
|
||||
|
||||
Counting number of regular files
|
||||
|
||||
In Linux, regular files are represented by the `–` symbol.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l | grep ^- | wc -l
|
||||
7
|
||||
|
||||
**Counting number of directories**
|
||||
|
||||
In Linux, directories are represented by the `d` symbol.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l | grep ^d | wc -l
|
||||
1
|
||||
|
||||
**Counting number of symbolic and hard links**
|
||||
|
||||
In Linux, symblic and hard links are represented by the l symbol.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l | grep ^l | wc -l
|
||||
0
|
||||
|
||||
**Counting number of block and character files**
|
||||
|
||||
In Linux, block and character files are represented by the `b` and `c` symbols respectively.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l /dev | grep ^b | wc -l
|
||||
37
|
||||
tecmint@tecmint ~/Linux-Tricks $ ls -l /dev | grep ^c | wc -l
|
||||
159
|
||||
|
||||
#### 4. Finding files on a Linux system ####
|
||||
|
||||
Next we shall look at some commands one can use to find files on a Linux system, these include the locate, find, whatis and which commands.
|
||||
|
||||
**Using the locate command to find files**
|
||||
|
||||
In the output below, I am trying to locate the [Samba server configuration][7] for my system.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ locate samba.conf
|
||||
/usr/lib/tmpfiles.d/samba.conf
|
||||
/var/lib/dpkg/info/samba.conffiles
|
||||
|
||||
**Using the find command to find files**
|
||||
|
||||
To learn how to use the find command in Linux, you can read our following article that shows more than 30+ practical examples and usage of find command in Linux.
|
||||
|
||||
- [35 Examples of ‘find’ Command in Linux][8]
|
||||
|
||||
**Using the whatis command to locate commands**
|
||||
|
||||
The whatis command is mostly used to locate commands and it is special because it gives information about a command, it also finds configurations files and manual entries for a command.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ whatis bash
|
||||
bash (1) - GNU Bourne-Again SHell
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ whatis find
|
||||
find (1) - search for files in a directory hierarchy
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ whatis ls
|
||||
ls (1) - list directory contents
|
||||
|
||||
**Using which command to locate commands**
|
||||
|
||||
The which command is used to locate commands on the filesystem.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ which mkdir
|
||||
/bin/mkdir
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ which bash
|
||||
/bin/bash
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ which find
|
||||
/usr/bin/find
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ $ which ls
|
||||
/bin/ls
|
||||
|
||||
#### 5. Working with time on your Linux system ####
|
||||
|
||||
When working in a networked environment, it is a good practice to keep the correct time on your Linux system. There are certain services on Linux systems that require correct time to work efficiently on a network.
|
||||
|
||||
We shall look at commands you can use to manage time on your machine. In Linux, time is managed in two ways: system time and hardware time.
|
||||
|
||||
The system time is managed by a system clock and the hardware time is managed by a hardware clock.
|
||||
|
||||
To view your system time, date and timezone, use the date command as follows.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ date
|
||||
Wed Sep 9 12:25:40 IST 2015
|
||||
|
||||
Set your system time using date -s or date –set=”STRING” as follows.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo date -s "12:27:00"
|
||||
Wed Sep 9 12:27:00 IST 2015
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo date --set="12:27:00"
|
||||
Wed Sep 9 12:27:00 IST 2015
|
||||
|
||||
You can also set time and date as follows.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo date 090912302015
|
||||
Wed Sep 9 12:30:00 IST 2015
|
||||
|
||||
Viewing current date from a calendar using cal command.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ cal
|
||||
September 2015
|
||||
Su Mo Tu We Th Fr Sa
|
||||
1 2 3 4 5
|
||||
6 7 8 9 10 11 12
|
||||
13 14 15 16 17 18 19
|
||||
20 21 22 23 24 25 26
|
||||
27 28 29 30
|
||||
|
||||
View hardware clock time using the hwclock command.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo hwclock
|
||||
Wednesday 09 September 2015 06:02:58 PM IST -0.200081 seconds
|
||||
|
||||
To set the hardware clock time, use hwclock –set –date=”STRING” as follows.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo hwclock --set --date="09/09/2015 12:33:00"
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ sudo hwclock
|
||||
Wednesday 09 September 2015 12:33:11 PM IST -0.891163 seconds
|
||||
|
||||
The system time is set by the hardware clock during booting and when the system is shutting down, the hardware time is reset to the system time.
|
||||
|
||||
Therefore when you view system time and hardware time, they are the same unless when you change the system time. Your hardware time may be incorrect when the CMOS battery is weak.
|
||||
|
||||
You can also set your system time using time from the hardware clock as follows.
|
||||
|
||||
$ sudo hwclock --hctosys
|
||||
|
||||
It is also possible to set hardware clock time using the system clock time as follows.
|
||||
|
||||
$ sudo hwclock --systohc
|
||||
|
||||
To view how long your Linux system has been running, use the uptime command.
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ uptime
|
||||
12:36:27 up 1:43, 2 users, load average: 1.39, 1.34, 1.45
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ uptime -p
|
||||
up 1 hour, 43 minutes
|
||||
|
||||
tecmint@tecmint ~/Linux-Tricks $ uptime -s
|
||||
2015-09-09 10:52:47
|
||||
|
||||
### Summary ###
|
||||
|
||||
Understanding file types is Linux is a good practice for begginers, and also managing time is critical especially on servers to manage services reliably and efficiently. Hope you find this guide helpful. If you have any additional information, do not forget to post a comment. Stay connected to Tecmint.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/manage-file-types-and-set-system-time-in-linux/
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/tag/linux-tricks/
|
||||
[2]:http://www.tecmint.com/free-online-linux-learning-guide-for-beginners/
|
||||
[3]:http://www.tecmint.com/10-useful-linux-command-line-tricks-for-newbies/
|
||||
[4]:http://www.tecmint.com/linux-dir-command-usage-with-examples/
|
||||
[5]:http://www.tecmint.com/12-practical-examples-of-linux-grep-command/
|
||||
[6]:http://www.tecmint.com/wc-command-examples/
|
||||
[7]:http://www.tecmint.com/setup-samba-file-sharing-for-linux-windows-clients/
|
||||
[8]:http://www.tecmint.com/35-practical-examples-of-linux-find-command/
|
Loading…
Reference in New Issue
Block a user