Linux 101 Hacks 3null change file case Xargs

Source: Internet
Author: User

Suppress output of standard output and error messages

When we debug shell scripts, we often do not want to see the standard output and standard error information. We can make
Use/DEV/NULLL to suppress the standard error message.

REDIRECT standard output to/dev/null
This command is useful when you are debugging a shell script and you do not want to see the output and just want to see the error message.

Cat file. txt >/dev/null#. /shell-script. sh >/dev/null

Suppress error output with "2>/dev/null"
This command can be very useful when you want to see only the standard output and don't want to see the error message.

cat invalid-file2>/dev/null#. /shell-script. SH 2>/dev/null
Join command

The join command can be combined on the basis of a common entry for two files.
In the following example, we have two files, respectively, Employee.txt and salary, and they have common items-
Employee-id. So we merged two files based on the Employee-id item.

To be honest, I'd rather use awk if I had to merge.

$CatEmployee.txt -Jason Smith $John Doe -Sanjay Gupta -Ashok sharma$CatBonus.txt -$5, the $$ - -$3, the -$1, -$ Joinemployee.txt bonus.txt -Jason Smith $5, the $John Doe $ - -Sanjay Gupta $3, the -Ashok Sharma $1, -
Change the case of a character

Lying trough, this is amazing.

Convert a file's contents all to uppercase

Cat Employee.txt  - Jason Smith  $ John Doe  - Sanjay Gupta  -  tr A-Z < employee.txt  JASON SMITH  JOHN DOE  SANJAY GUPTA ASHOK SHARMA

Convert a file's contents to lowercase letters

Cat Department.txt  - FINANCE  $ MARKETING  - PRODUCT Development  -  tr A-Z < department.txt  finance  Marketing  product development Sales

Note that the above changes are only standard output, the original file has not changed, the latter can add > output to the file

Xargs command

Xargs is a very powerful command that can take the output of one command as a parameter to another command. Here are a few
Examples of how to use the Xargs command effectively

I don't know how to read this Xargs, first mark.

When you use the RM command to delete many files, you may get an error message: "/bin/rm Argument
List too Long–linux ". You can use Xargs to avoid this problem.

Find Xargs -0rm –f

Get all files ending with. conf in/etc. There are several ways to get the following results. The following commands are only intended to help
You understand how to use the input results of the Xargs.find command to pass to Xargs one by one, as a ls-l parameter.

Find " *.conf " Xargs ls –l

When you want to download some URLs, these URLs are stored in a file, you can use the Xargs command as follows

Cat Xargs wget –c

Find all the pictures in the. jpg format and archive them.

Find Xargs tar -cvzf images. tar. gz

Copy all JPG image files to an external hard drive

ls Xargs CP {}/external-hard-drive/directory

Linux 101 Hacks 3null change file case Xargs

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.