Linux cpio examples

Posted on April 25, 2013

Linux command cpio copies files into or out of a cpio or tar archive, The archive can be another file on the disk, a magnetic tape, or a pipe.

Examples:

1.Archive a single directory using cpio,and we can use option -v –to-stdout to check the content of cpio file

032b66c0c0683846a4f0e5f802a9[......]

Read more

» Filed Under Linux | Leave a Comment

Linux awk examples

Posted on April 15, 2013

Below will show you several simple awk command examples.

1.The first awk example,which will show you the whole content of file /etc/passwd

bash-3.2$ awk '{print}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
 
.....etc.

2.Another examples do the same thing as the 1st examples, $0 means the whole line

032b66c0c0683846a4f0e5f802a9fa6b004[......]

Read more

» Filed Under Linux | Leave a Comment

Linux cut command examples

Posted on April 5, 2013

Linux cut command is used to remove sections from each line of files.Below is some simple examples:

1.cut the first 1-3 bytes from output

bash-3.2$ date |cut -b 1-3
Fri

2.cut 1-3 and 6 and 8-15 bytes from outout

bash-3.2$ date|cut -b 1-3,6,8-15
Frie  3 16:4

3.Using “:” as a field delimiter and[......]

Read more

» Filed Under Linux | Leave a Comment

linux dd command examples

Posted on March 25, 2013

1.Copy a whole hard disk using dd(Replace X and Y with your own number)

dd if=/dev/hdX of=/dev/hdY

2.Copy a hard disk to an image file

dd if=/dev/hdx of=/path/to/image

3.Do the same thing as example 2 ,but also compress

dd if=/dev/hdx | gzip >/path/to/image.gz

4.Backup MBR using d[......]

Read more

» Filed Under Linux | Leave a Comment

Linux df command examples

Posted on March 15, 2013

Linux command dd is used to report file system disk space usage,normally we can use it to see how many disk space is used and how many is left.Here we go,let’s see some examples

1.Report all disk space usage on current host(include nfs points and print space size as byte )

032b66c0c0683846a4f0e5[......]

Read more

» Filed Under Linux | Leave a Comment

Linux grep command examples

Posted on March 5, 2013

Linux grep command is used to print lines matching a pattern.

1.Search for a specific string from a file

bash-3.2$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
bash-3.2$

2.Grep string case insensitive with option -i

bash-3.2$ dmesg |grep -i memory
Your BIOS doesn't leave a aperture memory hole
Memory: 16186548k/16777216k available (2551k kernel code, 459056k reserved, 1290k data, 208k init)
Freeing initrd memory: 2609k freed
Total HugeTLB memory allocated, 0
Non-volatile memory driver v1.2
Freeing unused kernel memory: 208k freed
mvfs: Ok: INFO: MVFS: Setting mvfs_largeinit to 15 based on physical memory size of 16189368KB
bash-3.2$

3.Display non-matching lines with option -v

032b66c0c0683846a4f0e[......]

Read more

» Filed Under Linux | Leave a Comment

Linux tar command examples

Posted on February 25, 2013

Linux tar command is an useful archive utility for both admin and users.Below will show you some simple examples

1.Archive a directory dir1 using command tar and  verbosely list files processed
<pre lang=”bash”>bash-3.2$ ls
dir1
bash-3.2$ tar -cvf dir1.tar dir1
dir1/
dir1/dir2/
dir1/d[......]

Read more

» Filed Under Linux | Leave a Comment

linux zip directory recursive example

Posted on February 15, 2013

Linux command zip is used to compress files,below will show you some examples about how to use zip command ,include how to zip directory recursive

First we will use a directory named dir1 to do test,below is some information of dir1,include the size and subdirectories and files of dir1

032b66c0c[......]

Read more

» Filed Under Other | Leave a Comment

Linux unzip example

Posted on February 5, 2013

Linux command unzip is used to list, test and extract compressed files in a ZIP archive file(compressed via zip command).Below will show you some examples about how to use unzip command.

1.List the files in the zip file with option -l

bash-3.2$ ls
dir1.zip
bash-3.2$ unzip -l dir1.zip
Archive:  dir1.zip
Length     Date   Time    Name
--------    ----   ----    ----
0  02-09-12 09:33   dir1/
0  02-07-12 14:33   dir1/dir2/
0  02-08-12 10:45   dir1/dir2/dir3/
96524  02-08-12 10:45   dir1/dir2/dir3/ddd
439509  02-08-12 10:45   dir1/dir2/test
72393  02-08-12 10:45   dir1/file03
--------                   -------
608426                   6 files
bash-3.2$

2.Extract the zip file[......]

Read more

» Filed Under Linux | Leave a Comment

gzip command examples in linux

Posted on January 25, 2013

Linux command gzip is used to compress files or extract .gz files,below will show you some examples.

1.Compress file01 to file01.gz with gzip command

bash-3.2$ ls
dir1  file01
bash-3.2$ gzip file01
bash-3.2$ ls
dir1  file01.gz
bash-3.2$

2.Compress file01 to file01.gz with option -c to keep original file file01 untouched

032b66c0c0683846a4f0e[......]

Read more

» Filed Under Linux | Leave a Comment

keep looking »