Linux command-line tips

Source: Internet
Author: User
Tags curl

1. Back up the/etc directory to the current directory, the file name of the backup files is named after the source directory name and the time date on the server
[Email protected] ~]# tar CFZ etc- date +%x\(%H-%M-%S\). tar.gz/etc
[Email protected] ~]# tar cfz etc_$ (date +%f (%h-%m-%s)). tar.gz/etc
2. Display the last modified time of the file
[Email protected] ~]# date-r FILENAME +%f (%h-%m-%s)
[[email protected] ~]# echo ' Last Modification time: ' date -r FILENAME +%F\(%H-%M-%S\)
[Email protected] ~]# echo ' The Last modification time is: ' date -r FILENAME +%Z,%F,%P\:\(%H-%M-%S\)
[Email protected] ~]# echo ' The Last modification time is: '; Date-r FILENAME +%z,%f,%p\:(%h-%m-%s)
3. Displays a file that was last modified in the current directory
[Email protected] ~]# LS-LRT | Tail-1
[Email protected] ~]# echo-e "The Last File modified was:\033[1m$ (ls-t | head-1) \033[0m "
#取出当前目录下最近一次被修改的文件名

[Email protected] ~]# name= ls -rt | tail -1
#   [[email protected] ~]# echo $name

4. View the current operating level of the system
[Email protected] ~]# Who-r | awk ' {print $1,$2} '
[Email protected] ~]# echo-e "\033[1m$ (Who-r | awk ' {print $1,$2} ') \033[0m "
5. Export the man manual page content to a file
[[email protected] ~]# Man COMMAND | Col-b > FILENAME
6. Do not allow overwriting of existing regular files via redirected output
[Email protected] ~]# set-c
#只对当前的shell有效
7. Test whether the command was executed successfully
[[email protected] ~]# COMMAND && [$? = 0] && echo-e "\033[1;32m ok \033[0m" | | echo-e "\033[5;31M ER ROR \033[0m "
[[email protected] ~]# COMMAND && [$-eq 0] && echo-e "\033[1;32m ok \033[0m" | | echo-e "\033[5;31M E Rror \033[0m "
8. Switch back and forth between the last working directory and the current directory
[Email protected] ~]# CD-
9. Sequential and identical commands are not recorded in the history command
[Email protected] ~]# export histcontrol=ignoredups
10. View Public IP
[Email protected] ~]# Curl ifconfig.me
[Email protected] ~]# Curl Members.3322.org/dyndns/getip
[Email protected] ~]# Curl cip.cc

Linux command-line tips

Contact Us

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

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

A Free Trial That Lets You Build Big!

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

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

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