`

linux: useful commands

 
阅读更多

start time

1.uptime

16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.00

2. date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"


3. cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}'

Sed

//delete the first six char in every line

sed -i 's/^......//' tokenized-documents

//delete :

sed -i 's/://' tokenized-documents

//delete all spaces

sed -e 's/ //g' tokenized-documents > tokenized-documents.trimspace

//replace [ to \t

sed -i 's/\[/\t/g' tokenized-documents.trimspace

 

 

awk

add line no to file

awk '{ print FNR "\t" $0 }' testfile

 

//split every line in questions file and produce new file named with $1 for every line

//which content is $2

#cat questions | awk -F '\001' '{print $2 > $1}'

//the reverse produce

#awk '{print FILENAME "\t" $0 > "qestions"}' *

http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html

 

 

 

Splite huge file to chunks

#split --lines=1 -d  questions q_

 

remote call shell script

#!/bin/bash
USERNAME=someUser
HOSTS="host1 host2 host3"
SCRIPT="pwd; ls"
for HOSTNAME in ${HOSTS} ; do
    ssh -l ${USERNAME} ${HOSTNAME} "${SCRIPT}"
done

 

compare files in two directories

diff --brief -r dir1/ dir2/
diff -qr dir1/ dir2/

 

find files and copy to somewhere

find . -iname '*.jar' -exec cp {} ./jars \;

 

ZIP

# zip -r archive_name.zip directory_to_compress

# unzip archive_name.zip

 

TAR

# tar -cvf archive_name.tar directory_to_compress

# tar -xvf archive_name.tar.gz

# tar -xvf archive_name.tar -C /tmp/extract_here/

TAR.GZ

# tar -zcvf archive_name.tar.gz directory_to_compress

# tar -zxvf archive_name.tar.gz

# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

TAR.BZ2

# tar -jcvf archive_name.tar.bz2 directory_to_compress

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

 

 

To scrab a picture, use the following command

#gnome-screenshot -i

 

convert dos text format (newlines CR/LF) to linux format

 

#dos2unix  -n sourcefile.text  targetfile.text

http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

 

 

Find strings in files

find . | xargs grep 'string' -sl

find . -iname '*php' | xargs grep 'string' -sl

find . -iname '*php' -mtime -1 | xargs grep 'string' -sl

find . -iname '*php' -mtime +1 | xargs grep 'string' -sl

 

String replace

//replace matched string

sed -i 's/old-word/new-word/g' *.txt

//replace line

sed -i '/nameNode/c\nameNode=hdfs://192.168.122.1:2014' examples/apps/sqoop/job.properties  

//combined with grep
grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

//combined with find

find examples/ -name 'job.properties' |xargs sed -i '/jobTracker/c\jobTracker=192.168.122.1:2015'

 

bash history

Make an entry as follows in .bash_profile to save export command permanently
export HISTTIMEFORMAT='%F %T  '
export HISTIGNORE='ls -l:pwd:date:'
export HISTCONTROL=ignoredups
HISTSIZE=0  //not keep history of commands 
#history -c   //clear history
#history | grep pwd

Search previously executed command with ‘Ctrl+r’ command
Once you’ve found the command you’re looking for, press ‘Enter‘ to execute 
the same else press ‘esc‘ to cancel it.
see:http://www.tecmint.com/history-command-examples/
分享到:
评论

相关推荐

    java8集合源码-Linux-Useful-Commands:Linux-有用的命令

    java8集合源码有用的linux命令 在这里,您将找到 linux 上最常用的命令集。 对于刚接触 linux 操作系统的人来说,这些将是完全有帮助的。 我相信这个片段可以为那些需要在 linux 中创建开发环境以进行 Web 开发的人...

    A Practical Guide to Linux Commands, Editors, and Shell Programming 4th, ed

    The Most Useful Tutorial and Reference, with Hundreds of High-Quality Examples for Every Popular Linux Distribution “First Sobell taught people how to use Linux . . . now he teaches you the power of...

    Linux Administration: A Beginner's Guide, Fifth Edition

    His explanations are clear, patient, accurate, and useful, and they cover all aspects of the system administrator's job. He's careful to explain hundreds of commands in a logical way, including lists...

    linux-commands-cheat-sheet-phoenixnap_linux_console_

    描述中的“useful console list command in Unix”提示了这份资料的重点是Unix系统(包括Linux)中的命令行工具。Unix和Linux系统的命令行界面提供了强大的文本交互式环境,允许用户执行各种任务,如文件管理、进程...

    Linux for Beginners: An Introduction to the Linux Operating System

    The basic Linux commands you'll use most often. Creating, renaming, moving, and deleting directories. Listing, reading, creating, editing, copying, and deleting files. Exactly how permissions work ...

    Practical Guide to Linux Commands, Editors and Shell Programming (2013)

    Practical Guide to Linux Commands, Editors and Shell Programming (2013) “This book is a very useful tool for anyone who wants to ‘look under the hood’ so to speak, and really start putting the ...

    java8集合源码-useful-linux-commands:用于创建Web开发开发环境的Linux命令

    java8集合源码有用的linux命令 在这里,您将找到 linux 上最常用的命令集。 对于刚接触 linux 操作系统的人来说,这些将是完全有帮助的。 我相信这个片段可以为那些需要在 linux 中创建开发环境以进行 Web 开发的人...

    linux\linux命令速查手册

    ##### Other Useful Commands - **touch**: 修改文件的时间戳或创建空文件。 - **umask**: 设置新建文件的默认权限掩码。 - **whereis/which**: 查找命令的位置。 - **cat**: 显示文件内容。 - **chattr/chgrp/...

    GNU Linux Application Programming

    semaphores, POSIX, file handling, sockets, and more Provides detailed discussion of scripting and integration with the GNU/Linux environment with bash, including useful shell commands ...

    Linux Pocket Guide, 3rd Edition

    Linux Pocket Guide provides an organized learning path to help you gain mastery of the most useful and important commands. Whether you’re a novice who needs to get up to speed on Linux or an ...

    Linux command introduction.

    cover important, useful aspects of Linux so you can work pro‐ ductively. We do not, however, present every single command and every last option (our apologies if your favorite was omit‐ ted), nor ...

    A Practical Guide to Linux Commands, Editors and Shell Programming 4th Edition

    The Most Useful Tutorial and Reference, with Hundreds of High-Quality Examples for Every Popular Linux Distribution

    Linux System Administrator Guide Version0.9

    This section covers various hardware utilities and tools useful for system administrators: - **Hardware Utilities**: - **MAKEDEV Script**: A script used to create device files. - **mknod Command**:...

    Linux for Developers

    * **Basic Commands:** Teaches how to use basic developer commands such as gzip and grep, essential for file compression and searching through files respectively. #### Navigating Linux Filesystems * *...

    linux kernel in a nutshell

    This resource is particularly useful for those interested in designing embedded systems based on the Linux kernel, as it covers essential aspects of building, configuring, and customizing the kernel....

    101 shell script for linux and unix

    Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems <br>This cookbook of useful, customizable, and fun scripts gives you the tools to solve common Linux, Mac OS X and UNIX ...

    Linux Shell Scripting Cookbook - Third Edition

    Linux Shell Scripting Cookbook - Third Edition by Clif Flynt ...This book will take you through useful real-world recipes designed to make your daily life easier when working with the shell.

    shell cheat sheet

    This cheat sheet provides a comprehensive overview of essential shell commands, constructs, and utilities commonly used in UNIX/Linux environments. It is designed to serve as a quick reference guide ...

Global site tag (gtag.js) - Google Analytics